gpt4 book ai didi

capybara - 使用 Capybara 测试 URL

转载 作者:行者123 更新时间:2023-12-02 03:08:45 27 4
gpt4 key购买 nike

我很好奇是否有更好的方法来测试页面中是否存在完整的 URL(包括协议(protocol))。

使用 Capybara 2.10.2 和 Rails 5.0.0.1,我有以下设置:

rails_helper.rb

# Other config and content excluded for brevity.

RSpec.configure do |config|
config.include Rails.application.routes.url_helpers
end

test_url_spec.rb

describe 'Widget', type: :feature, js: true do
it 'shows correct URL' do
# Sets the default_url_options to match the session's server config.
# default_url_options is used by the url
self.default_url_options = {host: page.server.host, port: page.server.port}
# Assume that page contains the full URL.
expect(page).to have_content(root_url)
end
end

我相信我可以将 default_url_options setter 移动到适当上下文中的 before(:each) block 。默认情况下,URL 选项不包含在 Capybara 中。我无法想象我还能在哪里使用它们。

有什么想法吗?

最佳答案

我不知道这是否适合你,但这对我有用:

RSpec.configure do |config|
config.before(:type => :feature) do
default_url_options[:host] = "http://localhost:31337"
end
end

Capybara.server_port = 31337
Capybara.app_host = "http://localhost:31337"

关于capybara - 使用 Capybara 测试 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41007360/

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