diff options
Diffstat (limited to 'railties')
7 files changed, 106 insertions, 17 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 2f18619e30..064b109a6f 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -75,7 +75,7 @@ module Rails class_option :edge, type: :boolean, default: false, desc: "Setup the #{name} with Gemfile pointing to Rails repository" - class_option :rc, type: :string, default: false, + class_option :rc, type: :string, default: nil, desc: "Path to file containing extra configuration options for rails command" class_option :no_rc, type: :boolean, default: false, diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb index 40c831ec58..78f4530514 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb @@ -1,5 +1,5 @@ # Be sure to restart your server when you modify this file. -# Require `belongs_to` associations by default. This is a new Rails 5.0 default, +# Require `belongs_to` associations by default. This is a new Rails 5.0 default, # so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading. Rails.application.config.active_record.belongs_to_required_by_default = true diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb index 43510c244b..0b718aa1c6 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb @@ -1,5 +1,5 @@ # Be sure to restart your server when you modify this file. -# Do not halt callback chains when a callback returns false. This is a new Rails 5.0 default, +# Do not halt callback chains when a callback returns false. This is a new Rails 5.0 default, # so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading. ActiveSupport.halt_callback_chains_on_return_false = false diff --git a/railties/lib/rails/generators/rails/plugin/templates/README.md b/railties/lib/rails/generators/rails/plugin/templates/README.md index 61ad1ed36a..9d2b74416e 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/README.md +++ b/railties/lib/rails/generators/rails/plugin/templates/README.md @@ -1,3 +1,28 @@ # <%= camelized_modules %> +Short description and motivation. -This project rocks and uses MIT-LICENSE. +## Usage +How to use my plugin. + +## Installation +Add this line to your application's Gemfile: + +```ruby +gem '<%= name %>' +``` + +And then execute: +```bash +$ bundle +``` + +Or install it yourself as: +```bash +$ gem install <%= name %> +``` + +## Contributing +Contribution directions go here. + +## License +The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb index d39d2f32bf..d4ab2ada66 100644 --- a/railties/lib/rails/test_unit/minitest_plugin.rb +++ b/railties/lib/rails/test_unit/minitest_plugin.rb @@ -3,16 +3,13 @@ require "rails/test_unit/reporter" require "rails/test_unit/test_requirer" module Minitest - mattr_accessor(:hide_aggregated_results) { false } - - module AggregatedResultSuppresion + class SuppressedSummaryReporter < SummaryReporter + # Disable extra failure output after a run if output is inline. def aggregated_results - super unless Minitest.hide_aggregated_results + super unless options[:output_inline] end end - SummaryReporter.prepend AggregatedResultSuppresion - def self.plugin_rails_options(opts, options) executable = ::Rails::TestUnitReporter.executable opts.separator "" @@ -49,6 +46,12 @@ module Minitest options[:fail_fast] = true end + opts.on("-c", "--[no-]color", + "Enable color in the output") do |value| + options[:color] = value + end + + options[:color] = true options[:output_inline] = true options[:patterns] = opts.order! end @@ -77,9 +80,8 @@ 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.reporters.clear # Replace progress reporter for colors. + self.reporter << SuppressedSummaryReporter.new(options[:io], options) 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 695c67756b..73b8d7d27b 100644 --- a/railties/lib/rails/test_unit/reporter.rb +++ b/railties/lib/rails/test_unit/reporter.rb @@ -9,10 +9,16 @@ module Rails def record(result) super + if options[:verbose] + io.puts color_output(format_line(result), by: result) + else + io.print color_output(result.result_code, by: result) + end + if output_inline? && result.failure && (!result.skipped? || options[:verbose]) io.puts io.puts - io.puts format_failures(result) + io.puts format_failures(result).map { |line| color_output(line, by: result) } io.puts io.puts format_rerun_snippet(result) io.puts @@ -56,6 +62,10 @@ module Rails options[:fail_fast] end + def format_line(result) + "%s#%s = %.2f s = %s" % [result.class, result.name, result.time, result.result_code] + end + def format_failures(result) result.failures.map do |failure| "#{failure.result_label}:\n#{result.class}##{result.name}:\n#{failure.message}\n" @@ -76,5 +86,25 @@ module Rails def app_root @app_root ||= defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root end + + def colored_output? + options[:color] && io.respond_to?(:tty?) && io.tty? + end + + codes = { red: 31, green: 32, yellow: 33 } + COLOR_BY_RESULT_CODE = { + "." => codes[:green], + "E" => codes[:red], + "F" => codes[:red], + "S" => codes[:yellow] + } + + def color_output(string, by:) + if colored_output? + "\e[#{COLOR_BY_RESULT_CODE[by.result_code]}m#{string}\e[0m" + else + string + end + end end end diff --git a/railties/test/test_unit/reporter_test.rb b/railties/test/test_unit/reporter_test.rb index 3ff7cd18cd..2d08d4ec30 100644 --- a/railties/test/test_unit/reporter_test.rb +++ b/railties/test/test_unit/reporter_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'rails/test_unit/reporter' +require 'minitest/mock' class TestUnitReporterTest < ActiveSupport::TestCase class ExampleTest < Minitest::Test @@ -61,7 +62,7 @@ class TestUnitReporterTest < ActiveSupport::TestCase @reporter.record(failed_test) @reporter.report - expect = %r{\A\n\nFailure:\nTestUnitReporterTest::ExampleTest#woot:\nboo\n\nbin/rails test test/test_unit/reporter_test.rb:\d+\n\n\z} + expect = %r{\AF\n\nFailure:\nTestUnitReporterTest::ExampleTest#woot:\nboo\n\nbin/rails test test/test_unit/reporter_test.rb:\d+\n\n\z} assert_match expect, @output.string end @@ -69,7 +70,7 @@ class TestUnitReporterTest < ActiveSupport::TestCase @reporter.record(errored_test) @reporter.report - expect = %r{\A\n\nError:\nTestUnitReporterTest::ExampleTest#woot:\nArgumentError: wups\n No backtrace\n\nbin/rails test .*test/test_unit/reporter_test.rb:6\n\n\z} + expect = %r{\AE\n\nError:\nTestUnitReporterTest::ExampleTest#woot:\nArgumentError: wups\n No backtrace\n\nbin/rails test .*test/test_unit/reporter_test.rb:\d+\n\n\z} assert_match expect, @output.string end @@ -78,7 +79,7 @@ class TestUnitReporterTest < ActiveSupport::TestCase verbose.record(skipped_test) verbose.report - expect = %r{\A\n\nSkipped:\nTestUnitReporterTest::ExampleTest#woot:\nskipchurches, misstemples\n\nbin/rails test test/test_unit/reporter_test.rb:\d+\n\n\z} + expect = %r{\ATestUnitReporterTest::ExampleTest#woot = 10\.00 s = S\n\n\nSkipped:\nTestUnitReporterTest::ExampleTest#woot:\nskipchurches, misstemples\n\nbin/rails test test/test_unit/reporter_test.rb:\d+\n\n\z} assert_match expect, @output.string end @@ -113,6 +114,36 @@ class TestUnitReporterTest < ActiveSupport::TestCase assert_no_match 'Failed tests:', @output.string end + test "outputs colored passing results" do + @output.stub(:tty?, true) do + colored = Rails::TestUnitReporter.new @output, color: true, output_inline: true + colored.record(passing_test) + + expect = %r{\e\[32m\.\e\[0m} + assert_match expect, @output.string + end + end + + test "outputs colored skipped results" do + @output.stub(:tty?, true) do + colored = Rails::TestUnitReporter.new @output, color: true, output_inline: true + colored.record(skipped_test) + + expect = %r{\e\[33mS\e\[0m} + assert_match expect, @output.string + end + end + + test "outputs colored failed results" do + @output.stub(:tty?, true) do + colored = Rails::TestUnitReporter.new @output, color: true, output_inline: true + colored.record(errored_test) + + expected = %r{\e\[31mE\e\[0m\n\n\e\[31mError:\nTestUnitReporterTest::ExampleTest#woot:\nArgumentError: wups\n No backtrace\n\e\[0m} + assert_match expected, @output.string + end + end + private def assert_rerun_snippet_count(snippet_count) assert_equal snippet_count, @output.string.scan(%r{^bin/rails test }).size @@ -145,6 +176,7 @@ class TestUnitReporterTest < ActiveSupport::TestCase rescue Minitest::Assertion => e e end + st.time = 10 st end end |