Class: JsonSpec::Matchers::HaveJsonType
Instance Method Summary
collapse
#message_with_path
Methods included from Helpers
#generate_normalized_json, #load_json, #normalize_json, #parse_json
Constructor Details
Returns a new instance of HaveJsonType.
7
8
9
10
|
# File 'lib/json_spec/matchers/have_json_type.rb', line 7
def initialize(type)
@classes = type_to_classes(type)
@path = nil
end
|
Instance Method Details
#at_path(path) ⇒ Object
17
18
19
20
|
# File 'lib/json_spec/matchers/have_json_type.rb', line 17
def at_path(path)
@path = path
self
end
|
#description ⇒ Object
32
33
34
|
# File 'lib/json_spec/matchers/have_json_type.rb', line 32
def description
message_with_path(%(have JSON type "#{@classes.join(", ")}"))
end
|
#failure_message ⇒ Object
Also known as:
failure_message_for_should
22
23
24
|
# File 'lib/json_spec/matchers/have_json_type.rb', line 22
def failure_message
message_with_path("Expected JSON value type to be #{@classes.join(", ")}, got #{@ruby.class}")
end
|
#failure_message_when_negated ⇒ Object
Also known as:
failure_message_for_should_not
27
28
29
|
# File 'lib/json_spec/matchers/have_json_type.rb', line 27
def failure_message_when_negated
message_with_path("Expected JSON value type to not be #{@classes.join(", ")}, got #{@ruby.class}")
end
|
#matches?(json) ⇒ Boolean
12
13
14
15
|
# File 'lib/json_spec/matchers/have_json_type.rb', line 12
def matches?(json)
@ruby = parse_json(json, @path)
@classes.any? { |c| c === @ruby }
end
|