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



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

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

#details(verbosity) ⇒ Object



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

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

#exception_componentsObject



54
55
56
# File 'lib/rspec-live/example.rb', line 54

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

#failed?Boolean

Returns:

  • (Boolean)


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

def failed?
  @status == :failed
end

#failure_message(verbosity) ⇒ Object



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

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

#file_touched(name) ⇒ Object



58
59
60
# File 'lib/rspec-live/example.rb', line 58

def file_touched(name)
  @status = :unknown if @files_touched.include? name
end

#in_file?(filename) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/rspec-live/example.rb', line 62

def in_file?(filename)
  absolute_path == filename
end

#name_componentObject



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

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

#passed?Boolean

Returns:

  • (Boolean)


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

def passed?
  @status == :passed
end

#stale?Boolean

Returns:

  • (Boolean)


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

def stale?
  @status == :unknown
end

#update(data) ⇒ Object



13
14
15
16
17
18
19
# 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"]
  @files_touched = data["files_touched"] || []
end