0

I have two styles of spec in a single folder, one of which uses a full-fat rails environment, with rspec, the other is a light-weight helper which requires gems individually.

Recently I've had some problems running these together in Rubymine.

Right-clicking on a single file of either style runs fine. Right clicking the folder and selecting "Run > All specs in folder" has been returning this error for each spec:

NameError: undefined local variable or method `mocha_setup' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000000ca26d70>
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-expectations-2.14.5/lib/rspec/matchers/method_missing.rb:9:in `method_missing'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/mocking/with_mocha.rb:40:in `setup_mocks_for_rspec'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:299:in `run_before_each'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:113:in `block in run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:111:in `run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:390:in `block in run_examples'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:386:in `map'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:386:in `run_examples'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:371:in `run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:28:in `map'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:28:in `block in run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/reporter.rb:58:in `report'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:25:in `run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'

This had run together perfectly well until very recently.

I can run all of the specs from the command line without any issues:

rspec --pattern spec/models/auto_ordering/*_spec.rb

This seems to be something specific about running this folder within Rubymine. I've tried invalidating my caches and restarting the IDE. I've tried deleting the configuration for running that folder.

Does anyone know what might be causing this?

Update: I've since discovered that this seems to happen sporadically when calling it through the command line, also.

Vega
  • 27,856
  • 27
  • 95
  • 103
AJFaraday
  • 2,411
  • 1
  • 16
  • 39
  • What RubyMine version do you use? Have you launched the same command from Terminal using the same SDK as in project? – Olivia Jul 01 '15 at 08:06
  • I'm using Rubymine 7.1.2. Yes, I have the same SDK in command line as in Rubymine. – AJFaraday Jul 01 '15 at 08:53

1 Answers1

0

I eventually solved this issue:

  • It was nothing to do with Rubymine, it was a load-order issue.
  • Rubymine was running files in strict alphabetical order, the CLI was running them in an arbitrary order
  • When the full rails environment was loading first, it was working fine.
  • When my lean environment was loading first, it was missing this piece of config:
RSpec.configure do |config|
  config.mock_framework = :mocha
end

I added this to my light-weight spec helper and I can now run these files in any order.

AJFaraday
  • 2,411
  • 1
  • 16
  • 39