Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Created a method to unregister an URI #33

Open
wants to merge 1 commit into from

6 participants

@douglascamata

I needed to unregister URIs in one project that I'm using fakeweb and I was unable find this feature, so I implemented it for you.

@djbrowning

+1 This is super useful.

@fguillen

I'm looking for this too!

@lou
lou commented

:+1:

@rebyn

+1. Please merge :-).

@RafaelMCarvalho

+1 Really useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 12, 2012
  1. @douglascamata
This page is out of date. Refresh to see the latest.
View
10 lib/fake_web.rb
@@ -159,6 +159,16 @@ def self.register_uri(*args)
end
end
+ def self.unregister_uri(*args)
+ case args.length
+ when 2
+ Registry.instance.unregister_uri(*args)
+ else
+ raise ArgumentError.new("wrong number of arguments (#{args.length} for 2)")
+ end
+ end
+
+
# call-seq:
# FakeWeb.response_for(method, uri)
#
View
4 lib/fake_web/registry.rb
@@ -18,6 +18,10 @@ def register_uri(method, uri, options)
end
end
+ def unregister_uri(method, uri)
+ uri_map[normalize_uri(uri)][method] = {}
+ end
+
def registered_uri?(method, uri)
!responders_for(method, uri).empty?
end
View
26 test/test_fake_web.rb
@@ -111,6 +111,32 @@ def test_clean_registry_affects_registered_uri
assert !FakeWeb.registered_uri?(:get, "http://example.com")
end
+ def test_unregister_uri
+ FakeWeb.register_uri(:get, "http://example.com", :body => "registered")
+ assert FakeWeb.registered_uri?(:get, "http://example.com")
+ FakeWeb.unregister_uri(:get, "http://example.com")
+ assert !FakeWeb.registered_uri?(:get, "http://example.com")
+ end
+
+ def test_unregister_uri_affects_only_one_uri
+ FakeWeb.register_uri(:get, "http://example.com", :body => "registered")
+ FakeWeb.register_uri(:get, "http://other.example.com", :body => "registered")
+ assert FakeWeb.registered_uri?(:get, "http://example.com")
+ assert FakeWeb.registered_uri?(:get, "http://other.example.com")
+ FakeWeb.unregister_uri(:get, "http://example.com")
+ assert !FakeWeb.registered_uri?(:get, "http://example.com")
+ assert FakeWeb.registered_uri?(:get, "http://other.example.com")
+ end
+
+ def test_unregistered_uri_can_be_registered_again
+ FakeWeb.register_uri(:get, "http://example.com", :body => "registered")
+ assert FakeWeb.registered_uri?(:get, "http://example.com")
+ FakeWeb.unregister_uri(:get, "http://example.com")
+ assert !FakeWeb.registered_uri?(:get, "http://example.com")
+ FakeWeb.register_uri(:get, "http://example.com", :body => "registered")
+ assert FakeWeb.registered_uri?(:get, "http://example.com")
+ end
+
def test_clean_registry_affects_net_http_requests
FakeWeb.register_uri(:get, "http://example.com", :body => "registered")
response = Net::HTTP.start("example.com") { |query| query.get("/") }
Something went wrong with that request. Please try again.