Class: Konacha::Reporter
- Inherits:
-
Object
show all
- Defined in:
- lib/konacha/reporter.rb,
lib/konacha/reporter/example.rb,
lib/konacha/reporter/metadata.rb,
lib/konacha/reporter/example_group.rb
Defined Under Namespace
Classes: Example, ExampleGroup, Metadata, SpecException
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*formatters) ⇒ Reporter
Returns a new instance of Reporter.
12
13
14
15
16
|
# File 'lib/konacha/reporter.rb', line 12
def initialize(*formatters)
@formatters = formatters
@duration = @start_time = nil
@examples, @groups = {}, {}
end
|
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
10
11
12
|
# File 'lib/konacha/reporter.rb', line 10
def duration
@duration
end
|
#examples ⇒ Object
Returns the value of attribute examples.
10
11
12
|
# File 'lib/konacha/reporter.rb', line 10
def examples
@examples
end
|
#start_time ⇒ Object
Returns the value of attribute start_time.
10
11
12
|
# File 'lib/konacha/reporter.rb', line 10
def start_time
@start_time
end
|
Instance Method Details
#example_count ⇒ Object
50
51
52
|
# File 'lib/konacha/reporter.rb', line 50
def example_count
examples.count
end
|
#failure_count ⇒ Object
54
55
56
|
# File 'lib/konacha/reporter.rb', line 54
def failure_count
examples.values.count { |example| example.failed? }
end
|
#finish(seed = nil) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/konacha/reporter.rb', line 23
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
41
42
43
|
# File 'lib/konacha/reporter.rb', line 41
def passed?
failure_count == 0
end
|
#pending_count ⇒ Object
58
59
60
|
# File 'lib/konacha/reporter.rb', line 58
def pending_count
examples.values.count { |example| example.pending? }
end
|
#process_event(method, *args, &block) ⇒ Object
62
63
64
65
66
|
# File 'lib/konacha/reporter.rb', line 62
def process_event(method, *args, &block)
@formatters.each do |formatter|
formatter.send method, *args, &block
end
end
|
#process_mocha_event(event) ⇒ Object
45
46
47
48
|
# File 'lib/konacha/reporter.rb', line 45
def process_mocha_event(event)
event_name = event['event'].tr(' ', '_')
send "handle_mocha_#{event_name}", event
end
|
#start(expected_example_count = nil) ⇒ Object
18
19
20
21
|
# File 'lib/konacha/reporter.rb', line 18
def start(expected_example_count=nil)
@start_time = Time.now
process_event :start, expected_example_count
end
|
#stop ⇒ Object
36
37
38
39
|
# File 'lib/konacha/reporter.rb', line 36
def stop
@duration = Time.now - @start_time if @start_time
process_event :stop
end
|
#update_or_create_object(data, type) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/konacha/reporter.rb', line 68
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
|