Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make "rake test" display not only task name but also exception message. #1899

Merged
merged 2 commits into from

2 participants

@ihower

The "rake test" ignores the exception message. This pull request displays not only task name but also the exception message.

For example:

Errors running test:units, test:functionals!

This pull request:

Errors running test:units! Access denied for user ''@'localhost' to database...
Errors running test:functionals! Command failed with status...

@josevalim
Owner

Tks for the pull request, I like it. Do you think you could add a test to this new format? We already have some here:

https://github.com/rails/rails/blob/master/railties/test/application/rake_test.rb

@ihower

Add test. I can't find good way to test the abort message so I change to puts.

@josevalim
Owner

Thanks. About capturing stderr, wouldn't using capture(:stderr) work? It is defined in this file (that probably should be required as well):

https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/kernel/reporting.rb

@ihower

It seems the abort method writes to STDERR directly, not $stderr, so it will capture nothing.
STDERR only support reopen to change the os's file descriptor and does not accept StringIO.new :/

@josevalim josevalim merged commit c49d1f2 into from
@josevalim
Owner

Fair enough. merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 railties/lib/rails/test_unit/testing.rake
@@ -79,10 +79,14 @@ task :test do
Rake::Task[task].invoke
nil
rescue => e
- task
+ { :task => task, :exception => e }
end
end.compact
- abort "Errors running #{errors * ', '}!" if errors.any?
+
+ if errors.any?
+ puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
+ abort
+ end
end
namespace :test do
View
26 railties/test/application/rake_test.rb
@@ -59,6 +59,32 @@ def test_code_statistics_sanity
Dir.chdir(app_path){ `rake stats` }
end
+ def test_rake_test_error_output
+ Dir.chdir(app_path){ `rake db:migrate` }
+
+ app_file "config/database.yml", <<-RUBY
+ development:
+ RUBY
+
+ app_file "test/unit/one_unit_test.rb", <<-RUBY
+ RUBY
+
+ app_file "test/functional/one_functional_test.rb", <<-RUBY
+ raise RuntimeError
+ RUBY
+
+ app_file "test/integration/one_integration_test.rb", <<-RUBY
+ raise RuntimeError
+ RUBY
+
+ silence_stderr do
+ output = Dir.chdir(app_path){ `rake test` }
+ assert_match /Errors running test:units! #<ActiveRecord::AdapterNotSpecified/, output
+ assert_match /Errors running test:functionals! #<RuntimeError/, output
+ assert_match /Errors running test:integration! #<RuntimeError/, output
+ end
+ end
+
def test_rake_routes_output_strips_anchors_from_http_verbs
app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
Something went wrong with that request. Please try again.