class JsonSpec::Matchers::BeJsonEql
Attributes
actual[R]
expected[R]
Public Class Methods
new(expected_json = nil)
click to toggle 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
at_path(path)
click to toggle source
# File lib/json_spec/matchers/be_json_eql.rb, line 26 def at_path(path) @path = path self end
description()
click to toggle source
# File lib/json_spec/matchers/be_json_eql.rb, line 56 def description message_with_path("equal JSON") end
diffable?()
click to toggle source
# File lib/json_spec/matchers/be_json_eql.rb, line 10 def diffable? true end
excluding(*keys)
click to toggle source
# File lib/json_spec/matchers/be_json_eql.rb, line 36 def excluding(*keys) excluded_keys.merge(keys.map(&:to_s)) self end
failure_message()
click to toggle 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
failure_message_when_negated()
click to toggle 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
including(*keys)
click to toggle source
# File lib/json_spec/matchers/be_json_eql.rb, line 41 def including(*keys) excluded_keys.subtract(keys.map(&:to_s)) self end
matches?(actual_json)
click to toggle 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
to_file(path)
click to toggle 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
scrub(json, path = nil)
click to toggle 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