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

13 comments
Comment actions Permalink

Hello Larry,

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>

P.S. cucumber 1.0.2, rspec 2.6.0, spork 0.9.0.rc9

Which Rails gem do you use?

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?

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.

0
Comment actions Permalink

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

0
Comment actions Permalink

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).

0
Comment actions Permalink

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

0
Comment actions Permalink

(Which they are not because they all pass if I don't use spork.)

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:


# gems/cucumber-1.0.2/lib/cucumber/runtime.rb

def load_step_definitions   files = @configuration.support_to_load + @configuration.step_defs_to_load
  @support_code.load_files!(files) end



# gems/cucumber-1.0.2/lib/cucumber/cli/configuration.rb

def step_defs_to_load
  all_files_to_load.reject {|f| f =~ %r{/support/} } end def support_to_load   support_files = all_files_to_load.select {|f| f =~ %r{/support/} }   env_files = support_files.select {|f| f =~ %r{/support/env\..*} }   other_files = support_files - env_files   @options[:dry_run] ? other_files : env_files + other_files end

def all_files_to_load   requires = @options[:require].empty? ? require_dirs : @options[:require]   files = requires.map do |path|     path = path.gsub(/\\/, '/') # In case we're on windows. Globs don't work with backslashes.     path = path.gsub(/\/$/, '') # Strip trailing slash.     File.directory?(path) ? Dir["#{path}/**/*"] : path   end.flatten.uniq   remove_excluded_files_from(files)   files.reject! {|f| !File.file?(f)}   files.reject! {|f| File.extname(f) == '.feature' }   files.reject! {|f| f =~ /^http/}   files.sort end   

def require_dirs   feature_dirs + Dir['vendor/{gems,plugins}/*/cucumber'] end

def feature_dirs   paths.map { |f| File.directory?(f) ? f : File.dirname(f) }.uniq end



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.

larryh wrote:

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.

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

./config/cucumber.yml

default: --drb <%= std_opts %> features


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:

# gems/cucumber-1.0.2/lib/cucumber/cli/options.rb

def expanded_args_without_drb   return @expanded_args_without_drb  if @expanded_args_without_drb     @expanded_args_without_drb = (     previous_flag_was_profile = false     @expanded_args.reject do |arg|       if previous_flag_was_profile          previous_flag_was_profile = false          next true        end        if [PROFILE_SHORT_FLAG, PROFILE_LONG_FLAG].include?(arg)          previous_flag_was_profile = true          next true        end        arg == DRB_FLAG || @overridden_paths.include?(arg)    # <<<---- !!!!!! bug !!!!!!      end    )    @expanded_args_without_drb.push("--no-profile") unless @expanded_args_without_drb.include?(NO_PROFILE_LONG_FLAG) || @expanded_args_without_drb.include?(NO_PROFILE_SHORT_FLAG)    @expanded_args_without_drb end


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

Running tests with args ["/Users/romeo/RubymineProjects/rspec_cuc_rails309/features/subfolder/manage_people.feature", "--expand", "--color", "-r", "--format", "Teamcity::Cucumber::Formatter", "--strict", "--tags", "~@wip", "--no-profile"]...

Done.



instead of

Running tests with args ["/Users/romeo/RubymineProjects/rspec_cuc_rails309/features/subfolder/manage_people.feature", "--expand", "--color", "-r", "features", "--format", "Teamcity::Cucumber::Formatter", "--strict", "--tags", "~@wip", "--no-profile"]...

Done.




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.
0
Comment actions Permalink

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

0
Comment actions Permalink

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

0
Comment actions Permalink

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!)

Thanks, but it is absolutely not difficult to investigate cucumber/spork using RubyMine resolve and debugger features


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)>

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:
Screen Shot 2011-08-09 at 19.02.18.png
and "default: --drb <%= std_opts %>" in cucumber.yml

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'

Larry, did you try to restart spork server?

0
Comment actions Permalink

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.

0
Comment actions Permalink

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

0
Comment actions Permalink

Thanks, Roman!

0
Comment actions Permalink

Update2: We returned "-r features" to project defaults again. See http://youtrack.jetbrains.net/issue/RUBY-6883

0

Please sign in to leave a comment.