Class: JsonapiSpec::Matchers::HaveJsonapiError

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

Instance Method Summary collapse

Methods included from Helpers

#parse_jsonapi

Instance Method Details

#failure_messageObject



15
16
17
# File 'lib/jsonapi_spec/matchers/have_jsonapi_error.rb', line 15

def failure_message
  "Not a valid jsonapi error #{@validate_error_message}"
end

#failure_message_when_negatedObject



19
20
21
# File 'lib/jsonapi_spec/matchers/have_jsonapi_error.rb', line 19

def failure_message_when_negated
  "Valid jsonapi error"
end

#matches?(json) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
# File 'lib/jsonapi_spec/matchers/have_jsonapi_error.rb', line 6

def matches?(json)
  document = parse_jsonapi(json)
  return false if document.errors.nil?
  true
rescue JSON::API::InvalidDocument => ex
  @validate_error_message = ex.message
  false
end