Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

let users decide what mock framework to use

#2240

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.

Reported by David Chelimsky · March 15th, 2009 @ 06:52 PM

State: invalid
Milestone: 3.x
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. Pratik
    Pratik
    • 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.

    March 15th, 2009 @ 07:36 PM

  2. David Chelimsky
    David Chelimsky

    Jeremy - any thoughts on this?

    April 9th, 2009 @ 06:53 PM

  3. Jeremy Kemper
    Jeremy Kemper

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

    https://rails.lighthouseapp.com/...

    April 9th, 2009 @ 07:12 PM

  4. David Chelimsky
    David Chelimsky

    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?

    April 9th, 2009 @ 07:16 PM

  5. Jeremy Kemper
    Jeremy Kemper

    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.)

    April 9th, 2009 @ 07:36 PM

  6. David Chelimsky
    David Chelimsky

    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 http://gist.github.com/93003 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

    April 10th, 2009 @ 09:30 AM

  7. David Chelimsky
    David Chelimsky

    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.

    May 2nd, 2010 @ 09:02 PM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  9. Rohit Arondekar
    Rohit Arondekar

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

    June 15th, 2010 @ 10:57 AM

  10. José Valim
    José Valim
    • State changed from new to invalid

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

    June 22nd, 2010 @ 04:29 PM