RubyMine, Spork, RSpec, Cucumber

I can’t take credit for this one; that goes to Ben Lindsey. But since the answer I needed was buried in a comment, I thought I’d give it a little more googleability.

RubyMine needs to load special test formatters for its built-in RSpec and Cucumber runners to work. You can easily configure it to talk to a Spork server when running tests, but you’ll get a LoadError (“no such file to load — teamcity/spec/runner/formatter/teamcity/formatter”) with a vanilla Spork setup because the server won’t be able to find the RubyMine formatter libraries.

The solution is to add the requisite paths in the Spork prefork block. Here’s mine:

 

Spork.prefork do
  if ENV["RUBYMINE_HOME"]
    $:.unshift(File.expand_path("rb/testing/patch/common", ENV["RUBYMINE_HOME"]))
    $:.unshift(File.expand_path("rb/testing/patch/bdd", ENV["RUBYMINE_HOME"]))
  end

  # ...
end

I’ve put the above code in my spec_helper.rb as well as my Cucumber env.rb file. RUBYMINE_HOME is an environment variable I’ve set in my .zshenv file.

5 comments

  1. Hey, thanks for this note. I’d seen it where you saw it originally, however this is a little more clear seeing it extracted.

    Curious on something. I’m quite new and I’d like to run guard-spork + guard-rspec. Right now I’m getting some strangeness when changing my routes.rb on a small sample project from railstutorial.org. It appears that when you change routes.rb in my current setup such that it should fail with 2 matches and 1 failure, it will say that there are no matches and thus no failures. Any ideas?

  2. Still valid on RubyMine 5.4 for Guard users. Thanks for keeping the information available.

  3. I couldn’t run or debug specs in RubyMine having guard running. It gives me the exactly same load error. Though it works when guard is turned off. I tryed to use your solution and specs began to run when guard is turned on. But then debugging a spec with Guard turned on ignores breakpoints in a spec. It runs fine but doesn’t stop at breakpoints. Is there any way to debug spec using breakpoints in RubyMine not turning Guard off?

Leave a Reply

Your email address will not be published. Required fields are marked *