gpt4 book ai didi

javascript - Guard 执行所有规范导致 Capybara + JS 测试返回 : 'Rack application timed out during boot'

转载 作者:行者123 更新时间:2023-12-04 01:08:21 24 4
gpt4 key购买 nike

我有一个带有 Rsped 的 capybara 脚本,其中包括 :js => true,当我单独执行脚本时,该脚本运行良好。耶!这是脚本:

# spec/requests/capybara_and_js_spec.rb
require 'spec_helper'

describe "Associating Articles with Menus" do
it "should include javascript", js: true do
visit root_path
page.should have_selector('script')
end
end

当我执行脚本时,我得到:

.
Finished in 4.22 seconds
1 example, 0 failures

但是,当我通过 Guard Run all 使用我的所有规范执行相同的脚本时,我得到了这个(我省略了几千个测试)

........................*...*..............Rack application timed out during boot
Rack application timed out during boot
F.....................................

最佳答案

我花了很多时间研究这个问题,并发现了一些关于这个问题的有趣博客文章,但没有一个解决方案对我有用。

以下是我尝试过的选项:

我从 Capybara Selenium 的默认 js 驱动程序切换到 Webkit 和 Poltergeist,如下所示:

# Gemfile
gem "capybara-webkit"

# spec/spec_helper.rb
Spork.prefork do
Capybara.javascript_driver = :webkit
end

# Gemfile
gem "poltergeist"

# spec/spec_helper.rb
Spork.prefork do
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
end

但两者都不走运。

根据 this threadthis article我试过:

# spec/spec_helper.rb
Spork.prefork do
Capybara.server_boot_timeout = 600 # Default is 10 my entire suite
end # takes ~550s to run, that's why I
# attempted such a large boot timeout in
# case the time was from beginning of suite
# execution.

没用。

然后我找到this article ,所以我尝试:

# spec/spec_helper.rb
# initial advice was for cucumber, and thus recommended this to be placed in
# the features/env.rb file
def find_available_port
server = TCPServer.new('127.0.0.1', 0)
server.addr[1]
ensure
server.close if server
end

if ENV['TDDIUM'] then
Capybara.server_port = find_available_port
end

但运气不好。

我还检查了我的 database_cleaner 设置以确保 DatabaseCleaner 与我来自 FactoryGirl 的工厂很好地配合,per this issue on StackOverflow.

仍然没有运气。

接下来,我尝试从我的 Guardfile 中较低级别的 rspec 测试中解析出我的 capybara 测试,如下所示:

group 'integration tests' do
# Capybara Tests
guard 'rspec', spec_paths: ['spec/requests'] do
watch(%r{^spec/requests/.+_spec\.rb})
end
# Cucumber Feature Tests
guard 'cucumber', bundler: true do
watch(%r{^features/.+\.feature$})
end
end

group 'unit tests' do
rspec_paths = ['spec/controllers', 'spec/helpers', 'spec/models', 'spec/views']
# RSpec Unit Tests
guard 'rspec', spec_paths: rspec_paths do
watch(%r{^spec/.+_spec\.rb$})
end
# Jasmine JS Unit Tests
guard 'jasmine', all_on_start: false, all_after_pass: false do
watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
end
end

成功了!终于!

关于javascript - Guard 执行所有规范导致 Capybara + JS 测试返回 : 'Rack application timed out during boot' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13387455/

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