Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #172 from oestrich/fix_to_rack_port

Pass through SERVER_PORT when stubbing to rack
  • Loading branch information...
commit cf7d536eabefcb048fbdac74a0530eca11dc3b35 2 parents 224d056 + 56287b4
@bblimke authored
View
3  lib/webmock/rack_response.rb
@@ -35,7 +35,8 @@ def build_rack_env(request)
'CONTENT_LENGTH' => body.size,
'PATH_INFO' => uri.path,
'QUERY_STRING' => uri.query || '',
- 'SERVER_NAME' => uri.host
+ 'SERVER_NAME' => uri.host,
+ 'SERVER_PORT' => uri.port
}
env['HTTP_AUTHORIZATION'] = 'Basic ' + [uri.userinfo].pack('m').delete("\r\n") if uri.userinfo
View
8 spec/acceptance/shared/returning_declared_responses.rb
@@ -238,12 +238,14 @@ def call(request)
end
describe "when response is declared as an Rack app" do
- before(:each) do
+ it "should return response returned by the rack app" do
stub_request(:any, "http://www.example.com/greet").to_rack(MyRackApp)
+ http_request(:post, 'http://www.example.com/greet', :body => 'name=Jimmy').body.should == 'Good to meet you, Jimmy!'
end
- it "should return response returned by the rack app" do
- http_request(:post, 'http://www.example.com/greet', :body => 'name=Jimmy').body.should == 'Good to meet you, Jimmy!'
+ it "should pass along the port number to the rack app" do
+ stub_request(:get, "http://www.example.com/compute").to_rack(MyRackApp)
+ http_request(:get, "http://www.example.com/compute").status.should == "200"
end
end
View
6 spec/support/my_rack_app.rb
@@ -26,6 +26,12 @@ def self.call(env)
when ['POST', '/greet']
name = env["rack.input"].read[/name=([^&]*)/, 1] || "World"
[200, {}, ["Good to meet you, #{name}!"]]
+ when ['GET', '/compute']
+ if env['SERVER_PORT'] == 80
+ [200, {}, [""]]
+ else
+ [401, {}, [""]]
+ end
else
[404, {}, ['']]
end
Please sign in to comment.
Something went wrong with that request. Please try again.