54

OS: Arch Linux, Rails version: 4, RubyMine: 6.3

When I run a spec from Tools - Run Rake Task - spec I always get this error:

/home/chylli/.rvm/gems/ruby-2.1.2@rails4/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1024:in `require': cannot load such file -- teamcity/spec/runner/formatter/teamcity/formatter (LoadError)

but it is OK to run 'debug spec:models'.

What I tried: I added 'ruby arguments' under Run - edit configurations:

-I$RUBYMINE_HOME/rb/testing/patch/bdd -I$RUBYMINE_HOME/rb/testing/patch/common

but it doesn't work.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
chylli
  • 561
  • 1
  • 4
  • 7

3 Answers3

119

Run

spring stop

on the command line before running rake from RubyMine, or running specs directly, or doing anything else that uses spring.

You don't need to do this every time you run rake or specs or whatever in RubyMine, only if you previously started spring by running rake or doing something else that starts spring outside of RubyMine. You also don't need to spring stop when you switch from RubyMine back to the command line.

This happens because if spring is not running when you run rake or whatever outside RubyMine, spring will start and will preload your code but not RubyMine-specific code. Evidently spring doesn't know how to load missing code after it's been started.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
  • 5
    This answer should be accepted, it is exactly what was going on in my environment (OSX not Linux like for OP). – Alan LaMielle Sep 18 '14 at 17:41
  • Worked for me with OS X Mavericks. – Richard Brown Oct 04 '14 at 22:28
  • This also worked form me, RubyMine 7.0 + Ubuntu 14.10 – Neoecos Nov 19 '14 at 19:05
  • Sweet! Thanks for the great fix to an otherwise obtuse error. – Jon Kern Dec 31 '14 at 20:59
  • 2
    If RubyMine was already up and running before adding spring to your project, it still won't work - but after shutting RubyMine down completely and restarting, it does. (RM7.0.2 on Linux) – Matt Hucke Jan 07 '15 at 20:00
  • This also worked for me on RubyMine 7.1 + OS X Yosemite 10.10.3. Thanks! – Peter Bloom Apr 22 '15 at 19:34
  • For me it doesn't help - tried `spring stop`, tried killing `spring`, tried restarting IntelliJ, tried rebooting. It just starts the test like this: `/bin/bash -c "/Users/maris/.rvm/bin/rvm ruby-2.4.5 do bundle exec .rvm/rubies/ruby-2.4.5/bin/ruby .rvm/rubies/ruby-2.4.4/gems/ruby/2.4.0/bin/rspec /.../spec/test_spec.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter --example \"...\""` and then returns: `An error occurred while loading teamcity/spec/runner/formatter/teamcity/formatter.` – Maris Apr 04 '19 at 13:30
5

I took the time to fix this without the need to restart spring.

There's a Pull Request for the quick hack I made in my fork of the spring-commands-rspec gem.

But it doesn't look like that repo is active, so you can use my fix by switching your spring-commands-rspec entry to this to your Gemfile:

gem 'spring-commands-rspec', git: 'https://github.com/thewoolleyman/spring-commands-rspec.git'

HTH, :) -- Chad

thewoolleyman
  • 592
  • 6
  • 13
  • This was exactly what I was looking for and solves the problem on my end without the need to restart Spring. I'm confused as to why you've been downvoted. – MacKinley Smith May 02 '16 at 18:21
4

Had the same issue just today, and I had to take different actions:

spring stop would tell me that Spring is not running

So I had to

1. kill them manually

ps aux | grep spring

Would give me

thomasromera     27841   [...] | spring app    | started 23 hours ago | development mode
thomasromera     38931   [...] | spring app    | started 18 hours ago | development mode
thomasromera     54661   [...] | spring app    | started 4 mins ago | development mode
thomasromera     27840   [...] | spring server | started 23 hours ago

then kill all servers + apps

kill 27840
kill 38931
...

2. Turn off the spring pre-loader in RubyMine:

In RubyMine: CMD+Shift+A type spring pre-loader, turn it off and rerun the specs.

Don't forget to turn it on again if you need it.

Erowlin
  • 9,555
  • 4
  • 35
  • 63