Skip to content

Commit

Permalink
Merge pull request #2771 from cbliard/support-rack-mock-response-with…
Browse files Browse the repository at this point in the history
…-have-http-status

Support `have_http_status` with `Rack::MockResponse`
  • Loading branch information
JonRowe committed Jun 26, 2024
1 parent 7214738 commit 5a71461
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rspec/rails/matchers/have_http_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.matcher_for_status(target)
# @param obj [Object] object to convert to a response
# @return [ActionDispatch::TestResponse]
def as_test_response(obj)
if ::ActionDispatch::Response === obj
if ::ActionDispatch::Response === obj || ::Rack::MockResponse === obj
::ActionDispatch::TestResponse.from_response(obj)
elsif ::ActionDispatch::TestResponse === obj
obj
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/rails/matchers/have_http_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def create_response(opts = {})
end
end

context "given a Rack::MockResponse" do
it "returns true for a response with the same code" do
response = ::Rack::MockResponse.new(code, {}, "")

expect(matcher.matches?(response)).to be(true)
end
end

context "given an ActionDispatch::TestResponse" do
it "returns true for a response with the same code" do
response = ::ActionDispatch::TestResponse.new(code).tap { |x|
Expand Down

0 comments on commit 5a71461

Please sign in to comment.