aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-10-28 13:44:17 +0100
committerYves Senn <yves.senn@gmail.com>2013-11-04 10:00:44 +0100
commit84eac5dab8b0fe9ee20b51250e52ad7bfea36553 (patch)
tree9b7fd4f9c9796d6c716a3f974961d2bf4c640927
parent876fd5a5d4f424e6699a66058a13c9cda8d92f64 (diff)
downloadrails-84eac5dab8b0fe9ee20b51250e52ad7bfea36553.tar.gz
rails-84eac5dab8b0fe9ee20b51250e52ad7bfea36553.tar.bz2
rails-84eac5dab8b0fe9ee20b51250e52ad7bfea36553.zip
BACKTRACE environment variable to show unfiltered backtraces.
We used to support the `BACKTRACE` environment variable but when we switched to MiniTest it got removed: f9382cd7948 This commit adds back the functionality to show the unfiltered backtrace when needed. This also works when you run your tests with `rake`: * `BACKTRACE=1 bin/rake test` * `BACKTRACE=1 ruby -Itest ...`
-rw-r--r--railties/CHANGELOG.md11
-rw-r--r--railties/lib/rails/test_help.rb4
-rw-r--r--railties/test/application/test_test.rb39
3 files changed, 48 insertions, 6 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index aadf24a125..0606a4fbe7 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,14 @@
+* `BACKTRACE` environment variable to show unfiltered backtraces for
+ test failures.
+
+ Example:
+
+ `BACKTRACE=1 ruby -Itest ...`
+ # or with rake
+ `BAKCTRACE=1 bin/rake`
+
+ *Yves Senn*
+
* Removal of all javascript stuff (gems and files) when generating a new
application using the `--skip-javascript` option.
diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb
index 46f7466551..be801befc2 100644
--- a/railties/lib/rails/test_help.rb
+++ b/railties/lib/rails/test_help.rb
@@ -10,7 +10,9 @@ require 'rails/generators/test_case'
# Config Rails backtrace in tests.
require 'rails/backtrace_cleaner'
-MiniTest.backtrace_filter = Rails.backtrace_cleaner
+if ENV["BACKTRACE"].nil?
+ MiniTest.backtrace_filter = Rails.backtrace_cleaner
+end
if defined?(ActiveRecord::Base)
class ActiveSupport::TestCase
diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb
index c7ad2fba8f..6f2f328588 100644
--- a/railties/test/application/test_test.rb
+++ b/railties/test/application/test_test.rb
@@ -24,7 +24,7 @@ module ApplicationTests
end
RUBY
- run_test_file 'unit/foo_test.rb'
+ assert_successful_test_run 'unit/foo_test.rb'
end
test "integration test" do
@@ -49,19 +49,48 @@ module ApplicationTests
end
RUBY
- run_test_file 'integration/posts_test.rb'
+ assert_successful_test_run 'integration/posts_test.rb'
+ end
+
+ test "enable full backtraces on test failures" do
+ app_file 'test/unit/failing_test.rb', <<-RUBY
+ require 'test_helper'
+
+ class FailingTest < ActiveSupport::TestCase
+ def test_failure
+ raise "fail"
+ end
+ end
+ RUBY
+
+ output = run_test_file('unit/failing_test.rb', env: { "BACKTRACE" => "1" })
+ assert_match %r{/app/test/unit/failing_test\.rb}, output
end
private
- def run_test_file(name)
- result = ruby '-Itest', "#{app_path}/test/#{name}"
+ def assert_successful_test_run(name)
+ result = run_test_file(name)
assert_equal 0, $?.to_i, result
end
+ def run_test_file(name, options = {})
+ ruby '-Itest', "#{app_path}/test/#{name}", options
+ end
+
def ruby(*args)
+ options = args.extract_options!
+ env = options.fetch(:env, {})
+ env["RUBYLIB"] = $:.join(':')
+
Dir.chdir(app_path) do
- `RUBYLIB='#{$:.join(':')}' #{Gem.ruby} #{args.join(' ')}`
+ `#{env_string(env)} #{Gem.ruby} #{args.join(' ')}`
end
end
+
+ def env_string(variables)
+ variables.map do |key, value|
+ "#{key}='#{value}'"
+ end.join " "
+ end
end
end