Skip to content

Commit 26c4ba3

Browse files
committed
Do not run bundle install when generating a new plugin.
Since bundler 1.12.0, the gemspec is validated so the `bundle install` command will fail just after the gem is created causing confusion to the users. This change was a bug fix to correctly validate gemspecs.
1 parent 5a85938 commit 26c4ba3

File tree

5 files changed

+67
-39
lines changed

5 files changed

+67
-39
lines changed

railties/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
* Do not run `bundle install` when generating a new plugin.
2+
3+
Since bundler 1.12.0, the gemspec is validated so the `bundle install`
4+
command will fail just after the gem is created causing confusion to the
5+
users. This change was a bug fix to correctly validate gemspecs.
6+
7+
*Rafael Mendonça França*
8+
9+
110
## Rails 4.2.7.rc1 (June 30, 2016) ##
211

312
* No changes.

railties/lib/rails/generators/rails/plugin/plugin_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def finish_template
241241
build(:leftovers)
242242
end
243243

244-
public_task :apply_rails_template, :run_bundle
244+
public_task :apply_rails_template
245245

246246
def name
247247
@name ||= begin

railties/test/generators/app_generator_test.rb

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,21 @@ def test_web_console
420420
assert_gem 'web-console'
421421
end
422422

423+
def test_generation_runs_bundle_install
424+
assert_generates_with_bundler
425+
end
426+
427+
def test_dev_option
428+
assert_generates_with_bundler dev: true
429+
rails_path = File.expand_path('../../..', Rails.root)
430+
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
431+
end
432+
433+
def test_edge_option
434+
assert_generates_with_bundler edge: true
435+
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("4-2-stable")}["']$}
436+
end
437+
423438
def test_spring
424439
run_generator
425440
assert_gem 'spring'
@@ -518,15 +533,22 @@ def test_after_bundle_callback
518533

519534
protected
520535

521-
def action(*args, &block)
522-
capture(:stdout) { generator.send(*args, &block) }
523-
end
536+
def action(*args, &block)
537+
capture(:stdout) { generator.send(*args, &block) }
538+
end
524539

525-
def assert_gem(gem, constraint = nil)
526-
if constraint
527-
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/
528-
else
529-
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/
540+
def assert_gem(gem, constraint = nil)
541+
if constraint
542+
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/
543+
else
544+
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/
545+
end
546+
end
547+
548+
def assert_generates_with_bundler(options = {})
549+
generator([destination_root], options)
550+
generator.expects(:bundle_command).with('install').once
551+
generator.stubs(:bundle_command).with('exec spring binstub --all')
552+
quietly { generator.invoke_all }
530553
end
531-
end
532554
end

railties/test/generators/plugin_generator_test.rb

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,32 @@ def test_ensure_that_database_option_is_passed_to_app_generator
158158
assert_file "test/dummy/config/database.yml", /postgres/
159159
end
160160

161-
def test_generation_runs_bundle_install_with_full_and_mountable
162-
result = run_generator [destination_root, "--mountable", "--full", "--dev"]
163-
assert_match(/run bundle install/, result)
164-
assert $?.success?, "Command failed: #{result}"
165-
assert_file "#{destination_root}/Gemfile.lock" do |contents|
166-
assert_match(/bukkits/, contents)
167-
end
161+
def test_generation_runs_bundle_install
162+
generator([destination_root])
163+
generator.expects(:bundle_command).with('install').never
164+
quietly { generator.invoke_all }
165+
end
166+
167+
def test_dev_option
168+
generator([destination_root], dev: true)
169+
generator.expects(:bundle_command).with('install').never
170+
quietly { generator.invoke_all }
171+
rails_path = File.expand_path('../../..', Rails.root)
172+
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
173+
end
174+
175+
def test_edge_option
176+
generator([destination_root], edge: true)
177+
generator.expects(:bundle_command).with('install').never
178+
quietly { generator.invoke_all }
179+
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("4-2-stable")}["']$}
180+
end
181+
182+
def test_generation_does_not_run_bundle_install_with_full_and_mountable
183+
generator([destination_root], mountable: true, full: true, dev: true)
184+
generator.expects(:bundle_command).with('install').never
185+
quietly { generator.invoke_all }
186+
assert_no_file "#{destination_root}/Gemfile.lock"
168187
end
169188

170189
def test_skipping_javascripts_without_mountable_option

railties/test/generators/shared_generator_tests.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@ def test_skeleton_is_created
2626
default_files.each { |path| assert_file path }
2727
end
2828

29-
def assert_generates_with_bundler(options = {})
30-
generator([destination_root], options)
31-
generator.expects(:bundle_command).with('install').once
32-
generator.stubs(:bundle_command).with('exec spring binstub --all')
33-
quietly { generator.invoke_all }
34-
end
35-
36-
def test_generation_runs_bundle_install
37-
assert_generates_with_bundler
38-
end
39-
4029
def test_plugin_new_generate_pretend
4130
run_generator ["testapp", "--pretend"]
4231
default_files.each{ |path| assert_no_file File.join("testapp",path) }
@@ -104,17 +93,6 @@ def test_template_is_executed_when_supplied_an_https_path
10493
quietly { assert_match(/It works!/, capture(:stdout) { generator.invoke_all }) }
10594
end
10695

107-
def test_dev_option
108-
assert_generates_with_bundler dev: true
109-
rails_path = File.expand_path('../../..', Rails.root)
110-
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
111-
end
112-
113-
def test_edge_option
114-
assert_generates_with_bundler edge: true
115-
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("4-2-stable")}["']$$}
116-
end
117-
11896
def test_skip_gemfile
11997
generator([destination_root], skip_gemfile: true).expects(:bundle_command).never
12098
quietly { generator.invoke_all }

0 commit comments

Comments
 (0)