spork 0.9.2 and rspec 3.0.0 = uninitialized constant RSpec::Core::CommandLine (NameError)
Asked Answered
P

5

22

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?

Puente answered 4/6, 2014 at 6:53 Comment(11)
There is no need in spork since springEstuary
Thanks. Have looked at spring but it is not for windows OS.Puente
Did you manage to solve this? I'm on linux and I have the exact same problem.Davie
No I didnt. I still use rspec 2.6 with spork. There is an issue on rspec's github link 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.Puente
found the answer, see my answerPuente
I wish people would stop using spork....Heterophony
Are there any alternatives on windows? There are spring ans spin but they both are using "fork"Puente
@sevenseacat: Does spring work for non-Rails apps? The README seems very Rails-specific...Urion
@Urion I don't know. I don't use it.Heterophony
@Urion 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.Puente
@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.Urion
P
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

Puente answered 6/6, 2014 at 15:10 Comment(1)
This worked for me. I just monkey patch'd Spork's code.Brnaby
M
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'

Merrileemerrili answered 5/3, 2015 at 18:11 Comment(2)
branch option should be added, so that it looks like this: gem 'spork', github: 'sporkrb/spork', branch: 'master'Coquillage
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!Merrileemerrili
L
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.

Lucianolucias answered 5/10, 2014 at 18:51 Comment(4)
Since you have removed '--drb' parameter from guardfile Guard does not run Rspec on SporkPuente
@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?Skip
Do not know actually. But according to guard-spork documentation the cli: '--drb' parameter is responsible for running tests on spork drb server.Puente
@Skip Spork is listening for incoming connections via DRb. You can read more about DRb here. 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.Inculpable
S
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

Scholar answered 12/11, 2014 at 1:9 Comment(0)
S
-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.

Sterner answered 14/7, 2014 at 0:56 Comment(1)
I think you have just turned it off (I mean spork).Puente

© 2022 - 2024 — McMap. All rights reserved.