diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-02 23:07:56 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-02 23:07:56 +0000 |
commit | 59c8d50653480bef3f24517296e6ddf937fdf6bc (patch) | |
tree | df10aaf4f3307837fe3d1d129d66f6c0c7586bc5 /spec/bundler/runtime/executable_spec.rb | |
parent | 7deb37777a230837e865e0a11fb8d7c1dc6d03ce (diff) | |
download | ruby-59c8d50653480bef3f24517296e6ddf937fdf6bc.tar.gz |
Added bundler as default gems. Revisit [Feature #12733]
* bin/*, lib/bundler/*, lib/bundler.rb, spec/bundler, man/*:
Merge from latest stable branch of bundler/bundler repository and
added workaround patches. I will backport them into upstream.
* common.mk, defs/gmake.mk: Added `test-bundler` task for test suite
of bundler.
* tool/sync_default_gems.rb: Added sync task for bundler.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/bundler/runtime/executable_spec.rb')
-rw-r--r-- | spec/bundler/runtime/executable_spec.rb | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/spec/bundler/runtime/executable_spec.rb b/spec/bundler/runtime/executable_spec.rb new file mode 100644 index 0000000000..dcee234e15 --- /dev/null +++ b/spec/bundler/runtime/executable_spec.rb @@ -0,0 +1,190 @@ +# frozen_string_literal: true + +RSpec.describe "Running bin/* commands" do + before :each do + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "rack" + G + end + + it "runs the bundled command when in the bundle" do + bundle! "binstubs rack" + + build_gem "rack", "2.0", :to_system => true do |s| + s.executables = "rackup" + end + + gembin "rackup" + expect(out).to eq("1.0.0") + end + + it "allows the location of the gem stubs to be specified" do + bundle! "binstubs rack", :path => "gbin" + + expect(bundled_app("bin")).not_to exist + expect(bundled_app("gbin/rackup")).to exist + + gembin bundled_app("gbin/rackup") + expect(out).to eq("1.0.0") + end + + it "allows absolute paths as a specification of where to install bin stubs" do + bundle! "binstubs rack", :path => tmp("bin") + + gembin tmp("bin/rackup") + expect(out).to eq("1.0.0") + end + + it "uses the default ruby install name when shebang is not specified" do + bundle! "binstubs rack" + expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env #{RbConfig::CONFIG["ruby_install_name"]}\n") + end + + it "allows the name of the shebang executable to be specified" do + bundle! "binstubs rack", :shebang => "ruby-foo" + expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env ruby-foo\n") + end + + it "runs the bundled command when out of the bundle" do + bundle! "binstubs rack" + + build_gem "rack", "2.0", :to_system => true do |s| + s.executables = "rackup" + end + + Dir.chdir(tmp) do + gembin "rackup" + expect(out).to eq("1.0.0") + end + end + + it "works with gems in path" do + build_lib "rack", :path => lib_path("rack") do |s| + s.executables = "rackup" + end + + gemfile <<-G + gem "rack", :path => "#{lib_path("rack")}" + G + + bundle! "binstubs rack" + + build_gem "rack", "2.0", :to_system => true do |s| + s.executables = "rackup" + end + + gembin "rackup" + expect(out).to eq("1.0") + end + + it "creates a bundle binstub" do + build_gem "bundler", Bundler::VERSION, :to_system => true do |s| + s.executables = "bundle" + end + + gemfile <<-G + source "file://#{gem_repo1}" + gem "bundler" + G + + bundle! "binstubs bundler" + + expect(bundled_app("bin/bundle")).to exist + end + + it "does not generate bin stubs if the option was not specified" do + bundle! "install" + + expect(bundled_app("bin/rackup")).not_to exist + end + + it "allows you to stop installing binstubs", :bundler => "< 2" do + bundle! "install --binstubs bin/" + bundled_app("bin/rackup").rmtree + bundle! "install --binstubs \"\"" + + expect(bundled_app("bin/rackup")).not_to exist + + bundle! "config bin" + expect(out).to include("You have not configured a value for `bin`") + end + + it "remembers that the option was specified", :bundler => "< 2" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "activesupport" + G + + bundle! :install, forgotten_command_line_options([:binstubs, :bin] => "bin") + + gemfile <<-G + source "file://#{gem_repo1}" + gem "activesupport" + gem "rack" + G + + bundle "install" + + expect(bundled_app("bin/rackup")).to exist + end + + it "rewrites bins on --binstubs (to maintain backwards compatibility)", :bundler => "< 2" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle! :install, forgotten_command_line_options([:binstubs, :bin] => "bin") + + File.open(bundled_app("bin/rackup"), "wb") do |file| + file.print "OMG" + end + + bundle "install" + + expect(bundled_app("bin/rackup").read).to_not eq("OMG") + end + + it "rewrites bins on binstubs (to maintain backwards compatibility)" do + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + create_file("bin/rackup", "OMG") + + bundle! "binstubs rack" + + expect(bundled_app("bin/rackup").read).to_not eq("OMG") + end + + it "use BUNDLE_GEMFILE gemfile for binstub" do + # context with bin/bunlder w/ default Gemfile + bundle! "binstubs bundler" + + # generate other Gemfile with executable gem + build_repo2 do + build_gem("bindir") {|s| s.executables = "foo" } + end + + create_file("OtherGemfile", <<-G) + source "file://#{gem_repo2}" + gem 'bindir' + G + + # generate binstub for executable from non default Gemfile (other then bin/bundler version) + ENV["BUNDLE_GEMFILE"] = "OtherGemfile" + bundle "install" + bundle! "binstubs bindir" + + # remove user settings + ENV["BUNDLE_GEMFILE"] = nil + + # run binstub for non default Gemfile + gembin "foo" + + expect(exitstatus).to eq(0) if exitstatus + expect(out).to eq("1.0") + end +end |