Class: JsonSpec::Matchers::HaveJsonType

Inherits:
Object
  • Object
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

#initialize(klass) ⇒ HaveJsonType

Returns a new instance of HaveJsonType.



148
149
150
# File 'lib/json_spec/matchers.rb', line 148

def initialize(klass)
  @klass = klass
end

Instance Method Details

#at_path(path) ⇒ Object



157
158
159
160
# File 'lib/json_spec/matchers.rb', line 157

def at_path(path)
  @path = path
  self
end

#descriptionObject



174
175
176
177
178
# File 'lib/json_spec/matchers.rb', line 174

def description
  message = %(have JSON type "#{@klass.to_s}")
  message << %( at path "#{@path}") if @path
  message
end

#failure_message_for_shouldObject



162
163
164
165
166
# File 'lib/json_spec/matchers.rb', line 162

def failure_message_for_should
  message = "Expected JSON value type to be #{@klass}, got #{@ruby.class}"
  message << %( at path "#{@path}") if @path
  message
end

#failure_message_for_should_notObject



168
169
170
171
172
# File 'lib/json_spec/matchers.rb', line 168

def failure_message_for_should_not
  message = "Expected JSON value type to not be #{@klass}, got #{@ruby.class}"
  message << %( at path "#{@path}") if @path
  message
end

#matches?(json) ⇒ Boolean

Returns:

  • (Boolean)


152
153
154
155
# File 'lib/json_spec/matchers.rb', line 152

def matches?(json)
  @ruby = parse_json(json, @path)
  @ruby.is_a?(@klass)
end