class JsonSpec::Matchers::IncludeJson
Public Class Methods
Source
# File lib/json_spec/matchers/include_json.rb, line 8 def initialize(expected_json = nil) @expected_json = expected_json @path = nil end
Public Instance Methods
Source
# File lib/json_spec/matchers/include_json.rb, line 28 def at_path(path) @path = path self end
Source
# File lib/json_spec/matchers/include_json.rb, line 58 def description message_with_path("include JSON") end
Source
# File lib/json_spec/matchers/include_json.rb, line 38 def excluding(*keys) excluded_keys.merge(keys.map(&:to_s)) self end
Source
# File lib/json_spec/matchers/include_json.rb, line 48 def failure_message message_with_path("Expected #{@actual_json} to include #{@expected_json}") end
Also aliased as: failure_message_for_should
Source
# File lib/json_spec/matchers/include_json.rb, line 53 def failure_message_when_negated message_with_path("Expected #{@actual_json} to not include #{@expected_json}") end
Also aliased as: failure_message_for_should_not
Source
# File lib/json_spec/matchers/include_json.rb, line 33 def from_file(path) @expected_json = load_json(path) self end
Source
# File lib/json_spec/matchers/include_json.rb, line 43 def including(*keys) excluded_keys.subtract(keys.map(&:to_s)) self end
Source
# File lib/json_spec/matchers/include_json.rb, line 13 def matches?(actual_json) raise "Expected included JSON not provided" if @expected_json.nil? @actual_json = actual_json actual = parse_json(actual_json, @path) expected = exclude_keys(parse_json(@expected_json)) case actual when Hash then actual.values.map { |v| exclude_keys(v) }.include?(expected) when Array then actual.map { |e| exclude_keys(e) }.include?(expected) when String then actual.include?(expected) else false end end