21

Im using spork 0.9.2 and rspec 3.0.0. When trying to run test rspec --drb I have an exception

C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/spork-0.9.2/lib/spork/test_framework/rspec.rb:11:in run_tests: uninitialized constant RSpec::Core::CommandLine (NameError)

But when changing rspec version back to 2.6 - everything is OK. Has anyone faced the same issue? Is it possible to work around?

lx00st
  • 1,566
  • 9
  • 17
  • 4
    There is no need in `spork` since `spring` – zishe Jun 04 '14 at 06:55
  • 1
    Thanks. Have looked at `spring` but it is not for windows OS. – lx00st Jun 04 '14 at 21:07
  • Did you manage to solve this? I'm on linux and I have the exact same problem. – Spyros Mandekis Jun 06 '14 at 12:26
  • No I didnt. I still use rspec 2.6 with spork. There is an issue on rspec's github [link](https://github.com/rspec/rspec-core/issues/1235) concearning RSpec::Core::CommandLine and output_strem. Its not the exact problem but may be the right thing. I have not tried it yet so you may. – lx00st Jun 06 '14 at 14:16
  • found the answer, see my answer – lx00st Jun 06 '14 at 15:04
  • I wish people would stop using spork.... – sevenseacat Jul 14 '14 at 01:26
  • Are there any alternatives on windows? There are spring ans spin but they both are using "fork" – lx00st Jul 14 '14 at 07:23
  • @sevenseacat: Does spring work for non-Rails apps? The README seems very Rails-specific... – womble Aug 31 '14 at 08:50
  • @womble I don't know. I don't use it. – sevenseacat Aug 31 '14 at 09:29
  • @womble It seems to me like you can but with some effort. Spring generates stubs for rails ruby scripts. They all look the same like 1.load spring 2.run a script. You can put your own script and see what will happen. – lx00st Sep 01 '14 at 08:13
  • 2
    @zishe: Only if the entire world used Rails. Which they don't. lx00st, spring looks for Rails-specific initialization files, and if they don't exist, it exceptions out. – womble Sep 05 '14 at 00:27

5 Answers5

33

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

lx00st
  • 1,566
  • 9
  • 17
13

Like @lx00st said:

The reason is that RSpec::Core::CommandLine was removed in Rspec3

The spork gem hasn't been updated in rubygems.org. However, the fix has been merged into spork's master branch on github. You can grab it by telling bundler that you'd like to get spork from github (master) instead of rubygems.org. So do this:

This has been fixed on spork's master branch. Simple solution:

gem 'spork', github: 'sporkrb/spork', branch: 'master'

If you're using spork-rails, just require spork via github before requiring spork-rails in your gemfile. For more info on this, see my comment here:

https://github.com/sporkrb/spork-rails/issues/26

Edit: added branch: 'master'

Ben
  • 695
  • 6
  • 12
  • branch option should be added, so that it looks like this: `gem 'spork', github: 'sporkrb/spork', branch: 'master'` – elquimista Aug 27 '16 at 02:16
  • Bundler will use the master branch by default if not specified, but you're right, better to be explicit. I've edited my post per your suggestion, thanks! – Ben Aug 29 '16 at 14:50
1

Same thing here. Just remove the "--drb" line from .spec file and remove the cli: '--drb' parameter on the guard :rspec... line within the Guardfile. This does not turn off spork. It just turn off the "distributed ruby" (--drb) Rspec option. As guard knows you are running Rspec through Spork, it is not needed.

7stud
  • 46,922
  • 14
  • 101
  • 127
RedSoul
  • 41
  • 4
  • Since you have removed '--drb' parameter from guardfile Guard does not run Rspec on Spork – lx00st Oct 08 '14 at 13:30
  • @lx00st, How do you know that? When I followed efiguerc's advice: 1) It solved some errors. 2) When I timed the tests before starting guard and then after starting guard, the tests executed faster after starting guard. How is that possible if guard did not use spork? – 7stud Oct 08 '14 at 17:06
  • Do not know actually. But according to guard-spork documentation the cli: '--drb' parameter is responsible for running tests on spork drb server. – lx00st Oct 10 '14 at 06:32
  • @7stud Spork is listening for incoming connections via DRb. You can read more about DRb here. http://www.ruby-doc.org/stdlib-1.9.3/libdoc/drb/rdoc/DRb.html But essentially if you don't tell rspec to use DRb, spork won't be listening for it and it won't use spork. – JoshEmory Jan 20 '15 at 21:02
1

I started using Spring instead of Spork and that solved it.

It seems to be the new Rails way: http://edgeguides.rubyonrails.org/4_1_release_notes.html#spring-application-preloader

Amin Ariana
  • 4,635
  • 2
  • 35
  • 21
-2

I had this same problem. Sans digging into the rspec3 source code, removing the --drb line from my .rspec file fixed the problem for me. Some Guardfile examples also have use of the --drb which causes issues for me. Once removed all tests work fine.

soppliger
  • 31
  • 1
  • 9