1

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!

jimbobsweeney
  • 107
  • 1
  • 9

3 Answers3

2

You're using an older version of Spork. You should try upgrading to v0.9.2 to see if that helps.

Brandan
  • 14,735
  • 3
  • 56
  • 71
1

I know i kept forgetting bundle exec rspec . --drb after running spork in another tab. This got rid of any weird warnings for me. Maybe this is for google.

pjammer
  • 9,489
  • 5
  • 46
  • 56
0

See lx00st's answer to spork 0.9.2 and rspec 3.0.0 = uninitialized constant RSpec::Core::CommandLine (NameError), quoting:

The reason is that RSpec::Core::CommandLine was removed in Rspec3 https://github.com/rspec/rspec-core/blob/master/Changelog.md

Merge RSpec::Core::CommandLine (never formally declared public) into RSpec::Core::Runner. (Myron Marston)

But spork depends on this code.

There is already an issue on spork's github and a solution can be found in a following spork's fork:

https://github.com/codecarson/spork/commit/38c79dcedb246daacbadb9f18d09f50cc837de51#diff-937afaa19ccfee172d722a05112a7c6fL6

In general - replace

::RSpec::Core::CommandLine.new(argv).run(stderr, stdout)

with

::RSpec::Core::Runner.run(argv,stderr, stdout)

in the soprks source code

It worked fine for me (thouhg I suspect a spork gem update might erase the source code fix). I just replaced the content 'spork/test_framework/rspec.rb' with the proposed content from github:

require 'rspec/core/version'

class Spork::TestFramework::RSpec < Spork::TestFramework
  DEFAULT_PORT = 8989
  HELPER_FILE = File.join(Dir.pwd, "spec/spec_helper.rb")

  def run_tests(argv, stderr, stdout)
    if rspec1?
      ::Spec::Runner::CommandLine.run(
        ::Spec::Runner::OptionParser.parse(argv, stderr, stdout)
      )
    elsif rspec3?
      options = ::RSpec::Core::ConfigurationOptions.new(argv)
      ::RSpec::Core::Runner.new(options).run(stderr, stdout)
    else
      ::RSpec::Core::CommandLine.new(argv).run(stderr, stdout)
    end
  end

  def rspec3?
    return false if !defined?(::RSpec::Core::Version::STRING)
    ::RSpec::Core::Version::STRING =~ /^3\./
  end

  def rspec1?
    defined?(Spec) && !defined?(RSpec)
  end
end
Community
  • 1
  • 1
ratiaris
  • 327
  • 2
  • 10
  • Please avoid link only answers. Place the link in a comment on the question if you believe it is helpful. – Rory McCrossan Aug 10 '14 at 12:55
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Mo. Aug 10 '14 at 13:35
  • Thanks for the feedback @Athimannil, hope the answer is in better shape now. – ratiaris Aug 11 '14 at 22:53
  • @RoryMcCrossan, got your hint. Note that I couldn't comment the initial question (not enough rep). – ratiaris Aug 11 '14 at 22:55