I'm messing around with Mocha for days and cannot seem to get it working properly.
I'm using Rails 3.1.0.rc4 and Mocha 0.9.12, running under Ruby 1.9.2-p180. In my Gemfile I have a
gem 'mocha', :require => false
and I require Mocha in the last line of my test_helper.rb
require 'mocha'
as suggested in various questions and blog posts.
However, when creating a new Rails project and writing simple tests like the following:
test "test 1" do
User.any_instance.expects(:something).returns(true)
u = User.new
assert u.something
end
test "test 2" do
User.any_instance.expects(:something).returns(true)
u = User.new
end
test "test 3" do
u = mock()
u.expects(:something).at_least_once
end
All test pass without any errors. So, mocking works (because :something is not a real function) but in the second and third test I would expect Mocha to complain about :something not being called.
Running tests with "MOCHA_OPTIONS=debug" says
Detected MiniTest version: 1.6.0
Monkey patching MiniTest >= v1.4.2 and <= v1.7.2
Can anyone tell me what I'm missing here?