Skip to content

Commit 2e59604

Browse files
committed
make it possible to customize the executable inside rereun snippets.
In the Rails repository we use a `bin/test` executable to run our tests. However the rerun snippets still included `bin/rails test`: BEFORE: ``` Failed tests: bin/rails test test/cases/adapters/postgresql/schema_test.rb:91 ``` AFTER: ``` Failed tests: bin/test test/cases/adapters/postgresql/schema_test.rb:91 ```
1 parent c0b4654 commit 2e59604

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

railties/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Make it possible to customize the executable inside rerun snippets.
2+
3+
*Yves Senn*
4+
15
* Add support for API only apps.
26
Middleware stack was slimmed down and it has only the needed
37
middleware for API apps & generators generates the right files,

railties/lib/rails/test_unit/reporter.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
require "active_support/core_ext/class/attribute"
12
require "minitest"
23

34
module Rails
45
class TestUnitReporter < Minitest::StatisticsReporter
6+
class_attribute :executable
7+
self.executable = "bin/rails test"
8+
59
def report
610
return if results.empty?
711
io.puts
@@ -15,7 +19,7 @@ def aggregated_results # :nodoc:
1519
filtered_results.reject!(&:skipped?) unless options[:verbose]
1620
filtered_results.map do |result|
1721
location, line = result.method(result.name).source_location
18-
"bin/rails test #{relative_path_for(location)}:#{line}"
22+
"#{self.executable} #{relative_path_for(location)}:#{line}"
1923
end.join "\n"
2024
end
2125

railties/test/test_unit/reporter_test.rb

+14
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ def woot; end
4343
assert_rerun_snippet_count 1
4444
end
4545

46+
test "allows to customize the executable in the rerun snippet" do
47+
original_executable = Rails::TestUnitReporter.executable
48+
begin
49+
Rails::TestUnitReporter.executable = "bin/test"
50+
verbose = Rails::TestUnitReporter.new @output, verbose: true
51+
@reporter.record(failed_test)
52+
@reporter.report
53+
54+
assert_match %r{^bin/test .*test/test_unit/reporter_test.rb:6$}, @output.string
55+
ensure
56+
Rails::TestUnitReporter.executable = original_executable
57+
end
58+
end
59+
4660
private
4761
def assert_rerun_snippet_count(snippet_count)
4862
assert_equal snippet_count, @output.string.scan(%r{^bin/rails test }).size

tools/test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ def self.root
88
@root ||= Pathname.new(COMPONENT_ROOT)
99
end
1010
end
11+
12+
Rails::TestUnitReporter.executable = "bin/test"

0 commit comments

Comments
 (0)