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
disable_net_connect!
affects subsequent Capybara test even if WebMock is disabled
#870
Comments
@asterite I confirm that something is weird here and I don't know why. Perhaps there is another ruby process started on the first visit which is not affected by disable. Not sure. |
have you tried adding an expectation after When running Capybara with a JS profile, the I have had a similar issue and identified that the problem was that The order of these two I found out, in my project, that we were calling If, during that small time window, the browser is able to trigger a request to the application, and the application makes a request to the outside world, then that request would should in WebMock's registry for the next spec. Fixing the Now I wonder how #865 could impact our problem. Would it be an improvement or make it worse? |
If anyone is experiencing the problem, take a look at the Gotchas section: https://github.com/teamcapybara/capybara#gotchas |
@KirillKayumov Thanks for the link. Which Gotcha in particular do you think is relevant here? 🙏🏻 |
|
@KirillKayumov Thank you. To me, that gotcha seems unrelated to the initial problem in this issue? |
@davidstosik yes, you're right, I'm sorry for the confusion. Lines 28 to 39 in d19b472
.disable_net_connect! does webmock/lib/webmock/webmock.rb Lines 117 to 120 in d19b472
webmock/lib/webmock/webmock.rb Lines 49 to 54 in d19b472
So, I may recommend doing:
I hope it'll help! |
This one is pretty strange and I can't figure out what's going on.
The gist
If you have a spec like this:
and run it in order (
rspec --order defined
) then you get two failures in "baz":If we remove the first test and only keep the last two:
and run the specs with
rspec --order defined
, the tests pass.Note that in both cases when we reach "baz", WebMock is disabled and configured to disallow net connections, but in the first case it fails... I don't know why, but it seems that allowing localhost and visiting the first path somehow affects what happens with subsequent test.
Where is the problem?
The problem seems to be a weird interaction of WebMock, RSPec, Selenium and Capybara. Maybe the problem is not in WebMock.
Also, if we remove
js: true
from the first snippet, it works fine... so maybe Capybara is setting up something that eventually messes up the way WebMock works?But maybe you have an idea of why this is happening?
Full steps to reproduce
The short method
You can download this zip file
test_capybara_webmock.zip , uncompress it, and inside that directory run:
The long method
rails new test_capybara_webmock -T
cd test_capybara_webmock
bundle
spec/features/home_spec.rb
file with the contents of the first snippet in this post.bundle exec rspec spec/features/home_spec.rb
and see it failThe End
Let me know if something is not clear! I'm happy to help figuring out what's going on, and fixing it if possible.
Thank you!
The text was updated successfully, but these errors were encountered: