diff --git a/lib/pact/matchers/unix_diff_formatter.rb b/lib/pact/matchers/unix_diff_formatter.rb index 1946b25..0eb9b1d 100644 --- a/lib/pact/matchers/unix_diff_formatter.rb +++ b/lib/pact/matchers/unix_diff_formatter.rb @@ -62,6 +62,8 @@ def generate_string diff, target begin # Can't think of an elegant way to check if we can pretty generate other than to try it and maybe fail json = fix_blank_lines_in_empty_hashes JSON.pretty_generate(comparable) + json = add_blank_lines_in_empty_hashes json + json = add_blank_lines_in_empty_arrays json add_comma_to_end_of_arrays json rescue JSON::GeneratorError comparable.to_s diff --git a/lib/pact/shared/jruby_support.rb b/lib/pact/shared/jruby_support.rb index 5f01032..8afcbb2 100644 --- a/lib/pact/shared/jruby_support.rb +++ b/lib/pact/shared/jruby_support.rb @@ -14,5 +14,14 @@ def fix_blank_lines_in_empty_hashes json json.gsub(/({\n)\n(\s*})/,'\1\2') end + # preserve pre json 2.8.x behaviour + # https://github.com/ruby/json/pull/626 + def add_blank_lines_in_empty_hashes(json) + json.gsub(/({\s*})/, "{\n }") + end + + def add_blank_lines_in_empty_arrays(json) + json.gsub(/\[\s*\]/, "[\n ]") + end end end \ No newline at end of file diff --git a/spec/lib/pact/matchers/unix_diff_formatter_spec.rb b/spec/lib/pact/matchers/unix_diff_formatter_spec.rb index 2e7912c..f535cf2 100644 --- a/spec/lib/pact/matchers/unix_diff_formatter_spec.rb +++ b/spec/lib/pact/matchers/unix_diff_formatter_spec.rb @@ -123,6 +123,7 @@ module Matchers end it "generates the right number of lines, even with ActiveSupport loaded" do + puts subject expect(line_count).to eq 7 + key_lines_count end end