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
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 7
def initialize(size)
@expected = size
end
|
Instance Method Details
#at_path(path) ⇒ Object
17
18
19
20
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 17
def at_path(path)
@path = path
self
end
|
#description ⇒ Object
30
31
32
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 30
def description
message_with_path(%(have JSON size "#{@expected}"))
end
|
#failure_message_for_should ⇒ Object
22
23
24
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 22
def failure_message_for_should
message_with_path("Expected JSON value size to be #{@expected}, got #{@actual}")
end
|
#failure_message_for_should_not ⇒ Object
26
27
28
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 26
def failure_message_for_should_not
message_with_path("Expected JSON value size to not be #{@expected}, got #{@actual}")
end
|
#matches?(json) ⇒ Boolean
11
12
13
14
15
|
# File 'lib/json_spec/matchers/have_json_size.rb', line 11
def matches?(json)
ruby = parse_json(json, @path)
@actual = Enumerable === ruby ? ruby.size : 1
@actual == @expected
end
|