capybara,rspec - 地址已经在使用 - bind(2)for 127.0.0.1:3000

时间:2015-05-27 03:16:00

标签: ruby-on-rails rspec capybara

我正在运行一个功能规范来测试一些Rails代码。规范运行正常,但有些js需要测试。

根据文档,我添加了:js =>方案的真实标志。但是,当我这样做时,我收到以下错误:

Failures:

  1) User can check off items as being owned user can check off an item on the checklist
     Failure/Error: Unable to find matching line from backtrace
     Errno::EADDRINUSE:
       Address already in use - bind(2) for 127.0.0.1:3000
     # /Users/agazoom/.rvm/gems/ruby-2.2.1@kollista/gems/rack-1.6.0/lib/rack/handler/webrick.rb:32:in `new'
     # /Users/agazoom/.rvm/gems/ruby-2.2.1@kollista/gems/rack-1.6.0/lib/rack/handler/webrick.rb:32:in `run'
     # /Users/agazoom/.rvm/gems/ruby-2.2.1@kollista/gems/capybara-2.4.4/lib/capybara.rb:173:in `run_default_server'
     # /Users/agazoom/.rvm/gems/ruby-2.2.1@kollista/gems/capybara-2.4.4/lib/capybara.rb:359:in `block (2 levels) in <top (required)>'
     # /Users/agazoom/.rvm/gems/ruby-2.2.1@kollista/gems/capybara-2.4.4/lib/capybara/server.rb:70:in `call'
     # /Users/agazoom/.rvm/gems/ruby-2.2.1@kollista/gems/capybara-2.4.4/lib/capybara/server.rb:70:in `block in boot'

测试如下。这很奇怪,因为当我删除js标志时,事情运行正常:

scenario "user can check off an item on the checklist", :js => true do
   visit root_path
   expect(page).to have_title("agazoom")
end

1 个答案:

答案 0 :(得分:4)

我做了一些实验,发现当我关闭webkit时,测试工作正常。基本上,看起来Capybara试图使用与webkit相同的端口并且在使用js时失败。不要问我有关原因或方法的详细信息。

所以,我刚刚改变了Capybara在'rails_helper'中运行的端口:

Capybara.configure do |config|
  .
  .
  config.server_port = 3001
end