class RSpec::JsonHelpers::EqualJsonMatcher
@api private
Public Class Methods
new(expected, colorize: true)
click to toggle source
# File lib/rspec/json_helpers/equal_json_matcher.rb, line 12 def initialize(expected, colorize: true) @expected = JsonHelpers.normalize_json(expected) @diff_format = colorize ? :color : :text end
Public Instance Methods
diff()
click to toggle source
# File lib/rspec/json_helpers/equal_json_matcher.rb, line 41 def diff diff = Diffy::Diff.new(@expected, @actual).to_s(@diff_format) diff.lines[0..-2].join end
diff_json_error_message()
click to toggle source
# File lib/rspec/json_helpers/equal_json_matcher.rb, line 33 def diff_json_error_message message = StringIO.new message << "expected: #{@expected}\n\n" message << "got: #{@actual}\n\n" message << "Diff: #{diff}" message.string end
failure_message()
click to toggle source
# File lib/rspec/json_helpers/equal_json_matcher.rb, line 25 def failure_message @wrong_type_error_message || diff_json_error_message end
failure_message_when_negated()
click to toggle source
# File lib/rspec/json_helpers/equal_json_matcher.rb, line 29 def failure_message_when_negated 'expected JSON value not to be equal' end
matches?(actual)
click to toggle source
# File lib/rspec/json_helpers/equal_json_matcher.rb, line 17 def matches?(actual) @actual = JsonHelpers.normalize_json(actual) @expected == @actual rescue ArgumentError => error @wrong_type_error_message = error.message false end