Skip to content

Commit

Permalink
Update expected example.com behavior
Browse files Browse the repository at this point in the history
IANA has recently changed http://example.com/ to redirect to
http://iana.org/domain/example instead of serving a proper page. As
WebMock specs rely on old example.com behavior, this change caused a
major test breakage.

This commit forces specs to expect a "302 Found" response from
example.com
  • Loading branch information
grig committed Mar 7, 2011
1 parent cd68c86 commit 0e5360b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions spec/net_http_spec.rb
Expand Up @@ -57,7 +57,7 @@
req = Net::HTTP::Post.new("/")
Net::HTTP.start("www.example.com") {|http|
http.request(req, StringIO.new("my_params"))
}.body.should =~ /Example Web Page/
}.body.should =~ /^$/
end

it "should handle requests with block passed to read_body", :net_connect => true do
Expand All @@ -71,7 +71,7 @@
end
end
end
body.should =~ /Example Web Page/
body.should =~ /^$/
end

it "should return a Net::ReadAdapter from response.body when a stubbed request is made with a block and #read_body" do
Expand Down Expand Up @@ -128,7 +128,7 @@
end

describe 'after_request callback support', :net_connect => true do
let(:expected_body_regex) { /You have reached this web page by typing.*example\.com/ }
let(:expected_body_regex) { /^$/ }

before(:each) do
WebMock.allow_net_connect!
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -42,8 +42,8 @@ def should_pass
def setup_expectations_for_real_example_com_request(options = {})
defaults = { :host => "www.example.com", :port => 80, :method => "GET",
:path => "/",
:response_code => 200, :response_message => "OK",
:response_body => "<title>example</title>" }
:response_code => 302, :response_message => "Found",
:response_body => "" }
setup_expectations_for_real_request(defaults.merge(options))
end

11 changes: 5 additions & 6 deletions spec/webmock_shared.rb
Expand Up @@ -4,7 +4,7 @@
SAMPLE_HEADERS = { "Content-Length" => "8888", "Accept" => "application/json" }
ESCAPED_PARAMS = "x=ab%20c&z=%27Stop%21%27%20said%20Fred"
NOT_ESCAPED_PARAMS = "z='Stop!' said Fred&x=ab c"
WWW_EXAMPLE_COM_CONTENT_LENGTH = 596
WWW_EXAMPLE_COM_CONTENT_LENGTH = 0
end

class MyException < StandardError; end;
Expand Down Expand Up @@ -33,8 +33,7 @@ class MyException < StandardError; end;

it "should make a real web request if request is not stubbed" do
setup_expectations_for_real_example_com_request
http_request(:get, "http://www.example.com/").
body.should =~ /.*example.*/
http_request(:get, "http://www.example.com/").status.should == "302"
end

it "should make a real https request if request is not stubbed" do
Expand Down Expand Up @@ -128,7 +127,7 @@ class MyException < StandardError; end;
end

it "should allow a real request to allowed host", :net_connect => true do
http_request(:get, "http://www.example.org/").status.should == "200"
http_request(:get, "http://www.example.org/").status.should == "302"
end
end
end
Expand Down Expand Up @@ -1493,8 +1492,8 @@ def call(request)
end

it "should pass response with status and message" do
@response.status[0].should == 200
@response.status[1].should == "OK"
@response.status[0].should == 302
@response.status[1].should == "Found"
end

it "should pass response with headers" do
Expand Down

0 comments on commit 0e5360b

Please sign in to comment.