gpt4 book ai didi

ruby-on-rails - Capybara webkit 允许未设置未知 url

转载 作者:行者123 更新时间:2023-12-04 05:40:08 26 4
gpt4 key购买 nike

我在 Rails 应用程序中使用 capybara webkit 进行一些 rspec 测试。我想使用 allow_unknown_urls 并根据此处的全局配置指南在 spec_helper.rb 文件中进行设置 https://github.com/thoughtbot/capybara-webkit/ - 这是我当前的 spec_helper.rb 文件:

# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
ENV["RAILS_ENV"] ||= "test"
ENV['SERVER_NAME'] = "user.myapp.com"

require File.expand_path("../../config/environment", __FILE__)
require "rspec/rails"


Capybara::Webkit.configure do |config|
# Enable debug mode. Prints a log of everything the driver is doing.
config.debug = false

config.allow_unknown_urls
# Allow pages to make requests to any URL without issuing a warning.

# Allow a specifc domain without issuing a warning.
config.allow_url("checkout.stripe.com")



# Timeout if requests take longer than 5 seconds
config.timeout = 10

# Don't raise errors when SSL certificates can't be validated
config.ignore_ssl_errors

end

Capybara.javascript_driver = :webkit

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end

config.before(:each) do |example|
DatabaseCleaner.strategy= example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
end

config.after(:each) do
DatabaseCleaner.clean
end

config.include SignInHelpers, type: :feature
config.mock_with :rspec

config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
end

正如您在 webkit 配置块中看到的,我正在设置 config.allow_unknown_urls 并明确允许 checkout.stripe.com

当我运行使用 webkit 的测试时,我收到以下警告:
WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt. You're using version 4.8.7.
Request to unknown URL: https://checkout.stripe.com/v3/data/languages/en.json
To block requests to unknown URLs:
page.driver.block_unknown_urls
To allow just this URL:
page.driver.allow_url("https://checkout.stripe.com/v3/data/languages/en.json")
To allow requests to URLs from this host:
page.driver.allow_url("checkout.stripe.com")
Buyer creates a new event

这让我感到困惑,因为我的 webkit 已配置为允许所有未知的 url 并明确地 checkout.stripe.com。我在这里配置不正确的是什么?

最佳答案

你必须使用

config.allow_urls("checkout.stripe.com") 

消除警告的最佳方法是阻止未知 URL,如消息中所述: page.driver.block_unknown_urls .如果您的应用程序依赖于外部资源、API 等,您需要通过 page.drive.allow_url 允许这些 URL。 .如果您不关心警告,可以通过 page.driver.allow_unknown_hosts 使它们静音。 .

关于ruby-on-rails - Capybara webkit 允许未设置未知 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31329419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com