class JsonSpec::Matchers::BeJsonEql
Attributes
Public Class Methods
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 14 def initialize(expected_json = nil) @expected_json = expected_json @path = nil end
Public Instance Methods
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 26 def at_path(path) @path = path self end
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 56 def description message_with_path("equal JSON") end
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 36 def excluding(*keys) excluded_keys.merge(keys.map(&:to_s)) self end
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 46 def failure_message message_with_path("Expected equivalent JSON") end
Also aliased as: failure_message_for_should
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 51 def failure_message_when_negated message_with_path("Expected inequivalent JSON") end
Also aliased as: failure_message_for_should_not
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 41 def including(*keys) excluded_keys.subtract(keys.map(&:to_s)) self end
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 19 def matches?(actual_json) raise "Expected equivalent JSON not provided" if @expected_json.nil? @actual, @expected = scrub(actual_json, @path), scrub(@expected_json) @actual == @expected end
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 31 def to_file(path) @expected_json = load_json(path) self end
Private Instance Methods
Source
# File lib/json_spec/matchers/be_json_eql.rb, line 61 def scrub(json, path = nil) generate_normalized_json(exclude_keys(parse_json(json, path))).chomp + "\n" end