Spork With RSpec and Cucumber
Hi,
I just downloaded 3.2.3. Before I had spork working with RSpec but not Cucumber. Now it doesn't work with RSpec, either. In both cases the spork server starts fine, but then I get the following error messages:
RSpec: Exception encountered: #<LoadError: no such file to load -- teamcity/spec/runner/formatter/teamcity/formatter>
Cucumber: Exception encountered: #<Errno::ENOENT: No such file or directory - Teamcity::Cucumber::Formatter>
I don't know what this TeamCity-Formatter stuff is adding to the package, but given the massive amounts of headaches it has caused and how it has flat out prevented many of us from using spork when running RSpec and/or Cucumber tests, is there any way you can just yank it out of there?
Thanks,
Larry
P.S. cucumber 1.0.2, rspec 2.6.0, spork 0.9.0.rc9
请先登录再写评论。
Hello Larry,
Which Rails gem do you use?
It is our custom results fromatter which listens test framework events and builds test UI and statistics in RubyMine test runner console. Mostly all cucumber-spork related issues are due to bugs in cucumber gem and buggy support of custom formatters. They improve it several months ago, but old cucumber.yml in legacy projects are still incorrect and lead similar errors. Please tell me you rails, rspec-rails, cucumber-rails gems versions and I'll try to reproduce the issue.
Probably http://youtrack.jetbrains.net/issue/RUBY-8862 issue will help
Hi Roman,
Regarding your other post which pointed to someone else's solution: I deleted my old Run configs for the Cuke and RSpec Spork servers. When I re-generated them RSpec/Spork started working again, but Cuke/Spork did not; instead, I got this error message: Exception encountered: #<Errno::ENOENT: No such file or directory - Teamcity::Cucumber::Formatter>
I'm using the following gems:
rails 3.0.9
cucumber and cucumber-rails 1.0.2
rspec 2.6.0 (but this is no longer a problem)
I always run cucumber:install when I upgrade cuke and I notice that it hasn't updated my cucumber.yml file in awhile. Here are the contents of that file:
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: --drb <%= std_opts %> features
wip: --drb --tags @wip:3 --wip features
rerun: --drb <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
Huh, now this is interesting...
I had this for my "Runner Options" for running cuke tests: "--color -r features"
I think you mentioned removing this in a previous post, so when I removed this option I was able to run the tests... except for the fact that it reported all of my steps as being undefined. (Which they are not because they all pass if I don't use spork.)
This is very encouraging as it is the farthest I have ever gotten and it seems like maybe I am missing one simple setting. Do you know what that could be?
BTW, the "None of your steps are defined" error happens when I run all features in either a folder or a file.
Thanks,
Larry
Larry,
Thank you for the investigation, I've managed to reproduce the same behaviour. As far as I understand it affects feature files located in subolders of "features" folder. All features in "features" and run single feature directly from "feature" folder should work (working directory - rails appliction root, runner params without -r features).
Hi Roman,
Thanks for the reply. I tried what you said and am sitll having problems. Under my /features directory I have sub-dirs called 'scenarios', 'step_definitions' and 'support'. I can't get any of my tests running the way things are set up. I tried moving one of my feature files into the /features directory and got a lot closer. So when you say it works with tests in the /features folder, do you mean that they literally have to be in that folder and nowhere else, i.e. in sub-folders?
If so, then spork is useless to me (and I imagine many others) as there's no way I can just stick all of my features into one directory; heck, that goes against organizational strategies on any computer for any types of files.
You said "as I understand it". What exactly does that mean - is this a spork or cucumber or Rubymine limitation? Also, is it a temporary thing or will it be fixed in the future? Nothing I have ever read about spork said that in order for it to work, all features had to be in the top-leve /feature folder.
This is what happened when I moved one of my feature files up into the /featurs directory: One of my tests failed due to some strange error about it not finding a method for one of my models - something that definitely exists. Here is the entire message:
NoMethodError: undefined method `pols_for_state' for #<Class:0x000000053ad748>
./app/controllers/pol/persons_controller.rb:31:in `index'
<internal:prelude>:10:in `synchronize'
./features/step_definitions/web_steps.rb:49:in `/^(?:|I )go to (.+)$/'
./features/xxx.feature:33:in `When I go to the <name> page'
Who knows what the "internal:prelude in synchronize" error is all about...
And finally, I couldn't get any single test to run no matter how hard I tried.
If you know what's wrong off the top of your head and can share that info - fine. If not, don't worry about it as I have spent way too much time on this issue - and I know you have too. (I imagine we are both sick of it. ;))
However, I would like to know about the "as I understand it" comment regarding running all features in the /features folder. Bascially,
1) Is this a known problem?
2) With what? (e.g. spork, cucumber, Rubymine, Ruby, Rails, ...)
3) Will we ever be able to run features in sub-directories using spork?
Thanks, and sorry about all of the time you have had to spend on this issue.
-- Larry
Are you sure that the same configration passes without spork and '-r features' option?
"-r features" option tells cucumber where to find "step_definitions" and "support" folders. In simple cases cucumber may autodetect location of these folders. E.g when you asked cucumber to launch all tests in "[your app]/features" folder of asked to run a feature file which is a direct child of "[your app]/features" folder. See cucumber gem implementation:
So if you need to launch [your app]/features/subfolder/some.feature cucumber will not find step definitions out of the box. Or you have to place them in [your app]/features/subfolder/step_definitions.
I was wrong. I think "-r features" is required until you work with simple scenarios when cucumber able to find step definitions.
-----
Ok, when you use "-r features" there is another problem related to cucumber bug. Cucumber merges commanld line options and profiles. Default profile
launches all tests from "features" folder. When you launch something else using rubymine our run configuration passes feature/subfolder name via command line options. Such options have higher priority so cucumber ignores other paths from profiles and store difference in @overridden_paths variable. As far as I understand before passing options to spork server cucumber merges them simply, then remove --drb flage and @overridden_paths. See:
if you pass "-r features" cmdline option and default profile contains "features" path, then for all other paths the above code removes 'features' from '-r features' i.e. it corrupts cmdline options. E.g. sends to cucumber
instead of
As a workaround you can remove "features" from default profile (it is Rafael advice -see http://devnet.jetbrains.net/message/5300467#5300467) or replace "features" with it's full path in "--color -r features" options (you can save it in cucumber run configuration project default settings: RubyMine | Run | Edit Configurations | Defaults).
P.S: I'll try to sumbit a issue and path in cucumber project.
Larry,
See my next post with detailed reply. It took some time to debug cucumber and figure out what is going wrong.
"As far as I understand" - means my opinion and my understanding of cucumber gem sources and how it works
Hi Roman,
I tried removing the 'features' argument from the cucumber.yml file and it helped in that spork/cuke can now find my features and step-defs.
However, I ran a bunch of my tests (which all pass without using spork) and in a bunch of cases I still got that unfound-method-in-model error that I mentioned in my previous post:
NoMethodError: undefined method `pols_for_state' for #<Class:0x000000053ad748>
./app/controllers/pol/persons_controller.rb:31:in `index'
<internal:prelude>:10:in `synchronize'
./features/step_definitions/web_steps.rb:49:in `/^(?:|I )go to (.+)$/'
./features/xxx.feature:33:in `When I go to the <name> page'
But the method is defined and passes without spork, so I have no idea what's going on.
And in another instance I got this error message:
#<RuntimeError: All but one formatter must use --out, only one can print to each stream (or STDOUT)>
These problems occurred duing my first two runs, at which point i just said "forget it".
I really do appreciate all of your help on this issue and I truly believe that it is a problem with the cucumber code. (It amazes me how much you know about cucumber/spork when they're not even your projects!)
But I've just had it. I just want to get back to my code and get some work done. (As I'm sure you do, too! :))
Thanks,
Larry
Thanks, but it is absolutely not difficult to investigate cucumber/spork using RubyMine resolve and debugger features
Most likely it is same issue as https://rspec.lighthouseapp.com/projects/16211/tickets/597-cucumber-fails-when-tests-are-launched-from-rubymine-using-spork. I get such error if "Use DRb server (...)" checkbox isn't checked in run configuration but --drb option is inherited from default profile. E.g:

and "default: --drb <%= std_opts %>" in cucumber.yml
Larry, did you try to restart spork server?
Hi Roman,
Good call on the unchecked 'Use DRb server' in the Run Config causing the problem; when I checked that option the error disappeared.
But I am still getting undefined method errors on my model, which totally baffles me. One is a class method I defined myself and the other is an actual database attribute (the attribute is called 'district' and it's giving me this: NoMethodError: undefined method `district=' for #<Pol::Person:0x000000026d0ab8>
But both of these are resolved when I run without spork and when I run the app in general. I have no idea what's going on and don't expect you to look into this (as it's my code ;)). You have gone way above and beyond the call of duty and for that I am grateful - thanks a lot!
If I figure out what's going on I will describe it in this post. But that might be awhile, i.e. until I get into a better frame of mine about using spork. ;)
Thanks again, Roman.
-- Larry
P.S. I did try restarting the spork server (a bunch of times) and that didn't help.
I sent pull request to cucumber project with suggested fix for "-r features" related bug, see/vote issue https://github.com/cucumber/cucumber/issues/117
Thanks, Roman!
Update2: We returned "-r features" to project defaults again. See http://youtrack.jetbrains.net/issue/RUBY-6883