This project is archived and is in readonly mode.

#2240 ✓invalid
David Chelimsky

let users decide what mock framework to use

Reported by David Chelimsky | March 15th, 2009 @ 06:52 PM | in 3.x

I see require 'mocha' in a bunch of the test case base classes. While mocha is an excellent choice (I use it too!), it adds methods to Object that conflict with other mocking frameworks.

What we did with rspec was to to make rspec's mock framework the default, but offer up a simple way to choose any other mock framework you wish to use for a project.

I think rails should offer something similar where mocha is the default, but a developer can say "i want to use RR, or flexmock, or ...."

If you're open to it, I'll be glad to submit a patch. I'm thinking of something like "config.mock_framework = :mocha" in config/test.rb - then you can just change that to whatever.

Of course, the really simple thing would be to just not have those requires in the test case classes to begin with. If you want to use mocha for rails' own test suite, those requires can go in test_helper.rb.

Comments and changes to this ticket

  • Pratik

    Pratik March 15th, 2009 @ 07:36 PM

    • Assigned user set to “Jeremy Kemper”

    The best is probably just to not require mocha in any test cases. But Jeremy will probably have more thoughts on this.

  • David Chelimsky

    David Chelimsky April 9th, 2009 @ 06:53 PM

    Jeremy - any thoughts on this?

  • Jeremy Kemper

    Jeremy Kemper April 9th, 2009 @ 07:12 PM

    That'd be great. There's an older patch to do this that had to be reverted, though.

  • David Chelimsky

    David Chelimsky April 9th, 2009 @ 07:16 PM

    Jeremy, that patch seems to be trying to do something more implicit. Are you saying something explicit that supports end-user configuration would be great? Or just something that allows rails own tests to function properly without implicitly requiring mocha for end-users?

  • Jeremy Kemper

    Jeremy Kemper April 9th, 2009 @ 07:36 PM

    Right. Our fixtures code breaks if Mocha is loaded after ActiveSupport::TestCase because Mocha overwrites #run. A comment in test/test_helper.rb to require 'mocha' (or whatever mocking lib) before require 'test_help' should be enough (no config option needed.)

  • David Chelimsky

    David Chelimsky April 10th, 2009 @ 09:30 AM

    Hey Jeremy, I just pulled edge and see 27 failures in actionpack, 3 in actionmailer, 1 in activerecord (running against mysql)

    Can you peek at and tell me if anything jumps out at you. I'm hoping there is simply something wrong in my environment that you'll recognize immediately from the particular sets of failures.

    I don't want to start working on this until I have 100% passing tests so I know I don't break anything :)

    Cheers, David

  • David Chelimsky

    David Chelimsky May 2nd, 2010 @ 09:02 PM

    I don't think this is an issue any more with Rails 3 because the app developer needs to specify the mocha gem in the Gemfile to use it, so it won't be automatically loaded just because it is present on the file system.

    If you agree, let's close this ticket.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Rohit Arondekar

    Rohit Arondekar June 15th, 2010 @ 10:57 AM

    What's the status on this ticket? Any more info?

  • José Valim

    José Valim June 22nd, 2010 @ 04:29 PM

    • State changed from “new” to “invalid”

    Let's close this. I will be glad to reopen it if needed.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by