forked from chrisk/fakeweb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require File.join(File.dirname(__FILE__), "test_helper") | ||
|
||
class TestFakeWebAllowNetConnect < Test::Unit::TestCase | ||
include FakeWebTestHelper | ||
|
||
def test_unregistered_requests_are_passed_through_when_allow_net_connect_is_true | ||
original_value = FakeWeb.allow_net_connect? | ||
FakeWeb.allow_net_connect = true | ||
|
||
setup_expectations_for_real_apple_hot_news_request | ||
Net::HTTP.get(URI.parse("http://images.apple.com/main/rss/hotnews/hotnews.rss")) | ||
|
||
FakeWeb.allow_net_connect = original_value | ||
end | ||
|
||
def test_raises_for_unregistered_requests_when_allow_net_connect_is_false | ||
original_value = FakeWeb.allow_net_connect? | ||
FakeWeb.allow_net_connect = false | ||
|
||
assert_raise RuntimeError do | ||
Net::HTTP.get(URI.parse('http://example.com/')) | ||
end | ||
|
||
FakeWeb.allow_net_connect = original_value | ||
end | ||
|
||
def test_question_mark_method_returns_true_after_setting_allow_net_connect_to_true | ||
original_value = FakeWeb.allow_net_connect? | ||
FakeWeb.allow_net_connect = true | ||
assert FakeWeb.allow_net_connect? | ||
FakeWeb.allow_net_connect = original_value | ||
end | ||
|
||
def test_question_mark_method_returns_false_after_setting_allow_net_connect_to_false | ||
original_value = FakeWeb.allow_net_connect? | ||
FakeWeb.allow_net_connect = false | ||
assert !FakeWeb.allow_net_connect? | ||
FakeWeb.allow_net_connect = original_value | ||
end | ||
|
||
def test_allow_net_connect_is_true_by_default | ||
assert FakeWeb.allow_net_connect? | ||
end | ||
|
||
end |