Capybara 发送意外的 google http 请求

Capybara sends unexpected google http requests

提问人:mr_muscle 提问时间:10/8/2023 最后编辑:mr_muscle 更新时间:10/8/2023 访问量:54

问:

在我的 Rails 7 应用程序中,我有一个简单的单页 Web 表单,用户在其中有一个输入文本字段和提交按钮。用户在字段中提供一些文本并按下提交按钮后,表单提交将通过 Turbo 异步处理。我用水豚准备了一个功能测试:

  context 'when the user enters a valid params', js: true do
    it 'renders the image after async form submision' do
      breed = Faker::Creature::Dog.breed

      visit root_path
      fill_in 'breed', with: breed

      click_button 'Submit'

      expect(page).to have_css("turbo-frame[id='dog-image']")
    end
   end

当我运行此测试时,我收到一个奇怪的HTTP请求:

     WebMock::NetConnectNotAllowedError:
       Real HTTP connections are disabled. Unregistered request: GET https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build.json with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'googlechromelabs.github.io', 'User-Agent'=>'Ruby'}

我允许localhost请求,根据我的:spec_helper.rb

require 'capybara/rspec'
require 'rails_helper'
require 'webmock/rspec'
require 'selenium-webdriver'

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.javascript_driver = :chrome

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end
  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end
  config.shared_context_metadata_behavior = :apply_to_host_groups
  
  WebMock.disable_net_connect! allow_localhost: true
  Capybara.server = :puma, { Silent: true }
  Capybara.javascript_driver = :selenium_chrome_headless
  Capybara.default_max_wait_time = 5
  Capybara.server_host = 'localhost'
  Capybara.server_port = 3000
  Capybara.app_host = 'http://localhost'
end

我认为这是一个配置问题,因为当我进行测试时将是绿色的。我不认为把它放在那里是一个好的做法。我在设置中错过了什么?WebMock.allow_net_connect!WebMock.allow_net_connect!

Ruby-on-Rails 红宝石 RSPec 水豚

评论

0赞 max 10/8/2023
我认为它只是在寻找更新的chrome。而不是使用 WebMock.allow_net_connect!只是有选择地将该 URI 列入白名单。github.com/bblimke/......

答: 暂无答案