Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSON Formatter #1580

Merged
merged 11 commits into from
Dec 7, 2021
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ 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))

### Changed

Expand Down
4 changes: 3 additions & 1 deletion features/docs/writing_support_code/attachments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
aurelien-reeves marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions lib/cucumber/formatter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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)
Expand All @@ -105,7 +105,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]
aurelien-reeves marked this conversation as resolved.
Show resolved Hide resolved
end

def internal_hook?(test_step)
Expand Down