Skip to content

Empty list of proxied requests #52

Open
@brindu

Description

@brindu

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions