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: Factor out some common bundler mocking logic --- railties/test/generators/app_generator_test.rb | 29 ++++++++------------------ 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'railties') 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 @@ class AppGeneratorTest < Rails::Generators::TestCase 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 @@ class AppGeneratorTest < Rails::Generators::TestCase 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 -- cgit v1.2.3 From 3b0c1ef9c4b4a255d5069316f05338e404d5bd96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 23 Jun 2018 14:00:25 -0300 Subject: Improve readability of some specs --- railties/test/generators/app_generator_test.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 00ca8cad0d..58a6067cee 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -739,17 +739,23 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_generation_runs_bundle_install - assert_generates_with_bundler + generator([destination_root], {}) + + assert_bundler_command_called("install") end def test_dev_option - assert_generates_with_bundler dev: true + generator([destination_root], dev: true) + + assert_bundler_command_called("install") rails_path = File.expand_path("../../..", Rails.root) assert_file "Gemfile", /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/ end def test_edge_option - assert_generates_with_bundler edge: true + generator([destination_root], edge: true) + + assert_bundler_command_called("install") assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["']$} end @@ -1026,12 +1032,6 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - 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 @command_called ||= 0 -- cgit v1.2.3 From ee8d7850fd38b4602dc1d40323addc3448b60947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 23 Jun 2018 13:27:19 -0300 Subject: Generate bundler-compatible bundler binstub --- railties/lib/rails/generators/app_base.rb | 6 ++++++ railties/lib/rails/generators/rails/app/app_generator.rb | 2 ++ railties/lib/rails/generators/rails/app/templates/bin/bundle.tt | 2 -- railties/test/generators/api_app_generator_test.rb | 1 - railties/test/generators/app_generator_test.rb | 9 ++++++--- 5 files changed, 14 insertions(+), 6 deletions(-) delete mode 100644 railties/lib/rails/generators/rails/app/templates/bin/bundle.tt (limited to 'railties') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index f51542f3ec..3c5dfb2e92 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -458,6 +458,12 @@ module Rails end end + def generate_bundler_binstub + if bundle_install? + bundle_command("binstubs bundler") + end + end + def generate_spring_binstubs if bundle_install? && spring_install? bundle_command("exec spring binstub --all") diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 34067240d7..cc45a64b25 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -299,6 +299,8 @@ module Rails build(:bin) end + public_task :generate_bundler_binstub + def update_bin_files build(:bin_when_updating) end diff --git a/railties/lib/rails/generators/rails/app/templates/bin/bundle.tt b/railties/lib/rails/generators/rails/app/templates/bin/bundle.tt deleted file mode 100644 index a84f0afe47..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/bin/bundle.tt +++ /dev/null @@ -1,2 +0,0 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -load Gem.bin_path('bundler', 'bundle') diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index 9c523ad372..c2540f4091 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -118,7 +118,6 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase app/views/layouts app/views/layouts/mailer.html.erb app/views/layouts/mailer.text.erb - bin/bundle bin/rails bin/rake bin/setup diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 58a6067cee..4f6ff222ef 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -37,7 +37,6 @@ DEFAULT_APP_FILES = %w( app/views/layouts/application.html.erb app/views/layouts/mailer.html.erb app/views/layouts/mailer.text.erb - bin/bundle bin/rails bin/rake bin/setup @@ -764,6 +763,10 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_gem "spring" end + def test_bundler_binstub + assert_bundler_command_called("binstubs bundler") + end + def test_spring_binstubs jruby_skip "spring doesn't run on JRuby" @@ -945,7 +948,7 @@ class AppGeneratorTest < Rails::Generators::TestCase template end - sequence = ["git init", "install", "exec spring binstub --all", "echo ran after_bundle"] + sequence = ["git init", "binstubs bundler", "install", "exec spring binstub --all", "echo ran after_bundle"] @sequence_step ||= 0 ensure_bundler_first = -> command, options = nil do assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}" @@ -962,7 +965,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - assert_equal 4, @sequence_step + assert_equal 5, @sequence_step end def test_gitignore -- cgit v1.2.3