After completing Michael Hartl's excellent Rails Tutorial, I decided to try to get Autotest and Spork going to speed up my tests. Everything seemed to install correctly, but when I came to the final hurdle (running rspec with the --drb flag) I'm getting the following error:
$ rspec --drb spec/
*****************************************************************
DEPRECATION WARNING: you are using a deprecated constant that will
be removed from a future version of RSpec.
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/run_strategy/forking.rb:13:in `run'
* Spec is deprecated.
* RSpec is the new top-level module in RSpec-2
*****************************************************************
Exception encountered: #<NameError: uninitialized constant RSpec::Runner::CommandLine>
backtrace:
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/test_framework/rspec.rb:6:in `run_tests'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/run_strategy/forking.rb:13:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/forker.rb:21:in `initialize'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/forker.rb:18:in `fork'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/forker.rb:18:in `initialize'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/run_strategy/forking.rb:9:in `new'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/run_strategy/forking.rb:9:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/server.rb:48:in `run'
/usr/lib/ruby/1.8/drb/drb.rb:1558:in `__send__'
/usr/lib/ruby/1.8/drb/drb.rb:1558:in `perform_without_block'
/usr/lib/ruby/1.8/drb/drb.rb:1518:in `perform'
/usr/lib/ruby/1.8/drb/drb.rb:1592:in `main_loop'
/usr/lib/ruby/1.8/drb/drb.rb:1588:in `loop'
/usr/lib/ruby/1.8/drb/drb.rb:1588:in `main_loop'
/usr/lib/ruby/1.8/drb/drb.rb:1584:in `start'
/usr/lib/ruby/1.8/drb/drb.rb:1584:in `main_loop'
/usr/lib/ruby/1.8/drb/drb.rb:1433:in `run'
/usr/lib/ruby/1.8/drb/drb.rb:1430:in `start'
/usr/lib/ruby/1.8/drb/drb.rb:1430:in `run'
/usr/lib/ruby/1.8/drb/drb.rb:1350:in `initialize'
/usr/lib/ruby/1.8/drb/drb.rb:1630:in `new'
/usr/lib/ruby/1.8/drb/drb.rb:1630:in `start_service'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/server.rb:29:in `listen'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/server.rb:20:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/bin/../lib/spork/runner.rb:75:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/bin/../lib/spork/runner.rb:10:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/bin/spork:10
/usr/lib/ruby/gems/1.8/bin/spork:23:in `load'
/usr/lib/ruby/gems/1.8/bin/spork:23
The tests work perfectly if I just enter $ rspec spec/ but are, of course, very slow. So it seems the problem might be with something I've done in relation to Spork. I followed the instructions at http://ruby.railstutorial.org/chapters/static-pages?version=3.0#sec:spork (using v3.0 instead of v3.2 as that's what I started with).
Please note that I'm running Cygwin on Windows, which means I'm on Ruby v1.8.7 instead of 1.9.2+. I don't know whether this would make a difference.
Any thoughts on how to get Spork going (Autotest seems to be fine) would be very much appreciated.
Thanks in advance!
Rob
PS My spec/spec_helper.rb looks like this:
require 'rubygems'
require 'spork'
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'
# 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
# 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
def test_sign_in(user)
controller.current_user = user
end
end
Edit 2: I changed the ends in the spec_helper.rb file. I don't think that I had one extra, as was suggested, but I think they were in the wrong place, due to poor indenting on my part. The resulting file (with all the comments removed) looks like this:
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
end
end
Spork.each_run do
end
def test_sign_in(user)
controller.current_user = user
end
The error message is the still the same. Tomorrow, if I get a chance, I'll try to uninstall Ruby v1.8.7 and install v1.9.2 or 3, for want of any other ideas. Thanks very much for all the help that's been offered so far!