ruby-on-railsrubyrspecrubymineruby-mocha

RSpec, Mocha and Rubymine - Undefined method `mocha_setup'


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.


Solution

  • I eventually solved this issue:

    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.