forked from chrisk/fakeweb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug where trailing slashes were considered significant for requ…
…ests to the root of a domain
- Loading branch information
Showing
2 changed files
with
72 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require File.join(File.dirname(__FILE__), "test_helper") | ||
|
||
class TestFakeWebTrailingSlashes < Test::Unit::TestCase | ||
|
||
def setup | ||
FakeWeb.clean_registry | ||
@original_allow_net_connect = FakeWeb.allow_net_connect? | ||
end | ||
|
||
def teardown | ||
FakeWeb.allow_net_connect = @old_allow_net_conncet | ||
end | ||
|
||
def test_registering_root_without_slash_and_ask_predicate_method_with_slash | ||
FakeWeb.register_uri(:get, "http://www.google.com", :string => "Google") | ||
assert FakeWeb.registered_uri?(:get, "http://www.google.com/") | ||
end | ||
|
||
def test_registering_root_without_slash_and_request | ||
FakeWeb.register_uri(:get, "http://www.google.com", :string => "Google") | ||
response = Net::HTTP.start("www.google.com") { |query| query.get('/') } | ||
assert_equal "Google", response.body | ||
end | ||
|
||
def test_registering_root_with_slash_and_ask_predicate_method_without_slash | ||
FakeWeb.register_uri(:get, "http://www.google.com/", :string => "Google") | ||
assert FakeWeb.registered_uri?(:get, "http://www.google.com") | ||
end | ||
|
||
def test_registering_root_with_slash_and_request | ||
FakeWeb.register_uri(:get, "http://www.google.com/", :string => "Google") | ||
response = Net::HTTP.start("www.google.com") { |query| query.get('/') } | ||
assert_equal "Google", response.body | ||
end | ||
|
||
def test_registering_path_without_slash_and_ask_predicate_method_with_slash | ||
FakeWeb.register_uri(:get, "http://www.example.com/users", :string => "User list") | ||
assert !FakeWeb.registered_uri?(:get, "http://www.example.com/users/") | ||
end | ||
|
||
def test_registering_path_without_slash_and_request_with_slash | ||
FakeWeb.allow_net_connect = false | ||
FakeWeb.register_uri(:get, "http://www.example.com/users", :string => "User list") | ||
assert_raise FakeWeb::NetConnectNotAllowedError do | ||
response = Net::HTTP.start("www.example.com") { |query| query.get('/users/') } | ||
end | ||
end | ||
|
||
def test_registering_path_with_slash_and_ask_predicate_method_without_slash | ||
FakeWeb.register_uri(:get, "http://www.example.com/users/", :string => "User list") | ||
assert !FakeWeb.registered_uri?(:get, "http://www.example.com/users") | ||
end | ||
|
||
def test_registering_path_with_slash_and_request_without_slash | ||
FakeWeb.allow_net_connect = false | ||
FakeWeb.register_uri(:get, "http://www.example.com/users/", :string => "User list") | ||
assert_raise FakeWeb::NetConnectNotAllowedError do | ||
response = Net::HTTP.start("www.example.com") { |query| query.get('/users') } | ||
end | ||
end | ||
|
||
end |