-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: print a new line between JSON documents when using --format json
This allows the stream to be parsed as jsonl Fixes: pact-foundation/pact-go#88
- Loading branch information
Showing
3 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
lib/pact/provider_verifier/rspec_json_formatter_monkeypatch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'rspec' | ||
|
||
begin | ||
require 'rspec/core/formatters/json_formatter' | ||
|
||
RSpec::Core::Formatters::JsonFormatter | ||
|
||
# This looks dodgy, but it's actually safer than inheriting from | ||
# RSpec::Core::Formatters::JsonFormatter and using a custom class, | ||
# because if the JsonFormatter class gets refactored, | ||
# the --format json option will still work, but the inheritance will break. | ||
|
||
module RSpec | ||
module Core | ||
module Formatters | ||
class JsonFormatter | ||
alias_method :old_close, :close | ||
|
||
def close(*args) | ||
# Append a new line so that the output stream can be split at | ||
# the new lines, and each JSON document parsed separately | ||
old_close(*args) | ||
output.write("\n") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
rescue NameError | ||
Pact.configuration.error_stream.puts "WARN: Could not find RSpec::Core::Formatters::JsonFormatter to modify it to put a new line between JSON result documents." | ||
rescue LoadError | ||
Pact.configuration.error_stream.puts "WARN: Could not load rspec/core/formatters/json_formatter to modify it to put a new line between JSON result documents." | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters