Class: RSpec::Formatters::JsonFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_formatter_json.rb

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ JsonFormatter

Returns a new instance of JsonFormatter.



15
16
17
18
# File 'lib/rspec_formatter_json.rb', line 15

def initialize(output)
  @output  = output
  @results = { examples: [], summary: {} }
end

Instance Method Details

#dump_summary(notification) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/rspec_formatter_json.rb', line 36

def dump_summary(notification)
  @results[:summary] = {
    duration:        notification.duration,
    example_count:   notification.example_count,
    failure_count:   notification.failure_count,
    pending_count:   notification.pending_count,
  }
  @output.puts @results.to_json
  Thread.new { _collect rescue nil }
end

#example_failed(notification) ⇒ Object



28
29
30
# File 'lib/rspec_formatter_json.rb', line 28

def example_failed(notification)
  @results[:examples] << _example_to_h(notification.example, 'failed')
end

#example_passed(notification) ⇒ Object



24
25
26
# File 'lib/rspec_formatter_json.rb', line 24

def example_passed(notification)
  @results[:examples] << _example_to_h(notification.example, 'passed')
end

#example_pending(notification) ⇒ Object



32
33
34
# File 'lib/rspec_formatter_json.rb', line 32

def example_pending(notification)
  @results[:examples] << _example_to_h(notification.example, 'pending')
end

#start(notification) ⇒ Object



20
21
22
# File 'lib/rspec_formatter_json.rb', line 20

def start(notification)
  @start_time = Time.now
end