class RSpec::Oj::Matchers::BeJsonEql
Attributes
actual[R]
expected[R]
Public Class Methods
new(expected_json = nil)
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 17 def initialize(expected_json = nil) @expected_json = expected_json @path = nil end
Public Instance Methods
at_path(path)
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 30 def at_path(path) @path = path self end
description()
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 60 def description message_with_path('equal JSON') end
diffable?()
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 13 def diffable? true end
excluding(*keys)
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 40 def excluding(*keys) excluded_keys.merge(keys.map(&:to_s)) self end
failure_message()
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 50 def failure_message message_with_path('Expected equivalent JSON') end
Also aliased as: failure_message_for_should
failure_message_when_negated()
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 55 def failure_message_when_negated message_with_path('Expected inequivalent JSON') end
Also aliased as: failure_message_for_should_not
including(*keys)
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 45 def including(*keys) excluded_keys.subtract(keys.map(&:to_s)) self end
matches?(actual_json)
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 22 def matches?(actual_json) raise 'Expected equivalent JSON not provided' if @expected_json.nil? @actual = scrub(actual_json, @path) @expected = scrub(@expected_json) @actual == @expected end
to_file(path)
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 35 def to_file(path) @expected_json = load_json(path) self end
Private Instance Methods
scrub(json, path = nil)
click to toggle source
# File lib/rspec/oj/matchers/be_json_eql.rb, line 66 def scrub(json, path = nil) generate_normalized_json(exclude_keys(parse_json(json, path))).chomp + "\n" end