Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2576 from lucasmazza/multiple-binstubs
Browse files Browse the repository at this point in the history
Add support for multiple gems in `bundle binstubs`
  • Loading branch information
indirect committed Aug 1, 2013
2 parents a20d093 + a6c248b commit cadc77a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,26 @@ def show(gem_name = nil)
"binstub destination directory (default bin)"
method_option "force", :type => :boolean, :default => false, :banner =>
"overwrite existing binstubs if they exist"
def binstubs(gem_name)
def binstubs(*gems)
Bundler.definition.validate_ruby!
Bundler.settings[:bin] = options["path"] if options["path"]
Bundler.settings[:bin] = nil if options["path"] && options["path"].empty?
installer = Installer.new(Bundler.root, Bundler.definition)
spec = installer.specs.find{|s| s.name == gem_name }
raise GemNotFound, not_found_message(gem_name, Bundler.definition.specs) unless spec

if spec.name == "bundler"
Bundler.ui.warn "Sorry, Bundler can only be run via Rubygems."
else
installer.generate_bundler_executable_stubs(spec, :force => options[:force], :binstubs_cmd => true)
if gems.empty?
Bundler.ui.error "`bundle binstubs` needs at least one gem to run."
exit 1
end

gems.each do |gem_name|
spec = installer.specs.find{|s| s.name == gem_name }
raise GemNotFound, not_found_message(gem_name, Bundler.definition.specs) unless spec

if spec.name == "bundler"
Bundler.ui.warn "Sorry, Bundler can only be run via Rubygems."
else
installer.generate_bundler_executable_stubs(spec, :force => options[:force], :binstubs_cmd => true)
end
end
end

Expand Down
24 changes: 24 additions & 0 deletions spec/other/binstubs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
expect(bundled_app("bin/rails")).to exist
end

it "does install multiple binstubs" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
gem "rails"
G

bundle "binstubs rails rack"

expect(bundled_app("bin/rackup")).to exist
expect(bundled_app("bin/rails")).to exist
end

it "displays an error when used without any gem" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
G

bundle "binstubs", :exitstatus => true
expect(exitstatus).to eq(1)
expect(out).to eq("`bundle binstubs` needs at least one gem to run.")
end

it "does not bundle the bundler binary" do
install_gemfile <<-G
source "file://#{gem_repo1}"
Expand Down

0 comments on commit cadc77a

Please sign in to comment.