lib/cucumber/formatter/json.rb in cucumber-7.1.0 vs lib/cucumber/formatter/json.rb in cucumber-8.0.0.rc.1
- old
+ new
@@ -66,10 +66,11 @@
def on_test_step_finished(event)
test_step, result = *event.attributes
result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
return if internal_hook?(test_step)
+
add_match_and_result(test_step, result)
@any_step_failed = true if result.failed?
end
def on_test_case_finished(event)
@@ -79,11 +80,11 @@
result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
add_failed_around_hook(result) if result.failed? && !@any_step_failed
end
def on_test_run_finished(_event)
- @io.write(JSON.generate(@feature_hashes, pretty: true))
+ @io.write(JSON.pretty_generate(@feature_hashes))
end
def attach(src, mime_type)
if mime_type == 'text/x.cucumber.log+plain'
test_step_output << src
@@ -103,11 +104,11 @@
def same_feature_as_previous_test_case?(test_case)
current_feature[:uri] == test_case.location.file
end
def first_step_after_background?(test_step)
- @in_background && test_step.location.lines.max >= @test_case_hash[:line]
+ @in_background && test_step.location.file == @feature_hash[:uri] && test_step.location.lines.max >= @test_case_hash[:line]
end
def internal_hook?(test_step)
test_step.location.file.include?('lib/cucumber/')
end
@@ -131,11 +132,11 @@
when 'After hook'
after_hooks
when 'AfterStep hook'
after_step_hooks
else
- raise 'Unknown hook type ' + hook_step.to_s
+ raise "Unknown hook type #{hook_step}"
end
end
def before_hooks
@element_hash[:before] ||= []
@@ -173,19 +174,19 @@
step_hash = {
keyword: step_source.keyword,
name: test_step.text,
line: test_step.location.lines.min
}
- step_hash[:doc_string] = create_doc_string_hash(step_source.doc_string) unless step_source.doc_string.nil?
+ step_hash[:doc_string] = create_doc_string_hash(step_source.doc_string, test_step.multiline_arg.content) unless step_source.doc_string.nil?
step_hash[:rows] = create_data_table_value(step_source.data_table) unless step_source.data_table.nil?
step_hash
end
- def create_doc_string_hash(doc_string)
+ def create_doc_string_hash(doc_string, doc_string_content)
content_type = doc_string.media_type || ''
{
- value: doc_string.content,
+ value: doc_string_content,
content_type: content_type,
line: doc_string.location.line
}
end
@@ -257,9 +258,10 @@
name: feature.name,
description: value_or_empty_string(feature.description),
line: feature.location.line
}
return if feature.tags.empty?
+
@feature_hash[:tags] = create_tags_array_from_hash_array(feature.tags)
end
def background(background)
@background_hash = {