Class: Spec::Runner::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/runner/reporter.rb

Defined Under Namespace

Classes: Failure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Reporter

Returns a new instance of Reporter.



6
7
8
9
10
# File 'lib/spec/runner/reporter.rb', line 6

def initialize(options)
  @options = options
  @options.reporter = self
  clear
end

Instance Attribute Details

#example_groupsObject (readonly)

Returns the value of attribute example_groups.



4
5
6
# File 'lib/spec/runner/reporter.rb', line 4

def example_groups
  @example_groups
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/spec/runner/reporter.rb', line 4

def options
  @options
end

Instance Method Details

#add_example_group(example_group) ⇒ Object



12
13
14
15
16
17
# File 'lib/spec/runner/reporter.rb', line 12

def add_example_group(example_group)
  formatters.each do |f|
    f.add_example_group(example_group)
  end
  example_groups << example_group
end

#dumpObject

Dumps the summary and returns the total number of failures



55
56
57
58
59
60
61
62
63
64
# File 'lib/spec/runner/reporter.rb', line 55

def dump
  formatters.each{|f| f.start_dump}
  dump_pending
  dump_failures
  formatters.each do |f|
    f.dump_summary(duration, @examples.length, @failures.length, @pending_count)
    f.close
  end
  @failures.length
end

#endObject



50
51
52
# File 'lib/spec/runner/reporter.rb', line 50

def end
  @end_time = Time.new
end

#example_failed(example, error) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/spec/runner/reporter.rb', line 35

def example_failed(example, error)
  backtrace_tweaker.tweak_backtrace(error)
  failure = Failure.new(example_groups.empty? ? "" : example_groups.last.description, example, error)
  @failures << failure
  formatters.each do |f|
    f.example_failed(example, @failures.length, failure)
  end
end

#example_finished(example, error = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spec/runner/reporter.rb', line 23

def example_finished(example, error=nil)
  @examples << example
  
  if error.nil?
    example_passed(example)
  elsif Spec::Example::ExamplePendingError === error
    example_pending(example, error.pending_caller, error.message)
  else
    example_failed(example, error)
  end
end

#example_started(example) ⇒ Object



19
20
21
# File 'lib/spec/runner/reporter.rb', line 19

def example_started(example)
  formatters.each{|f| f.example_started(example)}
end

#start(number_of_examples) ⇒ Object



44
45
46
47
48
# File 'lib/spec/runner/reporter.rb', line 44

def start(number_of_examples)
  clear
  @start_time = Time.new
  formatters.each{|f| f.start(number_of_examples)}
end