lib/cucumber/formatter/json.rb in cucumber-2.0.2 vs lib/cucumber/formatter/json.rb in cucumber-2.1.0

- old
+ new

@@ -9,11 +9,11 @@ class Json include Io def initialize(runtime, io, _options) @runtime = runtime - @io = ensure_io(io, 'json') + @io = ensure_io(io) @feature_hashes = [] end def before_test_case(test_case) builder = Builder.new(test_case) @@ -27,10 +27,11 @@ @element_hash = builder.background_hash else feature_elements << @test_case_hash @element_hash = @test_case_hash end + @any_step_failed = false end def before_test_step(test_step) return if internal_hook?(test_step) hook_query = HookQueryVisitor.new(test_step) @@ -49,12 +50,17 @@ end def after_test_step(test_step, result) return if internal_hook?(test_step) add_match_and_result(test_step, result) + @any_step_failed = true if result.failed? end + def after_test_case(test_case, result) + add_failed_around_hook(result) if result.failed? && !@any_step_failed + end + def done @io.write(MultiJson.dump(@feature_hashes, pretty: true)) end def puts(message) @@ -121,10 +127,14 @@ def after_hooks @element_hash[:after] ||= [] end + def around_hooks + @element_hash[:around] ||= [] + end + def after_step_hooks @step_hash[:after] ||= [] end def test_step_output @@ -154,9 +164,17 @@ } end def add_match_and_result(test_step, result) @step_or_hook_hash[:match] = create_match_hash(test_step, result) + @step_or_hook_hash[:result] = create_result_hash(result) + end + + def add_failed_around_hook(result) + @step_or_hook_hash = {} + around_hooks << @step_or_hook_hash + @step_or_hook_hash[:match] = { location: "unknown_hook_location:1" } + @step_or_hook_hash[:result] = create_result_hash(result) end def create_match_hash(test_step, result) { location: test_step.action_location }