Skip to content

Commit

Permalink
Merge pull request #865 from drews256/reset-after-each
Browse files Browse the repository at this point in the history
Reset webmock after all after(:each/example) hooks
  • Loading branch information
bblimke committed Sep 9, 2020
2 parents 382d84c + b085e3b commit e09cca6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/webmock/rspec.rb
Expand Up @@ -33,7 +33,8 @@
WebMock.disable!
end

config.after(:each) do
config.around(:each) do |example|
example.run
WebMock.reset!
end
}
Expand Down
18 changes: 18 additions & 0 deletions spec/acceptance/shared/stubbing_requests.rb
Expand Up @@ -640,4 +640,22 @@ def stub_non_globally
}.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
end
end

describe "in Rspec around(:each) hook" do
# order goes
# around(:each)
# before(:each)
# after(:each)
# anything after example.run in around(:each)
around(:each) do |example|
example.run
expect {
http_request(:get, "http://www.example.com/")
}.to_not raise_error(WebMock::NetConnectNotAllowedError)
end

it "should still allow me to make a mocked request" do
stub_request(:get, "www.example.com")
end
end
end

0 comments on commit e09cca6

Please sign in to comment.