Mocha Mock Carries To Another Test

后端 未结 5 1042
无人共我
无人共我 2020-12-06 00:50

I have been following the 15 TDD steps to create a Rails application guide - but have run into an issue I cannot seem to resolve. For the functional test of the WordsContro

5条回答
  •  死守一世寂寞
    2020-12-06 01:26

    I had the same problem, mocked functionality was not isolated to a test, it seems to be a problem with the load order of Mocha.

    I had some issues getting Mocha to work with Rails3. I found a few stackoverflow posts regarding, but didn't stumble across the solution until I found a post on agoragames.com

    Basically, in the Gemfile of your project, the require for Mocha should look like:

    gem 'mocha', :require => false
    

    Then in test/test_helper.rb, add a require line for mocha:

    ...
    ...
    require File.expand_path('../../config/environment', __FILE__)
    require 'rails/test_help'
    require 'mocha'
    
    class ActiveSupport::TestCase
    ...
    ...
    

    I think the require line for mocha in the Gemfile means that you need to already have mocha installed as a gem, bundler won't take care of it for you.

提交回复
热议问题