Skip to content

Commit 368b993

Browse files
committed
Merge pull request rails#20870 from y-yagi/test_runner_inside_engine
make test runner work correctly inside engine
2 parents 908bc79 + 824246f commit 368b993

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
require "rails/test_unit/minitest_plugin"
22

3-
$: << File.expand_path("../../test", APP_PATH)
3+
if defined?(ENGINE_ROOT)
4+
$: << File.expand_path('test', ENGINE_ROOT)
5+
else
6+
$: << File.expand_path('../../test', APP_PATH)
7+
end
48

59
exit Minitest.run(ARGV)

railties/lib/rails/engine/commands.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
aliases = {
44
"g" => "generate",
5-
"d" => "destroy"
5+
"d" => "destroy",
6+
"t" => "test"
67
}
78

89
command = ARGV.shift
@@ -12,7 +13,7 @@
1213
engine = ::Rails::Engine.find(ENGINE_ROOT)
1314

1415
case command
15-
when 'generate', 'destroy'
16+
when 'generate', 'destroy', 'test'
1617
require 'rails/generators'
1718
Rails::Generators.namespace = engine.railtie_namespace
1819
engine.load_generators
@@ -30,6 +31,7 @@
3031
The common Rails commands available for engines are:
3132
generate Generate new code (short-cut alias: "g")
3233
destroy Undo code generated with "generate" (short-cut alias: "d")
34+
test Run tests (short-cut alias: "t")
3335
3436
All commands can be run with -h for more information.
3537

railties/test/generators/scaffold_controller_generator_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_controller_tests_pass_by_default_inside_mountable_engine
182182

183183
Dir.chdir(engine_path) do
184184
quietly { `bin/rails g controller dashboard foo` }
185-
assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
185+
assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`)
186186
end
187187
end
188188

@@ -193,7 +193,7 @@ def test_controller_tests_pass_by_default_inside_full_engine
193193

194194
Dir.chdir(engine_path) do
195195
quietly { `bin/rails g controller dashboard foo` }
196-
assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
196+
assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`)
197197
end
198198
end
199199

railties/test/generators/scaffold_generator_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def test_scaffold_tests_pass_by_default_inside_mountable_engine
488488
`bin/rails g scaffold User name:string age:integer;
489489
bundle exec rake db:migrate`
490490
end
491-
assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
491+
assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`)
492492
end
493493
end
494494

@@ -502,7 +502,7 @@ def test_scaffold_tests_pass_by_default_inside_full_engine
502502
`bin/rails g scaffold User name:string age:integer;
503503
bundle exec rake db:migrate`
504504
end
505-
assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
505+
assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`)
506506
end
507507
end
508508
end

0 commit comments

Comments
 (0)