Skip to content

Commit 0bb51ef

Browse files
authored
Merge pull request #2771 from cbliard/support-rack-mock-response-with-have-http-status
Support `have_http_status` with `Rack::MockResponse`
2 parents 591ef0b + 56f26a1 commit 0bb51ef

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/rspec/rails/matchers/have_http_status.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def self.matcher_for_status(target)
3333
# @param obj [Object] object to convert to a response
3434
# @return [ActionDispatch::TestResponse]
3535
def as_test_response(obj)
36-
if ::ActionDispatch::Response === obj
36+
if ::ActionDispatch::Response === obj || ::Rack::MockResponse === obj
3737
::ActionDispatch::TestResponse.from_response(obj)
3838
elsif ::ActionDispatch::TestResponse === obj
3939
obj

spec/rspec/rails/matchers/have_http_status_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ def create_response(opts = {})
1616
end
1717
end
1818

19+
context "given a Rack::MockResponse" do
20+
it "returns true for a response with the same code" do
21+
response = ::Rack::MockResponse.new(code, {}, "")
22+
23+
expect(matcher.matches?(response)).to be(true)
24+
end
25+
end
26+
1927
context "given an ActionDispatch::TestResponse" do
2028
it "returns true for a response with the same code" do
2129
response = ::ActionDispatch::TestResponse.new(code).tap { |x|

0 commit comments

Comments
 (0)