Class: JsonSpec::Matchers::HaveJsonSize
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 HaveJsonSize.
7
8
9
10
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 7
def initialize(size)
@expected = size
@path = nil
end
|
Instance Method Details
#at_path(path) ⇒ Object
19
20
21
22
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 19
def at_path(path)
@path = path
self
end
|
#description ⇒ Object
34
35
36
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 34
def description
message_with_path(%(have JSON size "#{@expected}"))
end
|
#failure_message ⇒ Object
Also known as:
failure_message_for_should
24
25
26
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 24
def failure_message
message_with_path("Expected JSON value size to be #{@expected}, got #{@actual}")
end
|
#failure_message_when_negated ⇒ Object
Also known as:
failure_message_for_should_not
29
30
31
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 29
def failure_message_when_negated
message_with_path("Expected JSON value size to not be #{@expected}, got #{@actual}")
end
|
#matches?(json) ⇒ Boolean
12
13
14
15
16
17
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 12
def matches?(json)
ruby = parse_json(json, @path)
raise EnumerableExpected.new(ruby) unless Enumerable === ruby
@actual = ruby.size
@actual == @expected
end
|