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

Cannot use the same url twice #1052

Open
rdptz opened this issue Mar 25, 2024 · 4 comments
Open

Cannot use the same url twice #1052

rdptz opened this issue Mar 25, 2024 · 4 comments

Comments

@rdptz
Copy link

rdptz commented Mar 25, 2024

It seems WM doesn't support stubbing the same url twice in the same spec. How can this be possibile?
If you run the single "its" below, everything is fine, if you run the whole specs the second one always fails with:

WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: POST http://localhost/foobar with body 'BAR' with headers {'Connection'=>'close', 'Content-Type'=>'application/xml', 'Host'=>'localhost', 'User-Agent'=>'http.rb/5.1.1'}

  it 'returns the foo' do
    stub_request(:post, 'http://localhost/foobar').with(body: 'FOO').to_return(status: 200, body: '')
    expect(1).to eq(1)
  end

  it 'returns the bar' do
    stub_request(:post, 'http://localhost/foobar').with(body: 'BAR').to_return(status: 200, body: '')
    expect(1).to eq(1)
  end

thanks,

@bblimke
Copy link
Owner

bblimke commented Apr 1, 2024

@rdptz can you please provide the sample code to reproduce the problem? your example doesn't have any code that executes the request.
Do you have require 'webmock/rspec' in your rails_helper.rb?

@rdptz
Copy link
Author

rdptz commented Apr 2, 2024

Hi, that is the sample code. You cannot stub two requests with the same url. The second spec raises:

WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: POST http://localhost/foobar with body 'BAR' with headers {'Connection'=>'close', 'Content-Type'=>'application/xml', 'Host'=>'localhost', 'User-Agent'=>'http.rb/5.1.1'}

Yes I have require 'webmock/rspec' in my rails_helper.rb

Everything works fine as long as I do not stub 2 requests with the same url.

@ukolovda
Copy link

I have the same trouble now...

@ukolovda
Copy link

I have the same trouble now...

Sorry, it was my mistake. It works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants