class RSpec::Resources::DSL::Matchers::ErrorMatcher

Public Class Methods

new(code, msg) click to toggle source
# File lib/rspec/resources/dsl/matchers/error_matcher.rb, line 8
def initialize(code, msg)
  @code = code
  @msg = msg
end

Public Instance Methods

description() click to toggle source
# File lib/rspec/resources/dsl/matchers/error_matcher.rb, line 34
def description
  "return an error with code #{@code}"
end
failure_message() click to toggle source
# File lib/rspec/resources/dsl/matchers/error_matcher.rb, line 26
def failure_message
  "Expected to get an error but got code #{@subject.code} and body #{@subject.body}"
end
failure_message_when_negated() click to toggle source
# File lib/rspec/resources/dsl/matchers/error_matcher.rb, line 30
def failure_message_when_negated
  "Expected to get no error but got code #{@subject.code} and body #{@subject.body}"
end
match_doc(error_doc) click to toggle source
# File lib/rspec/resources/dsl/matchers/error_matcher.rb, line 22
def match_doc(error_doc)
  @msg.nil? || Util.access_by_path(error_doc, Util.document_format_hash[:error_detail_path]).match(@msg)
end
matches?(subject) click to toggle source
# File lib/rspec/resources/dsl/matchers/error_matcher.rb, line 13
def matches?(subject)
  @subject = subject

  error_docs = Util.access_by_path(JSON.parse(@subject.body), Util.document_format_hash[:error_path])
  error_docs = [error_docs] unless error_docs.is_a?(Array)

  @subject.code == @code.to_s && error_docs.any? { |d| match_doc(d) }
end

Private Instance Methods

obj_name() click to toggle source
# File lib/rspec/resources/dsl/matchers/error_matcher.rb, line 40
def obj_name
  @obj.class.name.downcase
end