Skip to content

Commit

Permalink
Merge branch 'master' into v0_10
Browse files Browse the repository at this point in the history
  • Loading branch information
valscion committed Jan 12, 2020
2 parents b9a156e + 3251c65 commit 1d45796
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions spec/support/custom_matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Add better debuggability to be_forbidden failures
RSpec::Matchers.define :be_forbidden do
match(&:forbidden?)

failure_message do |actual|
debug_text_for_failure('forbidden', response: actual, last_request: last_request)
end
end

# Add better debuggability to be_not_found failures
RSpec::Matchers.define :be_not_found do
match(&:not_found?)

failure_message do |actual|
debug_text_for_failure('not_found', response: actual, last_request: last_request)
end
end

# Add better debuggability to be_unprocessable failures
RSpec::Matchers.define :be_unprocessable do
match(&:unprocessable?)

failure_message do |actual|
debug_text_for_failure('unprocessable', response: actual, last_request: last_request)
end
end

# Add better debuggability to be_successful failures
RSpec::Matchers.define :be_successful do
match(&:successful?)

failure_message do |actual|
debug_text_for_failure('successful', response: actual, last_request: last_request)
end
end

# Add better debuggability to be_ok failures
RSpec::Matchers.define :be_ok do
match(&:ok?)

failure_message do |actual|
debug_text_for_failure('ok', response: actual, last_request: last_request)
end
end

def debug_text_for_failure(expected, response:, last_request:)
debug_text = "expected response to be #{expected} but HTTP code was #{response.status}."
debug_text += " Last request was #{last_request.request_method} to #{last_request.fullpath}"
unless last_request.get?
debug_text += " with body:\n" + last_request.body.read
end
debug_text += "\nResponse body was:\n" + response.body
debug_text
end

0 comments on commit 1d45796

Please sign in to comment.