Skip to content

Commit

Permalink
Remove hard dependency on test-unit
Browse files Browse the repository at this point in the history
Instead show a error message asking users to add the gem to their
Gemfile if test-unit could not be loaded.
  • Loading branch information
rafaelfranca committed Jan 7, 2015
1 parent 292f6c9 commit 8f92edb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ else
end

gem 'i18n', '~> 0.6.11'
gem 'test-unit', '~> 3.0'

# This needs to be with require false to avoid
# it being automatically loaded by sprockets
Expand Down
1 change: 0 additions & 1 deletion activesupport/activesupport.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ Gem::Specification.new do |s|

s.add_dependency('i18n', '~> 0.6', '>= 0.6.4')
s.add_dependency('multi_json', '~> 1.0')
s.add_dependency('test-unit', '~> 3.0')
end
6 changes: 5 additions & 1 deletion activesupport/lib/active_support/test_case.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require 'test/unit/testcase'
begin
require 'test/unit/testcase'
rescue LoadError => e
raise LoadError, "Please add test-unit gem to your Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})", e.backtrace
end
require 'active_support/testing/setup_and_teardown'
require 'active_support/testing/assertions'
require 'active_support/testing/deprecation'
Expand Down
7 changes: 6 additions & 1 deletion activesupport/lib/active_support/testing/isolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ def run_in_isolation(&blk)

# Only in subprocess for windows / jruby.
if ENV['ISOLATION_TEST']
require "test/unit/collector/objectspace"
begin
require "test/unit/collector/objectspace"
rescue LoadError => e
raise LoadError, "Please add test-unit gem to your Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})", e.backtrace
end

class Test::Unit::Collector::ObjectSpace
def include?(test)
super && test.method_name == ENV['ISOLATION_TEST']
Expand Down
6 changes: 5 additions & 1 deletion railties/lib/rails/test_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# so fixtures aren't loaded into that environment
abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?

require 'test/unit'
begin
require 'test/unit'
rescue LoadError => e
raise LoadError, "Please add test-unit gem to your Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})", e.backtrace
end
require 'active_support/test_case'
require 'action_controller/test_case'
require 'action_dispatch/testing/integration'
Expand Down

1 comment on commit 8f92edb

@rafaelfranca
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.