Spork and Guard EADDRINUSE

时间:2013-01-10 07:31:49

标签: ruby-on-rails-3 rspec-rails guard spork

我正在构建一个rails应用程序并使用Spork / Guard / Rspec进行测试。

我在Mac上(10.6.8) - 这是我正在使用的宝石:

gem "rspec-rails", "~> 2.12.1"   
gem "guard-rspec", "~> 2.3.3"   
gem "guard-spork", "~> 1.4.1"   
gem "spork", "~> 0.9.2"   
gem 'rb-fsevent', '~> 0.9.1', :require => false   
gem "growl", "~> 1.0.3"  
gem 'capybara', '1.1.2'

当我编辑我的路线文件时,它应该重新启动spork服务器这里是我的Guardfile中的一行:

guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' }, :foreman => true do
  watch('config/routes.rb')
end

但是最近我刚刚开始添加新路线时出现以下错误:

Loading Spork.prefork block...
Rack::File headers parameter replaces cache_control after Rack 1.5.
Address already in use - bind(2) (Errno::EADDRINUSE)
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `initialize'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `open'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:861:in `open_server'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:759:in `block in open_server'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:757:in `each'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:757:in `open_server'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1342:in `initialize'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1624:in `new'
/Users/cyrus/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/drb/drb.rb:1624:in `start_service'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/lib/spork/server.rb:29:in `listen'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/lib/spork/server.rb:20:in `run'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/lib/spork/runner.rb:75:in `run'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/lib/spork/runner.rb:10:in `run'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/gems/spork-0.9.2/bin/spork:10:in `<top (required)>'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/bin/spork:23:in `load'
/Users/cyrus/.rvm/gems/ruby-1.9.3-p125@h/bin/spork:23:in `<main>'

通常当spork启动时,我会得到以下结果:

Loading Spork.prefork block...
Rack::File headers parameter replaces cache_control after Rack 1.5.
Spork is ready and listening on 8989!

如何避免此错误?

3 个答案:

答案 0 :(得分:2)

我来到这里遇到与OP相同的问题。

在关注'错误是一个错误'的兔子洞后,检查发生故障的代码行,我重新启动了沮丧。我意识到这样做之后,端口上的锁可能来自于我已经退出之前的桌面会话,并且Spork DRb服务器在关闭时挂起了RubyMine,所以也许这就是让端口打开的原因。

果然,我现在可以启动Spork服务器了。

我添加了这个,以便面对此问题的其他人可以考虑是否符合他们的情况。

答案 1 :(得分:0)

通过移除:foreman => true中的Guardfile,我能够摆脱这个问题。现在我没有在我的测试中有意义地使用.env文件中的值,所以应该没问题,但我在Github上提交了一个问题。

答案 2 :(得分:0)

看起来这个错误是一个错误:https://github.com/rails/rails/pull/8812