Capybara, rspec - Address already in use - bind (2) for 127.0.0.1:3000

I am running a function spec to test my Rails code. Spectrum works great, however there are some js that need to be tested.

As per the documentation, I added a script flag: js => true. However, when I do this, I get the following error:

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'

      

The test is shown below. This is weird because the thing works great when I remove the js flag:

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

      

+3


source to share


1 answer


I experimented and found that when I turn off webkit the tests work. Basically it looks like Capybara was trying to use the same port as webkit and crashing when using js. Don't ask me why or how.

So, I just changed the port that Capybara is running on in rails_helper:



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

      

+2


source







All Articles