Skip to content

Commit

Permalink
make it possible to customize the executable inside rereun snippets.
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
senny committed Jun 13, 2015
1 parent c0b4654 commit 2e59604
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Make it possible to customize the executable inside rerun snippets.

*Yves Senn*

* Add support for API only apps.
Middleware stack was slimmed down and it has only the needed
middleware for API apps & generators generates the right files,
Expand Down
6 changes: 5 additions & 1 deletion railties/lib/rails/test_unit/reporter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require "active_support/core_ext/class/attribute"
require "minitest"

module Rails
class TestUnitReporter < Minitest::StatisticsReporter
class_attribute :executable
self.executable = "bin/rails test"

def report
return if results.empty?
io.puts
Expand All @@ -15,7 +19,7 @@ def aggregated_results # :nodoc:
filtered_results.reject!(&:skipped?) unless options[:verbose]
filtered_results.map do |result|
location, line = result.method(result.name).source_location
"bin/rails test #{relative_path_for(location)}:#{line}"
"#{self.executable} #{relative_path_for(location)}:#{line}"
end.join "\n"
end

Expand Down
14 changes: 14 additions & 0 deletions railties/test/test_unit/reporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ def woot; end
assert_rerun_snippet_count 1
end

test "allows to customize the executable in the rerun snippet" do
original_executable = Rails::TestUnitReporter.executable
begin
Rails::TestUnitReporter.executable = "bin/test"
verbose = Rails::TestUnitReporter.new @output, verbose: true
@reporter.record(failed_test)
@reporter.report

assert_match %r{^bin/test .*test/test_unit/reporter_test.rb:6$}, @output.string
ensure
Rails::TestUnitReporter.executable = original_executable
end
end

private
def assert_rerun_snippet_count(snippet_count)
assert_equal snippet_count, @output.string.scan(%r{^bin/rails test }).size
Expand Down
2 changes: 2 additions & 0 deletions tools/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ def self.root
@root ||= Pathname.new(COMPONENT_ROOT)
end
end

Rails::TestUnitReporter.executable = "bin/test"

0 comments on commit 2e59604

Please sign in to comment.