Skip to content

Commit

Permalink
Do not automatically try to integrate with test libraries.
Browse files Browse the repository at this point in the history
Since the automatic test library integration functionality requires the test
library to be loaded and this doesn't usually happen until *after* the bundle
is loaded, it makes things simpler if we use `require 'mocha/setup'` to
explicitly setup Mocha when we know the test library has been loaded.

I deprecated the use of `require 'mocha'` in v0.13.0 and I plan to release
this change as part of a major version bump (i.e. v1.0.0), so it ought to
be safe to remove the deprecation in `lib/mocha.rb`.
  • Loading branch information
floehopper committed Dec 31, 2013
1 parent f33f506 commit 049080c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ Install the latest version of the gem with the following command...

$ gem install mocha

Note: If you are intending to use Mocha with Test::Unit or MiniTest, you should only load Mocha *after* loading the relevant test library...
Note: If you are intending to use Mocha with Test::Unit or MiniTest, you should only setup Mocha *after* loading the relevant test library...

require "test/unit"
require "mocha/setup"

#### Bundler

If you're using Bundler, ensure the correct load order by not auto-requiring Mocha in the `Gemfile` and then load it later once you know the test library has been loaded...
If you're using Bundler, include Mocha in the `Gemfile` and then setup Mocha later once you know the test library has been loaded...

# Gemfile
gem "mocha", :require => false
gem "mocha"

# Elsewhere after Bundler has loaded gems
require "test/unit"
require "mocha/setup"

#### Rails

If you're loading Mocha using Bundler within a Rails application, you should ensure Mocha is not auto-required (as above) and load Mocha manually e.g. at the bottom of your `test_helper.rb`.
If you're loading Mocha using Bundler within a Rails application, you should setup Mocha manually e.g. at the bottom of your `test_helper.rb`.

# Gemfile in Rails app
gem "mocha", :require => false
gem "mocha"

# At bottom of test_helper.rb
require "mocha/setup"
Expand All @@ -47,7 +47,10 @@ Install the Rails plugin...

$ rails plugin install git:/freerange/mocha.git

Note: As of version 0.9.8, the Mocha plugin is not automatically loaded at plugin load time. Instead it must be manually loaded e.g. at the bottom of your `test_helper.rb`.
Note: As of version 0.9.8, the Mocha plugin is not automatically setup at plugin load time. Instead it must be manually setup e.g. at the bottom of your `test_helper.rb`.

# At bottom of test_helper.rb
require "mocha/setup"

#### Know Issues

Expand Down
6 changes: 0 additions & 6 deletions lib/mocha.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
require 'mocha/version'
require 'mocha/deprecation'

Mocha::Deprecation.warning("Change `require 'mocha'` to `require 'mocha/setup'`.")

require 'mocha/setup'

4 changes: 2 additions & 2 deletions lib/mocha/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Mocha
module Integration
def self.activate
if [Integration::TestUnit, Integration::MiniTest].map(&:activate).none?
Deprecation.warning("Test::Unit or MiniTest must be loaded *before* Mocha.")
Deprecation.warning("If you're integrating with a test library other than Test::Unit or MiniTest, you should use `require 'mocha/api'` instead of `require 'mocha'`.")
Deprecation.warning("Test::Unit or MiniTest must be loaded *before* `require 'mocha/setup'`.")
Deprecation.warning("If you're integrating with a test library other than Test::Unit or MiniTest, you should use `require 'mocha/api'` instead of `require 'mocha/setup'`.")
end
end
end
Expand Down

0 comments on commit 049080c

Please sign in to comment.