1

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?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Michael Trojanek
  • 1,813
  • 17
  • 15
  • I think it still has the load issues: http://stackoverflow.com/questions/3118866/mocha-mock-carries-to-another-test/4375296#4375296 – oma Jun 27 '11 at 13:07

0 Answers0