From d2a91a7f90584dd3552430740c549d8c9257a588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 23 Jun 2018 13:52:11 -0300 Subject: [PATCH] Factor out some common bundler mocking logic --- .../test/generators/app_generator_test.rb | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index d8e9ae3369..00ca8cad0d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -760,21 +760,8 @@ def test_spring def test_spring_binstubs jruby_skip "spring doesn't run on JRuby" - command_check = -> command do - @binstub_called ||= 0 - case command - when "install" - # Called when running bundle, we just want to stub it so nothing to do here. - when "exec spring binstub --all" - @binstub_called += 1 - assert_equal 1, @binstub_called, "exec spring binstub --all expected to be called once, but was called #{@install_called} times." - end - end - - generator.stub :bundle_command, command_check do - quietly { generator.invoke_all } - end + assert_bundler_command_called("exec spring binstub --all") end def test_spring_no_fork @@ -1042,15 +1029,17 @@ def assert_no_listen_related_configuration def assert_generates_with_bundler(options = {}) generator([destination_root], options) + assert_bundler_command_called("install") + end + + def assert_bundler_command_called(target_command) command_check = -> command do - @install_called ||= 0 + @command_called ||= 0 case command - when "install" - @install_called += 1 - assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times" - when "exec spring binstub --all" - # Called when running tests with spring, let through unscathed. + when target_command + @command_called += 1 + assert_equal 1, @command_called, "#{command} expected to be called once, but was called #{@command_called} times." end end -- GitLab