fakeweb icon indicating copy to clipboard operation
fakeweb copied to clipboard

Unregister single URIs

Open exchgr opened this issue 10 years ago • 0 comments

It would be great if we had the ability to unregister a single URI. The use case for this would be in specs, where we would ideally want fake URIs to only last the duration of each example, to decrease dependency on the order in which tests are run. For example:

context "with a FakeWeb URI" do
  before do
    FakeWeb.register_uri :any, %r{somerequest.com} # ...
  end

  after do
    FakeWeb.unregister_uri %r{somerequest.com}
  end

  scenario "responds to somerequest.com" do
    expect(Net::HTTP).to receive(:get).with(URI.parse "http://somerequest.com/").and_return(anything)
  end
end

context "without a FakeWeb URI" do
  scenario "doesn't respond to somerequest.com" do
    expect(Net::HTTP).to receive(:get).with(URI.parse "http://somerequest.com/").and_return(nil) # or whatever
  end
end

exchgr avatar Aug 27 '14 22:08 exchgr