Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move minitest plugin
Minitest Rails plugin should be loaded on test_help, so we report errors
even when not running from the runner.

Also fix the backtrace
  • Loading branch information
arthurnn authored and senny committed Mar 18, 2015
1 parent 739cfd5 commit a71bcdb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
7 changes: 1 addition & 6 deletions railties/lib/rails/test_help.rb
Expand Up @@ -2,19 +2,14 @@
# so fixtures aren't loaded into that environment
abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?

require "rails/test_unit/minitest_plugin"
require 'active_support/testing/autorun'
require 'active_support/test_case'
require 'action_controller'
require 'action_controller/test_case'
require 'action_dispatch/testing/integration'
require 'rails/generators/test_case'

# Config Rails backtrace in tests.
require 'rails/backtrace_cleaner'
if ENV["BACKTRACE"].nil?
Minitest.backtrace_filter = Rails.backtrace_cleaner
end

if defined?(ActiveRecord::Base)
ActiveRecord::Migration.maintain_test_schema!

Expand Down
15 changes: 15 additions & 0 deletions railties/lib/rails/test_unit/minitest_plugin.rb
@@ -0,0 +1,15 @@
require "minitest"
require "rails/test_unit/reporter"

def Minitest.plugin_rails_init(options)
self.reporter << Rails::TestUnitReporter.new(options[:io], options)
if $rails_test_runner && (method = $rails_test_runner.find_method)
options[:filter] = method
end

if ENV["BACKTRACE"].nil? && !($rails_test_runner && $rails_test_runner.show_backtrace?)
Minitest.backtrace_filter = Rails.backtrace_cleaner
end
end
Minitest.extensions << 'rails'

19 changes: 4 additions & 15 deletions railties/lib/rails/test_unit/runner.rb
Expand Up @@ -2,7 +2,6 @@
require "optparse"
require "rake/file_list"
require "method_source"
require "rails/test_unit/reporter"

module Rails
class TestRunner
Expand Down Expand Up @@ -58,17 +57,7 @@ def initialize(options = {})
end

def run
enable_backtrace if @options[:backtrace]

$rails_test_runner = self
def Minitest.plugin_rails_init(options)
self.reporter << Rails::TestUnitReporter.new(options[:io], options)
if method = $rails_test_runner.find_method
options[:filter] = method
end
end
Minitest.extensions << 'rails'

run_tests
end

Expand All @@ -82,6 +71,10 @@ def find_method
method[1] if method
end

def show_backtrace?
@options[:backtrace]
end

private
def run_tests
test_files.to_a.each do |file|
Expand All @@ -102,10 +95,6 @@ def test_files
Rake::FileList[pattern]
end

def enable_backtrace
ENV["BACKTRACE"] = "1"
end

def test_methods
methods_map = []
suites = Minitest::Runnable.runnables.shuffle
Expand Down

0 comments on commit a71bcdb

Please sign in to comment.