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

Empty list of proxied requests #52

Open
brindu opened this issue Feb 23, 2023 · 0 comments
Open

Empty list of proxied requests #52

brindu opened this issue Feb 23, 2023 · 0 comments

Comments

@brindu
Copy link

brindu commented Feb 23, 2023

I'm using this gem to stub external requests but it has no effect so far.

My configuration in spec/spec_helper.rb:

  require 'capybara/rspec'
  require 'capybara/webmock'

  Capybara.javascript_driver = :capybara_webmock_chrome_headless

  require 'webmock/rspec'

  RSpec.configure do |config|
    config.before(:each) do |example|
      if example.metadata[:type] == :feature
        stub_request(:get, 'https://api.intercom.io/companies')
        Capybara::Webmock.start
      end
    end

    config.after(:suite) do
      Capybara::Webmock.stop
    end
end 

The test itself:

require 'rails_helper'

describe 'visit homepage', type: :feature do
  subject { visit root_path }

  it 'works', js: true do
    expect do
      subject
    end.not_to raise_error
  end
end

The test raixse this error:

Failures:

  1) visit homepage works
     Failure/Error:
       expect do
         subject
       end.not_to raise_error

       expected no Exception, got #<WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET h... "https://api.intercom.io/companies")

Which indicates the external is not stubbed... As documented in the README I inspect the list of proxied requests that remains empty.
I tried to populate it beforehand in different ways as in the follwing

Capybara::Webmock.proxied_requests << 'https://api.intercom.io/companies'
Capybara::Webmock.proxied_requests << URI('https://api.intercom.io/companies')
Capybara::Webmock.proxied_requests << stub_request(:get, 'https://api.intercom.io/companies') 

None of this works.

I can't find in the README neither in the code itself how to populate this list of proxied/stubbed requests and simply following the README instructions does not work. Can someone help clarify how this is supposed to work?

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

1 participant