Friday, March 23, 2007

Should Rails include Mocha?

I like the way the Rails integration tests currently depend on Mocha.
# integration_test.rb
...
begin # rescue LoadError
require 'mocha'
...
rescue LoadError
$stderr.puts "Skipping integration tests. `gem install mocha` and try again."
end
In fact, I stole the idea and changed it up a bit for sqldsl.
unless File.directory? File.dirname(__FILE__) + '/../vendor/mocha-0.4.0/'
raise "mocha 4.0 is required to run the test suite. create the 'vendor' directory as
a sibling of test and 'gem unpack mocha' in 'vendor'"
end
$:.unshift File.dirname(__FILE__) + '/../vendor/mocha-0.4.0/lib/'
require File.dirname(__FILE__) + '/../vendor/mocha-0.4.0/lib/mocha'
However, now I'm wondering if Rails should depend on, and include Mocha.

I've previously written that I think xUnit frameworks should include Mocks. Since Rails bakes in testing, I believe it should provide you with the full array of testing tools, including Mocks.

Thoughts?

5 comments:

  1. Anonymous11:59 AM

    Sounds good to me.

    Jay: Are you recommending Rails include Mocha as a gem dependency or that it actually include Mocha in the Rails source tree? I'd strongly recommend the former.

    ReplyDelete
  2. Anonymous2:43 PM

    I'm suggesting what you would prefer: Making Mocha a gem dependency of Rails.

    ReplyDelete
  3. In the last three Rails apps I wrote I included Mocha. Seems like a good idea to have it included with Rails, therefore.

    ReplyDelete
  4. At least some versions of activesupport 1.3.1 included flexmock. I don't see it in later versions.

    ReplyDelete

Note: Only a member of this blog may post a comment.