aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activejob/lib/active_job/test_helper.rb24
-rw-r--r--activejob/test/cases/test_helper_test.rb21
-rw-r--r--guides/source/asset_pipeline.md2
-rw-r--r--railties/lib/rails/test_unit/minitest_plugin.rb14
-rw-r--r--railties/lib/rails/test_unit/reporter.rb2
-rw-r--r--railties/test/application/test_runner_test.rb31
-rw-r--r--railties/test/test_unit/reporter_test.rb4
7 files changed, 60 insertions, 38 deletions
diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb
index de79de59f8..44ddfa5f69 100644
--- a/activejob/lib/active_job/test_helper.rb
+++ b/activejob/lib/active_job/test_helper.rb
@@ -231,19 +231,17 @@ module ActiveJob
# MyJob.set(wait_until: Date.tomorrow.noon).perform_later
# end
# end
- def assert_enqueued_with(args = {}, &_block)
- original_enqueued_jobs = enqueued_jobs.dup
- clear_enqueued_jobs
+ def assert_enqueued_with(args = {})
+ original_enqueued_jobs_count = enqueued_jobs.count
args.assert_valid_keys(:job, :args, :at, :queue)
serialized_args = serialize_args_for_assertion(args)
yield
- matching_job = enqueued_jobs.find do |job|
+ in_block_jobs = enqueued_jobs.drop(original_enqueued_jobs_count)
+ matching_job = in_block_jobs.find do |job|
serialized_args.all? { |key, value| value == job[key] }
end
assert matching_job, "No enqueued job found with #{args}"
instantiate_job(matching_job)
- ensure
- queue_adapter.enqueued_jobs = original_enqueued_jobs + enqueued_jobs
end
# Asserts that the job passed in the block has been performed with the given arguments.
@@ -257,19 +255,17 @@ module ActiveJob
# MyJob.set(wait_until: Date.tomorrow.noon).perform_later
# end
# end
- def assert_performed_with(args = {}, &_block)
- original_performed_jobs = performed_jobs.dup
- clear_performed_jobs
+ def assert_performed_with(args = {})
+ original_performed_jobs_count = performed_jobs.count
args.assert_valid_keys(:job, :args, :at, :queue)
serialized_args = serialize_args_for_assertion(args)
perform_enqueued_jobs { yield }
- matching_job = performed_jobs.find do |job|
+ in_block_jobs = performed_jobs.drop(original_performed_jobs_count)
+ matching_job = in_block_jobs.find do |job|
serialized_args.all? { |key, value| value == job[key] }
end
assert matching_job, "No performed job found with #{args}"
instantiate_job(matching_job)
- ensure
- queue_adapter.performed_jobs = original_performed_jobs + performed_jobs
end
def perform_enqueued_jobs(only: nil)
@@ -308,9 +304,9 @@ module ActiveJob
def enqueued_jobs_size(only: nil) # :nodoc:
if only
- enqueued_jobs.select { |job| Array(only).include?(job.fetch(:job)) }.size
+ enqueued_jobs.count { |job| Array(only).include?(job.fetch(:job)) }
else
- enqueued_jobs.size
+ enqueued_jobs.count
end
end
diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb
index a66f5d762c..f7ee763e8a 100644
--- a/activejob/test/cases/test_helper_test.rb
+++ b/activejob/test/cases/test_helper_test.rb
@@ -242,6 +242,15 @@ class EnqueuedJobsTest < ActiveJob::TestCase
assert_equal "No enqueued job found with {:job=>HelloJob, :args=>[#{wilma.inspect}]}", error.message
end
+
+ def test_assert_enqueued_job_does_not_change_jobs_count
+ HelloJob.perform_later
+ assert_enqueued_with(job: HelloJob) do
+ HelloJob.perform_later
+ end
+
+ assert_equal 2, ActiveJob::Base.queue_adapter.enqueued_jobs.count
+ end
end
class PerformedJobsTest < ActiveJob::TestCase
@@ -487,4 +496,16 @@ class PerformedJobsTest < ActiveJob::TestCase
assert_equal "No performed job found with {:job=>HelloJob, :args=>[#{wilma.inspect}]}", error.message
end
+
+ def test_assert_performed_job_does_not_change_jobs_count
+ assert_performed_with(job: HelloJob) do
+ HelloJob.perform_later
+ end
+
+ assert_performed_with(job: HelloJob) do
+ HelloJob.perform_later
+ end
+
+ assert_equal 2, ActiveJob::Base.queue_adapter.performed_jobs.count
+ end
end
diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md
index cc090e27e2..7b8d2d3aef 100644
--- a/guides/source/asset_pipeline.md
+++ b/guides/source/asset_pipeline.md
@@ -169,7 +169,7 @@ directory. Files in this directory are served by the Sprockets middleware.
Assets can still be placed in the `public` hierarchy. Any assets under `public`
will be served as static files by the application or web server when
-`config.assets.serve_static_files` is set to true. You should use `app/assets` for
+`config.serve_static_files` is set to true. You should use `app/assets` for
files that must undergo some pre-processing before they are served.
In production, Rails precompiles these files to `public/assets` by default. The
diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb
index 3a0a58df88..d1ba35a5ec 100644
--- a/railties/lib/rails/test_unit/minitest_plugin.rb
+++ b/railties/lib/rails/test_unit/minitest_plugin.rb
@@ -3,6 +3,16 @@ require "rails/test_unit/reporter"
require "rails/test_unit/test_requirer"
module Minitest
+ mattr_accessor(:hide_aggregated_results) { false }
+
+ module AggregatedResultSuppresion
+ def aggregated_results
+ super unless Minitest.hide_aggregated_results
+ end
+ end
+
+ SummaryReporter.prepend AggregatedResultSuppresion
+
def self.plugin_rails_options(opts, options)
opts.separator ""
opts.separator "Usage: bin/rails test [options] [files or directories]"
@@ -38,6 +48,7 @@ module Minitest
options[:fail_fast] = true
end
+ options[:output_inline] = true
options[:patterns] = opts.order!
end
@@ -63,6 +74,9 @@ module Minitest
Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
end
+ # Disable the extra failure output after a run, unless output is deferred.
+ self.hide_aggregated_results = options[:output_inline]
+
self.reporter << ::Rails::TestUnitReporter.new(options[:io], options)
end
diff --git a/railties/lib/rails/test_unit/reporter.rb b/railties/lib/rails/test_unit/reporter.rb
index 8f1116b6af..e1fe92a11b 100644
--- a/railties/lib/rails/test_unit/reporter.rb
+++ b/railties/lib/rails/test_unit/reporter.rb
@@ -49,7 +49,7 @@ module Rails
private
def output_inline?
- options.fetch(:output_inline, true)
+ options[:output_inline]
end
def fail_fast?
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb
index acfba21f1c..0aa6ce2252 100644
--- a/railties/test/application/test_runner_test.rb
+++ b/railties/test/application/test_runner_test.rb
@@ -341,30 +341,21 @@ module ApplicationTests
end
def test_output_inline_by_default
- app_file 'test/models/post_test.rb', <<-RUBY
- require 'test_helper'
+ create_test_file :models, 'post', pass: false
- class PostTest < ActiveSupport::TestCase
- def test_post
- assert false, 'wups!'
- end
- end
- RUBY
+ output = run_test_command('test/models/post_test.rb')
+ assert_match %r{Running:\n\nPostTest\nF\n\nwups!\n\nbin/rails test test/models/post_test.rb:4}, output
+ end
+
+ def test_only_inline_failure_output
+ create_test_file :models, 'post', pass: false
output = run_test_command('test/models/post_test.rb')
- assert_match %r{Running:\n\nF\n\nwups!\n\nbin/rails test test/models/post_test.rb:4}, output
+ assert_match %r{Finished in.*\n\n1 runs, 1 assertions}, output
end
def test_fail_fast
- app_file 'test/models/post_test.rb', <<-RUBY
- require 'test_helper'
-
- class PostTest < ActiveSupport::TestCase
- def test_post
- assert false, 'wups!'
- end
- end
- RUBY
+ create_test_file :models, 'post', pass: false
assert_match(/Interrupt/,
capture(:stderr) { run_test_command('test/models/post_test.rb --fail-fast') })
@@ -426,14 +417,14 @@ module ApplicationTests
app_file 'db/schema.rb', ''
end
- def create_test_file(path = :unit, name = 'test')
+ def create_test_file(path = :unit, name = 'test', pass: true)
app_file "test/#{path}/#{name}_test.rb", <<-RUBY
require 'test_helper'
class #{name.camelize}Test < ActiveSupport::TestCase
def test_truth
puts "#{name.camelize}Test"
- assert true
+ assert #{pass}, 'wups!'
end
end
RUBY
diff --git a/railties/test/test_unit/reporter_test.rb b/railties/test/test_unit/reporter_test.rb
index 59fdf4bc36..fa6bb71c64 100644
--- a/railties/test/test_unit/reporter_test.rb
+++ b/railties/test/test_unit/reporter_test.rb
@@ -8,7 +8,7 @@ class TestUnitReporterTest < ActiveSupport::TestCase
setup do
@output = StringIO.new
- @reporter = Rails::TestUnitReporter.new @output
+ @reporter = Rails::TestUnitReporter.new @output, output_inline: true
end
test "prints rerun snippet to run a single failed test" do
@@ -72,7 +72,7 @@ class TestUnitReporterTest < ActiveSupport::TestCase
end
test "outputs skipped tests inline if verbose" do
- verbose = Rails::TestUnitReporter.new @output, verbose: true
+ verbose = Rails::TestUnitReporter.new @output, verbose: true, output_inline: true
verbose.record(skipped_test)
verbose.report