Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundler binstubs #33202

Merged
merged 3 commits into from Aug 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions railties/lib/rails/generators/app_base.rb
Expand Up @@ -458,6 +458,12 @@ def run_webpack
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")
Expand Down
2 changes: 2 additions & 0 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -299,6 +299,8 @@ def create_bin_files
build(:bin)
end

public_task :generate_bundler_binstub

def update_bin_files
build(:bin_when_updating)
end
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion railties/test/generators/api_app_generator_test.rb
Expand Up @@ -118,7 +118,6 @@ def default_files
app/views/layouts
app/views/layouts/mailer.html.erb
app/views/layouts/mailer.text.erb
bin/bundle
bin/rails
bin/rake
bin/setup
Expand Down
50 changes: 21 additions & 29 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -37,7 +37,6 @@
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
Expand Down Expand Up @@ -739,17 +738,23 @@ def test_web_console_with_edge_option
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

Expand All @@ -758,23 +763,14 @@ def test_spring
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"
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
Expand Down Expand Up @@ -952,7 +948,7 @@ def test_after_bundle_callback
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}"
Expand All @@ -969,7 +965,7 @@ def test_after_bundle_callback
end
end

assert_equal 4, @sequence_step
assert_equal 5, @sequence_step
end

def test_gitignore
Expand Down Expand Up @@ -1039,18 +1035,14 @@ def assert_no_listen_related_configuration
end
end

def assert_generates_with_bundler(options = {})
generator([destination_root], options)

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

Expand Down