Skip to content

Commit 8ceb7b9

Browse files
authored
Merge pull request rails#53200 from davidstosik/sto/test-leaks
Fix some (flaky?) failures in railties tests
2 parents f799e4a + 376f62f commit 8ceb7b9

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

railties/lib/rails/test_unit/runner.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def path_argument?(arg)
125125
def list_tests(patterns)
126126
tests = Rake::FileList[patterns.any? ? patterns : default_test_glob]
127127
tests.exclude(default_test_exclude_glob) if patterns.empty?
128+
tests.exclude(%r{test/isolation/assets/node_modules})
128129
tests
129130
end
130131

railties/test/abstract_unit.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
module TestApp
1818
class Application < Rails::Application
19-
config.root = __dir__
19+
config.root = File.expand_path("../../", __FILE__)
2020
end
2121
end
2222

railties/test/generators/namespaced_generators_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ class NamespacedGeneratorTestCase < Rails::Generators::TestCase
1212

1313
def setup
1414
super
15+
@old_namespace = Rails::Generators.namespace
1516
Rails::Generators.namespace = TestApp
1617
end
18+
19+
def teardown
20+
super
21+
Rails::Generators.namespace = @old_namespace
22+
end
1723
end
1824

1925
class NamespacedControllerGeneratorTest < NamespacedGeneratorTestCase

railties/test/isolation/abstract_unit.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ def assert_welcome(resp)
105105
module Generation
106106
# Build an application by invoking the generator and going through the whole stack.
107107
def build_app(options = {})
108+
@prev_rails_app_class = Rails.app_class
109+
@prev_rails_application = Rails.application
110+
Rails.app_class = Rails.application = nil
111+
108112
@prev_rails_env = ENV["RAILS_ENV"]
109113
ENV["RAILS_ENV"] = "development"
110114

@@ -150,6 +154,8 @@ def build_app(options = {})
150154

151155
def teardown_app
152156
ENV["RAILS_ENV"] = @prev_rails_env if @prev_rails_env
157+
Rails.app_class = @prev_rails_app_class if @prev_rails_app_class
158+
Rails.application = @prev_rails_application if @prev_rails_application
153159
FileUtils.rm_rf(tmp_path)
154160
end
155161

railties/test/test_unit/reporter_test.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def woot; end
1818
record(failed_test)
1919
@reporter.report
2020

21-
assert_match %r{^bin/rails test .*test/test_unit/reporter_test\.rb:\d+$}, @output.string
21+
assert_match %r{^#{test_run_command_regex} .*test/test_unit/reporter_test\.rb:\d+$}, @output.string
2222
assert_rerun_snippet_count 1
2323
end
2424

@@ -64,15 +64,15 @@ def woot; end
6464
record(failed_test)
6565
@reporter.report
6666

67-
expect = %r{\AF\n\nFailure:\nTestUnitReporterTest::ExampleTest#woot \[[^\]]+\]:\nboo\n\nbin/rails test test/test_unit/reporter_test\.rb:\d+\n\n\z}
67+
expect = %r{\AF\n\nFailure:\nTestUnitReporterTest::ExampleTest#woot \[[^\]]+\]:\nboo\n\n#{test_run_command_regex} test/test_unit/reporter_test\.rb:\d+\n\n\z}
6868
assert_match expect, @output.string
6969
end
7070

7171
test "outputs errors inline" do
7272
record(errored_test)
7373
@reporter.report
7474

75-
expect = %r{\AE\n\nError:\nTestUnitReporterTest::ExampleTest#woot:\nArgumentError: wups\n some_test.rb:4\n\nbin/rails test .*test/test_unit/reporter_test\.rb:\d+\n\n\z}
75+
expect = %r{\AE\n\nError:\nTestUnitReporterTest::ExampleTest#woot:\nArgumentError: wups\n some_test.rb:4\n\n#{test_run_command_regex} .*test/test_unit/reporter_test\.rb:\d+\n\n\z}
7676
assert_match expect, @output.string
7777
end
7878

@@ -81,7 +81,7 @@ def woot; end
8181
record(skipped_test)
8282
@reporter.report
8383

84-
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}
84+
expect = %r{\ATestUnitReporterTest::ExampleTest#woot = 10\.00 s = S\n\n\nSkipped:\nTestUnitReporterTest::ExampleTest#woot \[[^\]]+\]:\nskipchurches, misstemples\n\n#{test_run_command_regex} test/test_unit/reporter_test\.rb:\d+\n\n\z}
8585
assert_match expect, @output.string
8686
end
8787

@@ -152,7 +152,7 @@ def woot; end
152152
@reporter = Rails::TestUnitReporter.new @output, color: true, output_inline: true
153153
record(failed_test)
154154

155-
expected = %r{\e\[31mF\e\[0m\n\n\e\[31mFailure:\nTestUnitReporterTest::ExampleTest#woot \[test/test_unit/reporter_test.rb:\d+\]:\nboo\n\e\[0m\n\nbin/rails test .*test/test_unit/reporter_test.rb:\d+\n\n}
155+
expected = %r{\e\[31mF\e\[0m\n\n\e\[31mFailure:\nTestUnitReporterTest::ExampleTest#woot \[test/test_unit/reporter_test.rb:\d+\]:\nboo\n\e\[0m\n\n#{test_run_command_regex} .*test/test_unit/reporter_test.rb:\d+\n\n}
156156
assert_match expected, @output.string
157157
end
158158
end
@@ -174,7 +174,7 @@ def record(test_result)
174174
end
175175

176176
def assert_rerun_snippet_count(snippet_count)
177-
assert_equal snippet_count, @output.string.scan(%r{^bin/rails test }).size
177+
assert_equal snippet_count, @output.string.scan(%r{^#{test_run_command_regex} }).size
178178
end
179179

180180
def failed_test
@@ -210,4 +210,8 @@ def skipped_test
210210
st.time = 10
211211
st
212212
end
213+
214+
def test_run_command_regex
215+
%r{bin/rails test|bin/test}
216+
end
213217
end

0 commit comments

Comments
 (0)