Skip to content

Commit

Permalink
Merge pull request #172 from oestrich/fix_to_rack_port
Browse files Browse the repository at this point in the history
Pass through SERVER_PORT when stubbing to rack
  • Loading branch information
bblimke committed Apr 4, 2012
2 parents 224d056 + 56287b4 commit cf7d536
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/webmock/rack_response.rb
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions spec/acceptance/shared/returning_declared_responses.rb
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions spec/support/my_rack_app.rb
Expand Up @@ -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
Expand Down

0 comments on commit cf7d536

Please sign in to comment.