Class: JsonapiSpec::Matchers::HaveJsonapiAttribute

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/jsonapi_spec/matchers/have_jsonapi_attribute.rb

Instance Method Summary collapse

Methods included from Helpers

#parse_jsonapi

Constructor Details

#initialize(attribute) ⇒ HaveJsonapiAttribute

Returns a new instance of HaveJsonapiAttribute.



6
7
8
# File 'lib/jsonapi_spec/matchers/have_jsonapi_attribute.rb', line 6

def initialize(attribute)
  @attribute = attribute
end

Instance Method Details

#failure_messageObject



17
18
19
# File 'lib/jsonapi_spec/matchers/have_jsonapi_attribute.rb', line 17

def failure_message
  "Not have a attribute #{@attribute}"
end

#failure_message_when_negatedObject



21
22
23
# File 'lib/jsonapi_spec/matchers/have_jsonapi_attribute.rb', line 21

def failure_message_when_negated
  "have jsonapi attribute #{@attribute}"
end

#matches?(json) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/jsonapi_spec/matchers/have_jsonapi_attribute.rb', line 10

def matches?(json)
  document = parse_jsonapi(json)
  document['data']['attributes'].key?(@attribute)
rescue JSONAPI::Parser::InvalidDocument
  false
end