Permalink
Browse files

application and plugin generation run bundle check unless --skip-gemfile

The purpose of this feature is that the user knows whether
dependencies are satisfied. In particular, if they are not
he will be warned upfront, rather than finding out himself
in an abrupt way by trying to run something.
  • Loading branch information...
fxn committed May 12, 2011
1 parent 55d87d2 commit c88dddbe4d40c9e0590df4d6f76c02c46448264d
View
@@ -1,5 +1,7 @@
*Rails 3.1.0 (unreleased)*
+* Application and plugin generation run bundle check unless --skip-gemfile. [fxn]
+
* Fixed database tasks for jdbc* adapters #jruby
[Rashmi Yadav]
@@ -184,9 +184,20 @@ def gem_for_javascript
"gem '#{options[:javascript]}-rails'" unless options[:skip_javascript]
end
- def bundle_if_dev_or_edge
- bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
- run "#{bundle_command} install" if dev_or_edge?
+ def bundle_command(command)
+ # We use backticks and #print here instead of vanilla #system because it
+ # is easier to silence stdout in the existing test suite this way. The
+ # end-user gets the bundler commands called anyway.
+ #
+ # Thanks to James Tucker for the Gem tricks involved in this call.
+ print `"#{Gem.ruby}" -rubygems "#{Gem.bin_path('bundler', 'bundle')}" #{command}`
+ end
+
+ def run_bundle
+ unless options[:skip_gemfile]
+ command = dev_or_edge? ? 'install' : 'check'
+ bundle_command(command)
+ end
end
def dev_or_edge?
@@ -225,7 +225,7 @@ def finish_template
build(:leftovers)
end
- public_task :apply_rails_template, :bundle_if_dev_or_edge
+ public_task :apply_rails_template, :run_bundle
protected
@@ -209,7 +209,7 @@ def finish_template
build(:leftovers)
end
- public_task :apply_rails_template, :bundle_if_dev_or_edge
+ public_task :apply_rails_template, :run_bundle
protected
@@ -119,17 +119,17 @@ def test_template_from_dir_pwd
assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]))
end
- def test_ensure_that_tests_works
+ def test_ensure_that_tests_work
run_generator
FileUtils.cd destination_root
- `bundle install`
+ `bundle install` # use backticks to silence stdout
assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`)
end
def test_ensure_that_tests_works_in_full_mode
run_generator [destination_root, "--full", "--skip_active_record"]
FileUtils.cd destination_root
- `bundle install`
+ `bundle install` # use backticks to silence stdout
assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`)
end
@@ -6,7 +6,6 @@ def setup
Rails.application = TestApp::Application
super
Rails::Generators::AppGenerator.instance_variable_set('@desc', nil)
- @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
Kernel::silence_warnings do
Thor::Base.shell.send(:attr_accessor, :always_force)
@@ -24,7 +23,12 @@ def teardown
def test_skeleton_is_created
run_generator
- default_files.each{ |path| assert_file path }
+ default_files.each { |path| assert_file path }
+ end
+
+ def test_generation_runs_bundle_check
+ generator([destination_root]).expects(:bundle_command).with('check').once
+ silence(:stdout) { generator.invoke_all }
end
def test_plugin_new_generate_pretend
@@ -112,25 +116,30 @@ def test_template_is_executed_when_supplied_an_https_path
end
def test_dev_option
- generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install")
- silence(:stdout){ generator.invoke_all }
+ generator([destination_root], :dev => true).expects(:bundle_command).with('install').once
+ silence(:stdout) { generator.invoke_all }
rails_path = File.expand_path('../../..', Rails.root)
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
- generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install")
- silence(:stdout){ generator.invoke_all }
+ generator([destination_root], :edge => true).expects(:bundle_command).with('install').once
+ silence(:stdout) { generator.invoke_all }
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$}
end
+
+ def test_skip_gemfile
+ generator([destination_root], :skip_gemfile => true).expects(:bundle_command).never
+ silence(:stdout) { generator.invoke_all }
+ assert_no_file 'Gemfile'
+ end
end
module SharedCustomGeneratorTests
def setup
Rails.application = TestApp::Application
super
Rails::Generators::AppGenerator.instance_variable_set('@desc', nil)
- @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
end
def teardown

0 comments on commit c88dddb

Please sign in to comment.