Class: RSpecLive::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-live/example.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExample

Returns a new instance of Example.



7
8
9
10
11
# File 'lib/rspec-live/example.rb', line 7

def initialize
  @name = ""
  @status = :unknown
  @backtrace = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rspec-live/example.rb', line 5

def name
  @name
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/rspec-live/example.rb', line 5

def status
  @status
end

Instance Method Details

#backtrace_components(verbosity) ⇒ Object



44
45
46
47
# File 'lib/rspec-live/example.rb', line 44

def backtrace_components(verbosity)
  return [] if verbosity < 1
  Backtrace.new(@backtrace, verbosity).components.reverse.map { |c| "(#{c})" }
end

#details(verbosity) ⇒ Object



32
33
34
# File 'lib/rspec-live/example.rb', line 32

def details(verbosity)
  failed? ? failure_message(verbosity) : name_component
end

#exception_componentsObject



49
50
51
# File 'lib/rspec-live/example.rb', line 49

def exception_components
  [@message.gsub("\n", " ").strip.inspect]
end

#failed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rspec-live/example.rb', line 28

def failed?
  @status == :failed
end

#failure_message(verbosity) ⇒ Object



40
41
42
# File 'lib/rspec-live/example.rb', line 40

def failure_message(verbosity)
  ([name_component] + backtrace_components(verbosity) + exception_components).compact.join " -> "
end

#name_componentObject



36
37
38
# File 'lib/rspec-live/example.rb', line 36

def name_component
  "(" + @name.gsub(/^.\//, "") + ")"
end

#passed?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rspec-live/example.rb', line 24

def passed?
  @status == :passed
end

#update(data) ⇒ Object



13
14
15
16
17
18
# File 'lib/rspec-live/example.rb', line 13

def update(data)
  @name = data["name"] if data["name"]
  @status = data["status"].to_sym if data["status"]
  @backtrace = data["backtrace"] if data["backtrace"]
  @message = data["message"] if data["message"]
end