我正在阅读 Rails 教程第 3.6 章,所以我正在尝试实现 Rspec、Guard 和 Spork。在这一点上,一切似乎都在工作,但是当 Guard 启动时,我被 EADDRINUSE 错误所困扰。我的环境是 Windows 8 x64、BiNami Rubystack 1.9.3-6、Ruby 1.9.3p392、Rails 3.2.13 和 RubyMine 5.4.2。同样的错误发生在 RubyMine 或 CLI 中。
在启动 Guard 之前和终止 Guard 之后,我使用 netstat 验证端口未在使用中。所以,Guard似乎是唯一的因素。我搜索了类似的问题,并确保我发现的任何问题都不匹配。我试图最小化我的环境以隔离问题但没有成功。例如,我试图消除多余的 gem,还试图使那些被指定为通用而没有版本规范的 gem。我所做的一切都没有改变。
我的宝石文件:
source 'https://rubygems.org'
gem 'rails', '3.2.13'
group :development, :test do
gem 'rspec-rails', '2.13.2'
gem 'database_cleaner'
gem 'guard'
gem 'win32console'
gem 'growl'
gem 'ruby_gntp'
gem 'rb-notifu'
gem 'guard-rspec'
gem 'wdm'
gem 'guard-spork', '1.2.0'
gem 'childprocess', '0.3.6'
gem 'spork', '1.0.0rc3'
gem 'spork-rails'
gem 'cucumber'
gem 'cucumber-rails', :require => false
end
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
我的保护文件:
require 'active_support/core_ext'
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
watch('test/test_helper.rb')
watch('spec/support/')
end
错误记录:
D:\BitNami\rubystack-1.9.3-6\ruby\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) D:/BitNami/rubystack-1.9.3-6/ruby/bin/bundle exec guard
17:03:39 - INFO - Guard uses GNTP to send notifications.
17:03:39 - INFO - Guard uses TerminalTitle to send notifications.
17:03:40 - INFO - Starting Spork for RSpec, Cucumber
Using RSpec, Rails
Using Cucumber, Rails
-- Rinda Ring Server listening for connections...
D:/BitNami/rubystack-1.9.3-6/ruby/lib/ruby/1.9.1/rinda/ring.rb:35:in `bind': Only one usage of each socket address (protocol/network address/port) is normally permitted. - bind(2) (Errno::EADDRINUSE)
from D:/BitNami/rubystack-1.9.3-6/ruby/lib/ruby/1.9.1/rinda/ring.rb:35:in `initialize'
from ring_server.rb:7:in `new'
from ring_server.rb:7:in `<main>'
-- Starting to fill pool...
Wait until at least one slave is provided before running tests...
** CTRL+BREAK to stop Spork and kill all ruby slave processes **
-- Starting to fill pool...
Wait until at least one slave is provided before running tests...
** CTRL+BREAK to stop Spork and kill all ruby slave processes **
Spork is ready and listening on 8989!
Spork is ready and listening on 8990!
-- build slave 1...
-- build slave 2...
Preloading Rails environment
-- build slave 1...
-- build slave 2...
Preloading Rails environment
Preloading Rails environment
Preloading Rails environment
Loading Spork.prefork block...
Loading Spork.prefork block...
Loading Spork.prefork block...
Loading Spork.prefork block...
--> DRb magazine_slave_service: 1 provided...
--> DRb magazine_slave_service: 2 provided...
--> DRb magazine_slave_service: 1 provided...
--> DRb magazine_slave_service: 2 provided...
17:03:59 - INFO - Spork server for RSpec, Cucumber successfully started
17:03:59 - INFO - Guard is now watching at 'D:/BitNami/rubystack-1.9.3-6/projects/sample_app'
]2;[Spork] RSpec, Cucumber successfully started
ain)>
ain)>
我的 spec_helper.rb
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
#20130530 RGR Installing Spork. The following code existed and was moved to Spork.prefork
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
end
Spork.each_run do
# This code will be run each time you run your specs.
end
end