kashmir
kashmir copied to clipboard
Running the test suite with mocha 1.5 fails
Reproduction steps
git clone https://github.com/mbigras/kashmir
cd kashmir/
git co ce9164251f7f27911f64a528e2cdb19c81533bc7
curl https://gist.githubusercontent.com/mbigras/b215f08c7d78226d37fc1c7d8732316d/raw/9fc48d9b3381532c2975a8b73246abfc0af2f6d5/gistfile1.txt > Gemfile.lock
bundle install
bundle exec rake
...
Finished in 0.438303s, 95.8241 runs/s, 136.8916 assertions/s.
1) Error:
Caching::misc#test_0001_does not cache already cached results:
Mocha::NotInitializedError: Mocha methods cannot be used outside the context of a test
/Users/mbigras/Box Sync/Projects/github.com/mbigras/kashmir/test/caching_test.rb:176:in `block (3 levels) in <top (required)>'
Seems like the root cause is we're not initializing mocha correctly. More details at:
https://github.com/lynndylanhurley/devise_token_auth/issues/1137#issuecomment-379409853
I think the problem is actually that you are not initializing Mocha correctly. For quite a long time now, Rails has been using Minitest not Test::Unit, and so you should be requiring "mocha/minitest"
Using mocha/minitest is also mentioned in the README:
https://github.com/freerange/mocha/tree/v1.5.0#minitest-1
MiniTest
# Gemfile in Rails app
gem 'mocha'
# At bottom of test_helper.rb (or at least after `require 'rails/test_help'`)
require 'mocha/minitest'