Module: Pact::JRubySupport

Included in:
Matchers::UnixDiffFormatter
Defined in:
lib/pact/shared/jruby_support.rb

Instance Method Summary collapse

Instance Method Details

#add_blank_lines_in_empty_arrays(json) ⇒ Object



23
24
25
# File 'lib/pact/shared/jruby_support.rb', line 23

def add_blank_lines_in_empty_arrays(json)
  json.gsub(/\[\s*\]/, "[\n  ]")
end

#add_blank_lines_in_empty_hashes(json) ⇒ Object

preserve pre json 2.8.x behaviour github.com/ruby/json/pull/626



19
20
21
# File 'lib/pact/shared/jruby_support.rb', line 19

def add_blank_lines_in_empty_hashes(json)
  json.gsub(/({\s*})/, "{\n  }")
end

#fix_blank_lines_in_empty_hashes(json) ⇒ Object

Under jruby, JSON.pretty_generate inserts a blank new line between the opening and closing brackets of an empty hash, like so: {

"empty": {

}

} This screws up the UnixDiffFormatter, so we need to remove the blank lines.



13
14
15
# File 'lib/pact/shared/jruby_support.rb', line 13

def fix_blank_lines_in_empty_hashes json
  json.gsub(/({\n)\n(\s*})/,'\1\2')
end