Class: RSpec::Core::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/reporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(*formatters) ⇒ Reporter

Returns a new instance of Reporter.



3
4
5
6
7
# File 'lib/rspec/core/reporter.rb', line 3

def initialize(*formatters)
  @formatters = formatters
  @example_count = @failure_count = @pending_count = 0
  @duration = @start = nil
end

Instance Method Details

#example_failed(example) ⇒ Object



66
67
68
69
# File 'lib/rspec/core/reporter.rb', line 66

def example_failed(example)
  @failure_count += 1
  notify :example_failed, example
end

#example_group_finished(group) ⇒ Object



53
54
55
# File 'lib/rspec/core/reporter.rb', line 53

def example_group_finished(group)
  notify :example_group_finished, group unless group.descendant_filtered_examples.empty?
end

#example_group_started(group) ⇒ Object



49
50
51
# File 'lib/rspec/core/reporter.rb', line 49

def example_group_started(group)
  notify :example_group_started, group unless group.descendant_filtered_examples.empty?
end

#example_passed(example) ⇒ Object



62
63
64
# File 'lib/rspec/core/reporter.rb', line 62

def example_passed(example)
  notify :example_passed, example
end

#example_pending(example) ⇒ Object



71
72
73
74
# File 'lib/rspec/core/reporter.rb', line 71

def example_pending(example)
  @pending_count += 1
  notify :example_pending, example
end

#example_started(example) ⇒ Object



57
58
59
60
# File 'lib/rspec/core/reporter.rb', line 57

def example_started(example)
  @example_count += 1
  notify :example_started, example
end

#finish(seed) ⇒ Object Also known as: abort



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rspec/core/reporter.rb', line 76

def finish(seed)
  begin
    stop
    notify :start_dump
    notify :dump_pending
    notify :dump_failures
    notify :dump_summary, @duration, @example_count, @failure_count, @pending_count
    notify :seed, seed if seed
  ensure
    notify :close
  end
end

#message(message) ⇒ Object



45
46
47
# File 'lib/rspec/core/reporter.rb', line 45

def message(message)
  notify :message, message
end

#notify(method, *args, &block) ⇒ Object



96
97
98
99
100
# File 'lib/rspec/core/reporter.rb', line 96

def notify(method, *args, &block)
  @formatters.each do |formatter|
    formatter.send method, *args, &block
  end
end

#report(count, &block) ⇒ Object #report(count, seed, &block) ⇒ Object

Initializes the report run and yields itself for further reporting. The block is required, so that the reporter can manage cleaning up after the run.

### Warning:

The ‘seed` argument is an internal API and is not guaranteed to be supported in the future.

Examples:


reporter.report(group.examples.size) do |r|
  example_groups.map {|g| g.run(r) }
end

Parameters:

  • count (Integer)

    the number of examples being run

  • seed (Integer) (defaults to: nil)

    the seed used to randomize the spec run

  • block (Block)

    yields itself for further reporting.



31
32
33
34
35
36
37
38
# File 'lib/rspec/core/reporter.rb', line 31

def report(expected_example_count, seed=nil)
  start(expected_example_count)
  begin
    yield self
  ensure
    finish(seed)
  end
end

#start(expected_example_count) ⇒ Object



40
41
42
43
# File 'lib/rspec/core/reporter.rb', line 40

def start(expected_example_count)
  @start = Time.now
  notify :start, expected_example_count
end

#stopObject



91
92
93
94
# File 'lib/rspec/core/reporter.rb', line 91

def stop
  @duration = Time.now - @start if @start
  notify :stop
end