Permalink
Browse files

Added `remove_request_stub` method to API.

  • Loading branch information...
1 parent 6a7804b commit f3abca688df4f806df236cd18e23f483b95a489a @bblimke committed Feb 28, 2013
View
@@ -2,6 +2,11 @@
## Master
+* added `remove_request_stub` method to the api to allow removing unused stubs i.e.
+
+ stub_get = stub_request(:get, "www.example.com")
+ remove_request_stub(stub_get)
+
* `assert_requested` and `assert_not_requested` raise an error if a stub object is provided together with a block.
## 1.9.3
View
@@ -46,6 +46,10 @@ def hash_including(expected)
end
end
+ def remove_request_stub(stub)
+ WebMock::StubRegistry.instance.remove_request_stub(stub)
+ end
+
private
def convert_uri_method_and_options_to_request_and_options(*args, &block)
@@ -36,6 +36,12 @@ def register_request_stub(stub)
stub
end
+ def remove_request_stub(stub)
+ if not request_stubs.delete(stub)
+ raise "Request stub \n\n #{stub.to_s} \n\n is not registered."
+ end
+ end
+
def registered_request?(request_signature)
request_stub_for(request_signature)
end
@@ -444,4 +444,18 @@ def stub_non_globally
end
end
end
+
+ describe "when request stub was removed" do
+ it "should raise an error on request" do
+ stub = stub_request(:get, "www.example.com")
+
+ http_request(:get, "http://www.example.com/")
+
+ remove_request_stub(stub)
+
+ lambda {
+ http_request(:get, "http://www.example.com/")
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
+ end
+ end
end
@@ -9,6 +9,15 @@
@request_stub = WebMock::RequestStub.new(:get, "www.example.com")
end
+ describe "remove_request_stub" do
+ it "should remove stub from registry" do
+ WebMock::StubRegistry.instance.register_request_stub(@request_stub)
+ WebMock::StubRegistry.instance.registered_request?(@request_signature).should == @request_stub
+ WebMock::StubRegistry.instance.remove_request_stub(@request_stub)
+ WebMock::StubRegistry.instance.registered_request?(@request_signature).should == nil
+ end
+ end
+
describe "reset!" do
before(:each) do
WebMock::StubRegistry.instance.register_request_stub(@request_stub)
@@ -4,4 +4,4 @@
it "should report version" do
WebMock.version.should == WebMock::VERSION
end
-end
+end

0 comments on commit f3abca6

Please sign in to comment.