Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some missing test coverage for FakeWeb.allow_net_connect?

  • Loading branch information...
commit f516ee98a7f75eef5a33ec8fe6205c4620aa545a 1 parent 325db4b
@chrisk chrisk authored
Showing with 25 additions and 1 deletion.
  1. +1 −1  lib/fake_web.rb
  2. +24 −0 test/test_allow_net_connect.rb
View
2  lib/fake_web.rb
@@ -62,7 +62,7 @@ def self.allow_net_connect=(allowed)
# you must supply a path to be tested against your filter
def self.allow_net_connect?(uri = nil)
if Registry.instance.passthrough_uri_map.any?
- raise "You must supply a URI to test" if uri.nil?
+ raise ArgumentError, "You must supply a URI to test" if uri.nil?
Registry.instance.passthrough_uri_matches?(uri)
else
@allow_all_connections
View
24 test/test_allow_net_connect.rb
@@ -129,6 +129,30 @@ def test_question_mark_method_returns_false_after_setting_allow_net_connect_to_f
FakeWeb.allow_net_connect = false
assert !FakeWeb.allow_net_connect?
end
+
+ def test_question_mark_method_raises_with_no_argument_when_allow_net_connect_is_a_whitelist
+ FakeWeb.allow_net_connect = "http://example.com"
+ exception = assert_raise ArgumentError do
+ FakeWeb.allow_net_connect?
+ end
+ assert_equal "You must supply a URI to test", exception.message
+ end
+
+ def test_question_mark_method_returns_true_when_argument_is_same_uri_as_allow_net_connect_string
+ FakeWeb.allow_net_connect = "http://example.com"
+ assert FakeWeb.allow_net_connect?("http://example.com/")
+ end
+
+ def test_question_mark_method_returns_true_when_argument_matches_allow_net_connect_regexp
+ FakeWeb.allow_net_connect = %r[^https?://example.com/]
+ assert FakeWeb.allow_net_connect?("http://example.com/path")
+ assert FakeWeb.allow_net_connect?("https://example.com:443/")
+ end
+
+ def test_question_mark_method_returns_false_when_argument_does_not_match_allow_net_connect_regexp
+ FakeWeb.allow_net_connect = %r[^http://example.com/]
+ assert !FakeWeb.allow_net_connect?("http://example.com:8080")
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.