Class: JsonSpec::Matchers::HaveJsonSize
- Inherits:
-
Object
- Object
- JsonSpec::Matchers::HaveJsonSize
show all
- Includes:
- Helpers
- Defined in:
- lib/json_spec/matchers.rb
Instance Method Summary
collapse
Methods included from Helpers
#generate_normalized_json, #normalize_json, #parse_json
Constructor Details
Returns a new instance of HaveJsonSize.
184
185
186
|
# File 'lib/json_spec/matchers.rb', line 184
def initialize(size)
@expected = size
end
|
Instance Method Details
#at_path(path) ⇒ Object
194
195
196
197
|
# File 'lib/json_spec/matchers.rb', line 194
def at_path(path)
@path = path
self
end
|
#description ⇒ Object
211
212
213
214
215
|
# File 'lib/json_spec/matchers.rb', line 211
def description
message = %(have JSON size "#{@expected}")
message << %( at path "#{@path}") if @path
message
end
|
#failure_message_for_should ⇒ Object
199
200
201
202
203
|
# File 'lib/json_spec/matchers.rb', line 199
def failure_message_for_should
message = "Expected JSON value size to be #{@expected}, got #{@actual}"
message << %( at path "#{@path}") if @path
message
end
|
#failure_message_for_should_not ⇒ Object
205
206
207
208
209
|
# File 'lib/json_spec/matchers.rb', line 205
def failure_message_for_should_not
message = "Expected JSON value size to not be #{@expected}, got #{@actual}"
message << %( at path "#{@path}") if @path
message
end
|
#matches?(json) ⇒ Boolean
188
189
190
191
192
|
# File 'lib/json_spec/matchers.rb', line 188
def matches?(json)
ruby = parse_json(json, @path)
@actual = ruby.is_a?(Enumerable) ? ruby.size : 1
@actual == @expected
end
|