diff --git a/CHANGELOG.md b/CHANGELOG.md index 4be92c18e4..90e2e49eec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,15 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo - Do not serialize Messages::Hook#tag_expression if it is empty. ([PR#1579](https://github.com/cucumber/cucumber-ruby/pull/1579)) +- JSON Formatter uses "pretty" output format + ([PR#1580](https://github.com/cucumber/cucumber-ruby/pull/1580)) + +- Fixed JSON Formatter "end of background" detection. + ([PR#1580](https://github.com/cucumber/cucumber-ruby/pull/1580)) + +- Fixed JSON Formatter expansion of Scenario Outline templates in Doc Strings. + ([PR#1580](https://github.com/cucumber/cucumber-ruby/pull/1580)) + - Removed usage of `eval` in `Cucumber::Term::ANSIColor` and `Cucumber::Formatter::ANSIColor`. ([PR#1589](https://github.com/cucumber/cucumber-ruby/pull/1589) [Issue#1583](https://github.com/cucumber/cucumber-ruby/issues/1583)) diff --git a/features/docs/formatters/json_formatter.feature b/features/docs/formatters/json_formatter.feature index 5ac6ac16d4..1d48eed093 100644 --- a/features/docs/formatters/json_formatter.feature +++ b/features/docs/formatters/json_formatter.feature @@ -389,6 +389,101 @@ Feature: JSON output formatter """ + Scenario: scenario outline with docstring + Given a file named "features/outline_doc_string.feature" with: + """ + Feature: An outline feature with a DocString + + Scenario Outline: outline + Then I should fail with + \"\"\" + + \"\"\" + + Examples: examples1 + | status | + | passes | + | fails | + """ + And a file named "features/step_definitions/steps.rb" with: + """ + Then /I should fail with/ do |s| + raise RuntimeError, s + end + """ + When I run `cucumber --format json features/outline_doc_string.feature` + Then it should fail with JSON: + """ + [ + { + "id": "an-outline-feature-with-a-docstring", + "uri": "features/outline_doc_string.feature", + "keyword": "Feature", + "name": "An outline feature with a DocString", + "line": 1, + "description": "", + "elements": [ + { + "id": "an-outline-feature-with-a-docstring;outline;examples1;2", + "keyword": "Scenario Outline", + "name": "outline", + "line": 11, + "description": "", + "type": "scenario", + "steps": [ + { + "keyword": "Then ", + "name": "I should fail with", + "line": 4, + "doc_string": { + "content_type": "", + "value": "passes", + "line": 5 + }, + "match": { + "location": "features/step_definitions/steps.rb:1" + }, + "result": { + "status": "failed", + "error_message": "passes (RuntimeError)\n./features/step_definitions/steps.rb:2:in `/I should fail with/'\nfeatures/outline_doc_string.feature:11:4:in `I should fail with'", + "duration": 1 + } + } + ] + }, + { + "id": "an-outline-feature-with-a-docstring;outline;examples1;3", + "keyword": "Scenario Outline", + "name": "outline", + "line": 12, + "description": "", + "type": "scenario", + "steps": [ + { + "keyword": "Then ", + "name": "I should fail with", + "line": 4, + "doc_string": { + "content_type": "", + "value": "fails", + "line": 5 + }, + "match": { + "location": "features/step_definitions/steps.rb:1" + }, + "result": { + "status": "failed", + "error_message": "fails (RuntimeError)\n./features/step_definitions/steps.rb:2:in `/I should fail with/'\nfeatures/outline_doc_string.feature:12:4:in `I should fail with'", + "duration": 1 + } + } + ] + } + ] + } + ] + """ + Scenario: print from step definition When I run `cucumber --format json features/print_from_step_definition.feature` Then it should pass with JSON: diff --git a/features/docs/writing_support_code/attachments.feature b/features/docs/writing_support_code/attachments.feature index d29b627c17..bea34bf83d 100644 --- a/features/docs/writing_support_code/attachments.feature +++ b/features/docs/writing_support_code/attachments.feature @@ -51,4 +51,6 @@ Feature: Attachments Scenario: With json formatter, files can be attached given their path When I run `cucumber --format json features/attaching_screenshot_with_mediatype.feature` - Then the output should contain "embeddings\":[{\"mime_type\":\"image/png\",\"data\":\"Zm9v\"}]" + Then the output should contain "embeddings\":" + And the output should contain "\"mime_type\": \"image/png\"," + And the output should contain "\"data\": \"Zm9v\"" diff --git a/lib/cucumber/formatter/json.rb b/lib/cucumber/formatter/json.rb index fa13f14d94..6b1e0f9f41 100644 --- a/lib/cucumber/formatter/json.rb +++ b/lib/cucumber/formatter/json.rb @@ -82,7 +82,7 @@ def on_test_case_finished(event) 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) @@ -106,7 +106,7 @@ def same_feature_as_previous_test_case?(test_case) 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) @@ -176,15 +176,15 @@ def create_step_hash(test_step) 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 }