Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset webmock after all after(:each/example) hooks #865

Merged
merged 1 commit into from Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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