Class: Webhookdb::SpecHelpers::Service::HaveStatusMatcher

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers
Defined in:
lib/webhookdb/spec_helpers/service.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_status) ⇒ HaveStatusMatcher

Returns a new instance of HaveStatusMatcher.



328
329
330
# File 'lib/webhookdb/spec_helpers/service.rb', line 328

def initialize(expected_status)
  @expected_status = expected_status
end

Instance Method Details

#failure_messageObject



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/webhookdb/spec_helpers/service.rb', line 341

def failure_message
  parsed = self.parsed_body
  msg = "expected response status %d, got a %d response instead\n" % [@expected_status, @response.status]
  if parsed&.include?("error")
    suffix = +""
    if (errmsg = parsed["error"].delete("message"))
      suffix << ("\nMessage: %s" % [errmsg])
    end
    if (backtrace = parsed["error"].delete("backtrace"))
      suffix << ("\nBacktrace:\n%s" % [backtrace])
    end
    msg << ("Body: %s%s" % [parsed.to_json, suffix])
  else
    msg << ("Body: %s" % [@response.body])
  end
  return msg
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


332
333
334
335
336
337
338
339
# File 'lib/webhookdb/spec_helpers/service.rb', line 332

def matches?(response)
  @response = response
  unless response.respond_to?(:status)
    raise "response has no .status method, did you pass in last_response.status " \
          "instead of last_response?"
  end
  return response.status == @expected_status
end