Class: Rocha::Reporter
- Inherits:
-
Object
show all
- Defined in:
- lib/rocha/reporter.rb,
lib/rocha/reporter/example.rb,
lib/rocha/reporter/metadata.rb,
lib/rocha/reporter/example_group.rb
Defined Under Namespace
Classes: Example, ExampleGroup, Metadata, SpecException
Constant Summary
collapse
- EVENT_CONVERSIONS =
{
'suite' => :example_group_started,
'test' => :example_started,
'pass' => :example_passed,
'fail' => :example_failed,
'pending' => :example_pending,
'suite end' => :example_group_finished,
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*formatters) ⇒ Reporter
Returns a new instance of Reporter.
21
22
23
24
25
26
|
# File 'lib/rocha/reporter.rb', line 21
def initialize(*formatters)
@formatters = formatters
@example_count = @failure_count = @pending_count = 0
@duration = @start_time = nil
@examples, @groups = {}, {}
end
|
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
19
20
21
|
# File 'lib/rocha/reporter.rb', line 19
def duration
@duration
end
|
#example_count ⇒ Object
Returns the value of attribute example_count.
19
20
21
|
# File 'lib/rocha/reporter.rb', line 19
def example_count
@example_count
end
|
#failure_count ⇒ Object
Returns the value of attribute failure_count.
19
20
21
|
# File 'lib/rocha/reporter.rb', line 19
def failure_count
@failure_count
end
|
#pending_count ⇒ Object
Returns the value of attribute pending_count.
19
20
21
|
# File 'lib/rocha/reporter.rb', line 19
def pending_count
@pending_count
end
|
#start_time ⇒ Object
Returns the value of attribute start_time.
19
20
21
|
# File 'lib/rocha/reporter.rb', line 19
def start_time
@start_time
end
|
Instance Method Details
83
84
85
86
87
|
# File 'lib/rocha/reporter.rb', line 83
def call_formatters(method, *args, &block)
@formatters.each do |formatter|
formatter.send method, *args, &block
end
end
|
#finish(seed = nil) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/rocha/reporter.rb', line 33
def finish(seed=nil)
begin
stop
process_event :start_dump
process_event :dump_pending
process_event :dump_failures
process_event :dump_summary, @duration, @example_count, @failure_count, @pending_count
process_event :seed, seed if seed
ensure
process_event :close
end
end
|
#passed? ⇒ Boolean
51
52
53
|
# File 'lib/rocha/reporter.rb', line 51
def passed?
@examples.values.all? { |example| example.passed? || example.pending? }
end
|
#process_event(method, *args, &block) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/rocha/reporter.rb', line 66
def process_event(method, *args, &block)
case method
when :example_started
@example_count += 1
when :example_failed
@failure_count += 1
when :example_pending
@pending_count += 1
end
if method == :example_pending
call_formatters(:example_started, *args, &block)
end
call_formatters(method, *args, &block)
end
|
#process_mocha_event(event) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/rocha/reporter.rb', line 55
def process_mocha_event(event)
if event['event'] == 'start'
start(event['testCount'])
elsif event['event'] == 'end'
finish
elsif event['type']
object = update_or_create_object(event['data'], event['type'])
process_event EVENT_CONVERSIONS[event['event']], object
end
end
|
#start(expected_example_count = nil) ⇒ Object
28
29
30
31
|
# File 'lib/rocha/reporter.rb', line 28
def start(expected_example_count=nil)
@start_time = Time.now
process_event :start, expected_example_count
end
|
#stop ⇒ Object
46
47
48
49
|
# File 'lib/rocha/reporter.rb', line 46
def stop
@duration = Time.now - @start_time if @start_time
process_event :stop
end
|
#update_or_create_object(data, type) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/rocha/reporter.rb', line 89
def update_or_create_object(data, type)
collection = type == 'test' ? @examples : @groups
object = collection[data['fullTitle']]
if object
object.update_metadata(data)
else
klass = type == 'test' ? Example : ExampleGroup
parent = @groups[data['parentFullTitle']]
object = collection[data['fullTitle']] = klass.new(data, parent)
end
object
end
|