Class: ParallelCucumber::Helper::Cucumber::JsonStatusFormatter

Inherits:
Object
  • Object
show all
Includes:
Cucumber::Formatter::Io
Defined in:
lib/parallel_cucumber/helper/cucumber/json_status_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ JsonStatusFormatter

Returns a new instance of JsonStatusFormatter.



9
10
11
12
13
14
15
# File 'lib/parallel_cucumber/helper/cucumber/json_status_formatter.rb', line 9

def initialize(config)
  config.on_event :after_test_case, &method(:on_after_test_case)
  config.on_event :finished_testing, &method(:on_finished_testing)

  @io     = ensure_io(config.out_stream)
  @result = {}
end

Instance Method Details

#on_after_test_case(event) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/parallel_cucumber/helper/cucumber/json_status_formatter.rb', line 17

def on_after_test_case(event)
  details = {status: event.result.to_sym}
  if event.result.respond_to?(:exception)
    details[:exception_classname] = event.result.exception.class.to_s
    details[:exception_message] = event.result.exception.message
  end
  details[:name] = "#{event.test_case.feature}: #{event.test_case.name}"
  details[:finish_time] = Time.now.to_i
  @result[event.test_case.location.to_s] = details
end

#on_finished_testingObject



28
29
30
# File 'lib/parallel_cucumber/helper/cucumber/json_status_formatter.rb', line 28

def on_finished_testing(*)
  @io.write(@result.to_json)
end