diff options
author | Andre Arko <andre@arko.net> | 2013-07-24 23:15:29 -0700 |
---|---|---|
committer | Jessica Lynn Suttles <jlsuttles@gmail.com> | 2013-08-05 14:15:50 -0700 |
commit | 0750d45b3933a5d1f28ebf4494c8505739a3a827 (patch) | |
tree | cf42596c66c2494271f552609d5f6b06fe5a97bf /spec/commands | |
parent | 4a53681628b895c7d0d372269ffd556d78763826 (diff) | |
download | bundler-0750d45b3933a5d1f28ebf4494c8505739a3a827.tar.gz |
break out cli command specs into a dedicated dir
move the dispatch integration specs into other
load friendly_errors so we can unit test it
require Thor so we can rescue the errors
bump ArgumentError above Exception so it wins
Diffstat (limited to 'spec/commands')
-rw-r--r-- | spec/commands/binstubs_spec.rb | 193 | ||||
-rw-r--r-- | spec/commands/check_spec.rb | 278 | ||||
-rw-r--r-- | spec/commands/clean_spec.rb | 592 | ||||
-rw-r--r-- | spec/commands/config_spec.rb | 181 | ||||
-rw-r--r-- | spec/commands/console_spec.rb | 54 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 270 | ||||
-rw-r--r-- | spec/commands/help_spec.rb | 39 | ||||
-rw-r--r-- | spec/commands/init_spec.rb | 39 | ||||
-rw-r--r-- | spec/commands/licenses_spec.rb | 18 | ||||
-rw-r--r-- | spec/commands/newgem_spec.rb | 403 | ||||
-rw-r--r-- | spec/commands/open_spec.rb | 55 | ||||
-rw-r--r-- | spec/commands/outdated_spec.rb | 116 | ||||
-rw-r--r-- | spec/commands/show_spec.rb | 102 |
13 files changed, 2340 insertions, 0 deletions
diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb new file mode 100644 index 0000000000..3d3ed0fc58 --- /dev/null +++ b/spec/commands/binstubs_spec.rb @@ -0,0 +1,193 @@ +require "spec_helper" + +describe "bundle binstubs <gem>" do + context "when the gem exists in the lockfile" do + it "sets up the binstub" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle "binstubs rack" + + expect(bundled_app("bin/rackup")).to exist + end + + it "does not install other binstubs" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "rails" + G + + bundle "binstubs rails" + + expect(bundled_app("bin/rackup")).not_to exist + 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}" + G + + bundle "binstubs bundler" + + expect(bundled_app("bin/bundle")).not_to exist + expect(out).to eq("Sorry, Bundler can only be run via Rubygems.") + end + + it "installs binstubs from git gems" do + FileUtils.mkdir_p(lib_path("foo/bin")) + FileUtils.touch(lib_path("foo/bin/foo")) + build_git "foo", "1.0", :path => lib_path("foo") do |s| + s.executables = %w(foo) + end + install_gemfile <<-G + gem "foo", :git => "#{lib_path('foo')}" + G + + bundle "binstubs foo" + + expect(bundled_app("bin/foo")).to exist + end + + it "installs binstubs from path gems" do + FileUtils.mkdir_p(lib_path("foo/bin")) + FileUtils.touch(lib_path("foo/bin/foo")) + build_lib "foo" , "1.0", :path => lib_path("foo") do |s| + s.executables = %w(foo) + end + install_gemfile <<-G + gem "foo", :path => "#{lib_path('foo')}" + G + + bundle "binstubs foo" + + expect(bundled_app("bin/foo")).to exist + end + end + + context "--path" do + it "sets the binstubs dir" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle "binstubs rack --path exec" + + expect(bundled_app("exec/rackup")).to exist + end + + it "setting is saved for bundle install" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "rails" + G + + bundle "binstubs rack --path exec" + bundle :install + + expect(bundled_app("exec/rails")).to exist + end + end + + context "when the bin already exists" do + it "doesn't overwrite and warns" do + FileUtils.mkdir_p(bundled_app("bin")) + File.open(bundled_app("bin/rackup"), 'wb') do |file| + file.print "OMG" + end + + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle "binstubs rack" + + expect(bundled_app("bin/rackup")).to exist + expect(File.read(bundled_app("bin/rackup"))).to eq("OMG") + expect(out).to include("Skipped rackup") + expect(out).to include("overwrite skipped stubs, use --force") + end + + context "when using --force" do + it "overwrites the binstub" do + FileUtils.mkdir_p(bundled_app("bin")) + File.open(bundled_app("bin/rackup"), 'wb') do |file| + file.print "OMG" + end + + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle "binstubs rack --force" + + expect(bundled_app("bin/rackup")).to exist + expect(File.read(bundled_app("bin/rackup"))).not_to eq("OMG") + end + end + end + + context "when the gem has no bins" do + it "suggests child gems if they have bins" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack-obama" + G + + bundle "binstubs rack-obama" + expect(out).to include('rack-obama has no executables') + expect(out).to include('rack has: rackup') + end + + it "works if child gems don't have bins" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "actionpack" + G + + bundle "binstubs actionpack" + expect(out).to include('no executables for the gem actionpack') + end + + it "works if the gem has development dependencies" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "with_development_dependency" + G + + bundle "binstubs with_development_dependency" + expect(out).to include('no executables for the gem with_development_dependency') + end + end +end diff --git a/spec/commands/check_spec.rb b/spec/commands/check_spec.rb new file mode 100644 index 0000000000..248b5c2eed --- /dev/null +++ b/spec/commands/check_spec.rb @@ -0,0 +1,278 @@ +require "spec_helper" + +describe "bundle check" do + it "returns success when the Gemfile is satisfied" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + + bundle :check, :exitstatus => true + expect(@exitstatus).to eq(0) + expect(out).to eq("The Gemfile's dependencies are satisfied") + end + + it "works with the --gemfile flag when not in the directory" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + + Dir.chdir tmp + bundle "check --gemfile bundled_app/Gemfile" + expect(out).to eq("The Gemfile's dependencies are satisfied") + end + + it "creates a Gemfile.lock by default if one does not exist" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + + FileUtils.rm("Gemfile.lock") + + bundle "check" + + expect(bundled_app("Gemfile.lock")).to exist + end + + it "does not create a Gemfile.lock if --dry-run was passed" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + + FileUtils.rm("Gemfile.lock") + + bundle "check --dry-run" + + expect(bundled_app("Gemfile.lock")).not_to exist + end + + it "prints a generic error if the missing gems are unresolvable" do + system_gems ["rails-2.3.2"] + + gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + + bundle :check + expect(out).to include("Bundler can't satisfy your Gemfile's dependencies.") + end + + it "prints a generic error if a Gemfile.lock does not exist and a toplevel dependency does not exist" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + + bundle :check, :exitstatus => true + expect(@exitstatus).to be > 0 + expect(out).to include("Bundler can't satisfy your Gemfile's dependencies.") + end + + it "prints a generic message if you changed your lockfile" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem 'rails' + G + install_gemfile <<-G + source "file://#{gem_repo1}" + gem 'rails_fail' + G + + gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + gem "rails_fail" + G + + bundle :check + expect(out).to include("Bundler can't satisfy your Gemfile's dependencies.") + end + + it "remembers --without option from install" do + gemfile <<-G + source "file://#{gem_repo1}" + group :foo do + gem "rack" + end + G + + bundle "install --without foo" + bundle "check", :exitstatus => true + expect(@exitstatus).to eq(0) + expect(out).to include("The Gemfile's dependencies are satisfied") + end + + it "ensures that gems are actually installed and not just cached" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", :group => :foo + G + + bundle "install --without foo" + + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle "check", :exitstatus => true + expect(out).to include("* rack (1.0.0)") + expect(@exitstatus).to eq(1) + end + + it "ignores missing gems restricted to other platforms" do + system_gems "rack-1.0.0" + + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + platforms :#{not_local_tag} do + gem "activesupport" + end + G + + lockfile <<-G + GEM + remote: file:#{gem_repo1}/ + specs: + activesupport (2.3.5) + rack (1.0.0) + + PLATFORMS + #{local} + #{not_local} + + DEPENDENCIES + rack + activesupport + G + + bundle :check + expect(out).to eq("The Gemfile's dependencies are satisfied") + end + + it "works with env conditionals" do + system_gems "rack-1.0.0" + + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + env :NOT_GOING_TO_BE_SET do + gem "activesupport" + end + G + + lockfile <<-G + GEM + remote: file:#{gem_repo1}/ + specs: + activesupport (2.3.5) + rack (1.0.0) + + PLATFORMS + #{local} + #{not_local} + + DEPENDENCIES + rack + activesupport + G + + bundle :check + expect(out).to eq("The Gemfile's dependencies are satisfied") + end + + it "outputs an error when the default Gemfile is not found" do + bundle :check, :exitstatus => true + expect(@exitstatus).to eq(10) + expect(out).to include("Could not locate Gemfile") + end + + it "does not output fatal error message" do + bundle :check, :exitstatus => true + expect(@exitstatus).to eq(10) + expect(out).not_to include("Unfortunately, a fatal error has occurred. ") + end + + it "should not crash when called multiple times on a new machine" do + gemfile <<-G + gem 'rails', '3.0.0.beta3' + gem 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git' + G + + simulate_new_machine + bundle "check" + last_out = out + 3.times do |i| + bundle :check + expect(out).to eq(last_out) + expect(err).to be_empty + end + end + + it "fails when there's no lock file and frozen is set" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "foo" + G + + bundle "install" + bundle "install --deployment" + FileUtils.rm(bundled_app("Gemfile.lock")) + + bundle :check, :exitstatus => true + expect(exitstatus).not_to eq(0) + end + + context "--path" do + before do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + bundle "install --path vendor/bundle" + + FileUtils.rm_rf(bundled_app(".bundle")) + end + + it "returns success" do + bundle "check --path vendor/bundle", :exitstatus => true + expect(@exitstatus).to eq(0) + expect(out).to eq("The Gemfile's dependencies are satisfied") + end + + it "should write to .bundle/config" do + bundle "check --path vendor/bundle", :exitstatus => true + bundle "check", :exitstatus => true + expect(@exitstatus).to eq(0) + end + end + + describe "when locked" do + before :each do + system_gems "rack-1.0.0" + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "1.0" + G + end + + it "returns success when the Gemfile is satisfied" do + bundle :install + bundle :check, :exitstatus => true + expect(@exitstatus).to eq(0) + expect(out).to eq("The Gemfile's dependencies are satisfied") + end + + it "shows what is missing with the current Gemfile if it is not satisfied" do + simulate_new_machine + bundle :check + expect(out).to match(/The following gems are missing/) + expect(out).to include("* rack (1.0") + end + end +end diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb new file mode 100644 index 0000000000..cee1312a5f --- /dev/null +++ b/spec/commands/clean_spec.rb @@ -0,0 +1,592 @@ +require "spec_helper" + +describe "bundle clean" do + def should_have_gems(*gems) + gems.each do |g| + expect(vendored_gems("gems/#{g}")).to exist + expect(vendored_gems("specifications/#{g}.gemspec")).to exist + expect(vendored_gems("cache/#{g}.gem")).to exist + end + end + + def should_not_have_gems(*gems) + gems.each do |g| + expect(vendored_gems("gems/#{g}")).not_to exist + expect(vendored_gems("specifications/#{g}.gemspec")).not_to exist + expect(vendored_gems("cache/#{g}.gem")).not_to exist + end + end + + it "removes unused gems that are different" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + gem "foo" + G + + bundle "install --path vendor/bundle --no-clean" + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + G + bundle "install" + + bundle :clean + + expect(out).to eq("Removing foo (1.0)") + + should_have_gems 'thin-1.0', 'rack-1.0.0' + should_not_have_gems 'foo-1.0' + + expect(vendored_gems("bin/rackup")).to exist + end + + it "removes old version of gem if unused" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "0.9.1" + gem "foo" + G + + bundle "install --path vendor/bundle --no-clean" + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + gem "foo" + G + bundle "install" + + bundle :clean + + expect(out).to eq("Removing rack (0.9.1)") + + should_have_gems 'foo-1.0', 'rack-1.0.0' + should_not_have_gems 'rack-0.9.1' + + expect(vendored_gems("bin/rackup")).to exist + end + + it "removes new version of gem if unused" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + gem "foo" + G + + bundle "install --path vendor/bundle --no-clean" + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "0.9.1" + gem "foo" + G + bundle "install" + + bundle :clean + + expect(out).to eq("Removing rack (1.0.0)") + + should_have_gems 'foo-1.0', 'rack-0.9.1' + should_not_have_gems 'rack-1.0.0' + + expect(vendored_gems("bin/rackup")).to exist + end + + it "removes gems in bundle without groups" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "foo" + + group :test_group do + gem "rack", "1.0.0" + end + G + + bundle "install --path vendor/bundle" + bundle "install --without test_group" + bundle :clean + + expect(out).to eq("Removing rack (1.0.0)") + + should_have_gems 'foo-1.0' + should_not_have_gems 'rack-1.0.0' + + expect(vendored_gems("bin/rackup")).to_not exist + end + + it "does not remove cached git dir if it's being used" do + build_git "foo" + revision = revision_for(lib_path("foo-1.0")) + git_path = lib_path('foo-1.0') + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + git "#{git_path}", :ref => "#{revision}" do + gem "foo" + end + G + + bundle "install --path vendor/bundle" + + bundle :clean + + digest = Digest::SHA1.hexdigest(git_path.to_s) + expect(vendored_gems("cache/bundler/git/foo-1.0-#{digest}")).to exist + end + + it "removes unused git gems" do + build_git "foo", :path => lib_path("foo") + git_path = lib_path('foo') + revision = revision_for(git_path) + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + git "#{git_path}", :ref => "#{revision}" do + gem "foo" + end + G + + bundle "install --path vendor/bundle" + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + G + bundle "install" + + bundle :clean + + expect(out).to eq("Removing foo (#{revision[0..11]})") + + expect(vendored_gems("gems/rack-1.0.0")).to exist + expect(vendored_gems("bundler/gems/foo-#{revision[0..11]}")).not_to exist + digest = Digest::SHA1.hexdigest(git_path.to_s) + expect(vendored_gems("cache/bundler/git/foo-#{digest}")).not_to exist + + expect(vendored_gems("specifications/rack-1.0.0.gemspec")).to exist + + expect(vendored_gems("bin/rackup")).to exist + end + + it "removes old git gems" do + build_git "foo-bar", :path => lib_path("foo-bar") + revision = revision_for(lib_path("foo-bar")) + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + git "#{lib_path('foo-bar')}" do + gem "foo-bar" + end + G + + bundle "install --path vendor/bundle" + + update_git "foo", :path => lib_path("foo-bar") + revision2 = revision_for(lib_path("foo-bar")) + + bundle "update" + bundle :clean + + expect(out).to eq("Removing foo-bar (#{revision[0..11]})") + + expect(vendored_gems("gems/rack-1.0.0")).to exist + expect(vendored_gems("bundler/gems/foo-bar-#{revision[0..11]}")).not_to exist + expect(vendored_gems("bundler/gems/foo-bar-#{revision2[0..11]}")).to exist + + expect(vendored_gems("specifications/rack-1.0.0.gemspec")).to exist + + expect(vendored_gems("bin/rackup")).to exist + end + + it "does not remove nested gems in a git repo" do + build_lib "activesupport", "3.0", :path => lib_path("rails/activesupport") + build_git "rails", "3.0", :path => lib_path("rails") do |s| + s.add_dependency "activesupport", "= 3.0" + end + revision = revision_for(lib_path("rails")) + + gemfile <<-G + gem "activesupport", :git => "#{lib_path('rails')}", :ref => '#{revision}' + G + + bundle "install --path vendor/bundle" + bundle :clean + expect(out).to eq("") + + expect(vendored_gems("bundler/gems/rails-#{revision[0..11]}")).to exist + end + + it "does not remove git sources that are in without groups" do + build_git "foo", :path => lib_path("foo") + git_path = lib_path('foo') + revision = revision_for(git_path) + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + group :test do + git "#{git_path}", :ref => "#{revision}" do + gem "foo" + end + end + G + bundle "install --path vendor/bundle --without test" + + bundle :clean + + expect(out).to eq("") + expect(vendored_gems("bundler/gems/foo-#{revision[0..11]}")).to exist + digest = Digest::SHA1.hexdigest(git_path.to_s) + expect(vendored_gems("cache/bundler/git/foo-#{digest}")).to_not exist + end + + it "does not blow up when using without groups" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + + group :development do + gem "foo" + end + G + + bundle "install --path vendor/bundle --without development" + + bundle :clean, :exitstatus => true + expect(exitstatus).to eq(0) + end + + it "displays an error when used without --path" do + install_gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + G + + bundle :clean, :exitstatus => true + + expect(exitstatus).to eq(1) + expect(out).to eq("Can only use bundle clean when --path is set or --force is set") + end + + # handling bundle clean upgrade path from the pre's + it "removes .gem/.gemspec file even if there's no corresponding gem dir" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + gem "foo" + G + + bundle "install --path vendor/bundle" + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "foo" + G + bundle "install" + + FileUtils.rm(vendored_gems("bin/rackup")) + FileUtils.rm_rf(vendored_gems("gems/thin-1.0")) + FileUtils.rm_rf(vendored_gems("gems/rack-1.0.0")) + + bundle :clean + + should_not_have_gems 'thin-1.0', 'rack-1.0' + should_have_gems 'foo-1.0' + + expect(vendored_gems("bin/rackup")).not_to exist + end + + it "does not call clean automatically when using system gems" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + gem "rack" + G + bundle :install + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + G + bundle :install + + sys_exec "gem list" + expect(out).to include("rack (1.0.0)") + expect(out).to include("thin (1.0)") + end + + it "--clean should override the bundle setting on install" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + gem "rack" + G + bundle "install --path vendor/bundle --clean" + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + G + bundle "install" + + should_have_gems 'rack-1.0.0' + should_not_have_gems 'thin-1.0' + end + + it "--clean should override the bundle setting on update" do + build_repo2 + + gemfile <<-G + source "file://#{gem_repo2}" + + gem "foo" + G + bundle "install --path vendor/bundle --clean" + + update_repo2 do + build_gem 'foo', '1.0.1' + end + + bundle "update" + + should_have_gems 'foo-1.0.1' + should_not_have_gems 'foo-1.0' + end + + it "does not clean automatically on --path" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + gem "rack" + G + bundle "install --path vendor/bundle" + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + G + bundle "install" + + should_have_gems 'rack-1.0.0', 'thin-1.0' + end + + it "does not clean on bundle update with --path" do + build_repo2 + + gemfile <<-G + source "file://#{gem_repo2}" + + gem "foo" + G + bundle "install --path vendor/bundle" + + update_repo2 do + build_gem 'foo', '1.0.1' + end + + bundle :update + should_have_gems 'foo-1.0', 'foo-1.0.1' + end + + it "does not clean on bundle update when using --system" do + build_repo2 + + gemfile <<-G + source "file://#{gem_repo2}" + + gem "foo" + G + bundle "install" + + update_repo2 do + build_gem 'foo', '1.0.1' + end + bundle :update + + sys_exec "gem list" + expect(out).to include("foo (1.0.1, 1.0)") + end + + it "cleans system gems when --force is used" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "foo" + gem "rack" + G + bundle :install + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "rack" + G + bundle :install + bundle "clean --force" + + expect(out).to eq("Removing foo (1.0)") + sys_exec "gem list" + expect(out).not_to include("foo (1.0)") + expect(out).to include("rack (1.0.0)") + end + + it "cleans git gems with a 7 length git revision" do + build_git "foo" + revision = revision_for(lib_path("foo-1.0")) + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "foo", :git => "#{lib_path('foo-1.0')}" + G + + bundle "install --path vendor/bundle" + + # mimic 7 length git revisions in Gemfile.lock + gemfile_lock = File.read(bundled_app('Gemfile.lock')).split("\n") + gemfile_lock.each_with_index do |line, index| + gemfile_lock[index] = line[0..(11 + 7)] if line.include?(" revision:") + end + File.open(bundled_app('Gemfile.lock'), 'w') do |file| + file.print gemfile_lock.join("\n") + end + + bundle "install --path vendor/bundle" + + bundle :clean + + expect(out).not_to include("Removing foo (1.0 #{revision[0..6]})") + + expect(vendored_gems("bundler/gems/foo-1.0-#{revision[0..6]}")).to exist + end + + it "when using --force on system gems, it doesn't remove binaries" do + build_repo2 + update_repo2 do + build_gem 'bindir' do |s| + s.bindir = "exe" + s.executables = "foo" + end + end + + gemfile <<-G + source "file://#{gem_repo2}" + + gem "bindir" + G + bundle :install + + bundle "clean --force" + + sys_status "foo" + + expect(exitstatus).to eq(0) + expect(out).to eq("1.0") + end + + it "doesn't blow up on path gems without a .gempsec" do + relative_path = "vendor/private_gems/bar-1.0" + absolute_path = bundled_app(relative_path) + FileUtils.mkdir_p("#{absolute_path}/lib/bar") + File.open("#{absolute_path}/lib/bar/bar.rb", 'wb') do |file| + file.puts "module Bar; end" + end + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "foo" + gem "bar", "1.0", :path => "#{relative_path}" + G + + bundle "install --path vendor/bundle" + bundle :clean, :exitstatus => true + + expect(exitstatus).to eq(0) + end + + it "doesn't remove gems in dry-run mode" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + gem "foo" + G + + bundle "install --path vendor/bundle --no-clean" + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + G + + bundle :install + + bundle "clean --dry-run" + + expect(out).not_to eq("Removing foo (1.0)") + expect(out).to eq("Would have removed foo (1.0)") + + should_have_gems 'thin-1.0', 'rack-1.0.0', 'foo-1.0' + + expect(vendored_gems("bin/rackup")).to exist + end + + it "doesn't store dry run as a config setting" do + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + gem "foo" + G + + bundle "install --path vendor/bundle --no-clean" + bundle "config dry_run false" + + gemfile <<-G + source "file://#{gem_repo1}" + + gem "thin" + G + + bundle :install + + bundle "clean" + + expect(out).to eq("Removing foo (1.0)") + expect(out).not_to eq("Would have removed foo (1.0)") + + should_have_gems 'thin-1.0', 'rack-1.0.0' + should_not_have_gems 'foo-1.0' + + expect(vendored_gems("bin/rackup")).to exist + end +end diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb new file mode 100644 index 0000000000..100889bce7 --- /dev/null +++ b/spec/commands/config_spec.rb @@ -0,0 +1,181 @@ +require "spec_helper" + +describe ".bundle/config" do + before :each do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "1.0.0" + G + end + + describe "BUNDLE_APP_CONFIG" do + it "can be moved with an environment variable" do + ENV['BUNDLE_APP_CONFIG'] = tmp('foo/bar').to_s + bundle "install --path vendor/bundle" + + expect(bundled_app('.bundle')).not_to exist + expect(tmp('foo/bar/config')).to exist + should_be_installed "rack 1.0.0" + end + + it "can provide a relative path with the environment variable" do + FileUtils.mkdir_p bundled_app('omg') + Dir.chdir bundled_app('omg') + + ENV['BUNDLE_APP_CONFIG'] = "../foo" + bundle "install --path vendor/bundle" + + expect(bundled_app(".bundle")).not_to exist + expect(bundled_app("../foo/config")).to exist + should_be_installed "rack 1.0.0" + end + + it "removes environment.rb from BUNDLE_APP_CONFIG's path" do + FileUtils.mkdir_p(tmp('foo/bar')) + ENV['BUNDLE_APP_CONFIG'] = tmp('foo/bar').to_s + bundle "install" + FileUtils.touch tmp('foo/bar/environment.rb') + should_be_installed "rack 1.0.0" + expect(tmp('foo/bar/environment.rb')).not_to exist + end + end + + describe "global" do + before(:each) { bundle :install } + + it "is the default" do + bundle "config foo global" + run "puts Bundler.settings[:foo]" + expect(out).to eq("global") + end + + it "can also be set explicitly" do + bundle "config --global foo global" + run "puts Bundler.settings[:foo]" + expect(out).to eq("global") + end + + it "has lower precedence than local" do + bundle "config --local foo local" + + bundle "config --global foo global" + expect(out).to match(/Your application has set foo to "local"/) + + run "puts Bundler.settings[:foo]" + expect(out).to eq("local") + end + + it "has lower precedence than env" do + begin + ENV["BUNDLE_FOO"] = "env" + + bundle "config --global foo global" + expect(out).to match(/You have a bundler environment variable for foo set to "env"/) + + run "puts Bundler.settings[:foo]" + expect(out).to eq("env") + ensure + ENV.delete("BUNDLE_FOO") + end + end + + it "can be deleted" do + bundle "config --global foo global" + bundle "config --delete foo" + + run "puts Bundler.settings[:foo] == nil" + expect(out).to eq("true") + end + + it "warns when overriding" do + bundle "config --global foo previous" + bundle "config --global foo global" + expect(out).to match(/You are replacing the current global value of foo/) + + run "puts Bundler.settings[:foo]" + expect(out).to eq("global") + end + + it "expands the path at time of setting" do + bundle "config --global local.foo .." + run "puts Bundler.settings['local.foo']" + expect(out).to eq(File.expand_path(Dir.pwd + "/..")) + end + end + + describe "local" do + before(:each) { bundle :install } + + it "can also be set explicitly" do + bundle "config --local foo local" + run "puts Bundler.settings[:foo]" + expect(out).to eq("local") + end + + it "has higher precedence than env" do + begin + ENV["BUNDLE_FOO"] = "env" + bundle "config --local foo local" + + run "puts Bundler.settings[:foo]" + expect(out).to eq("local") + ensure + ENV.delete("BUNDLE_FOO") + end + end + + it "can be deleted" do + bundle "config --local foo local" + bundle "config --delete foo" + + run "puts Bundler.settings[:foo] == nil" + expect(out).to eq("true") + end + + it "warns when overriding" do + bundle "config --local foo previous" + bundle "config --local foo local" + expect(out).to match(/You are replacing the current local value of foo/) + + run "puts Bundler.settings[:foo]" + expect(out).to eq("local") + end + + it "expands the path at time of setting" do + bundle "config --local local.foo .." + run "puts Bundler.settings['local.foo']" + expect(out).to eq(File.expand_path(Dir.pwd + "/..")) + end + end + + describe "env" do + before(:each) { bundle :install } + + it "can set boolean properties via the environment" do + ENV["BUNDLE_FROZEN"] = "true" + + run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end" + expect(out).to eq("true") + end + + it "can set negative boolean properties via the environment" do + run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end" + expect(out).to eq("false") + + ENV["BUNDLE_FROZEN"] = "false" + + run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end" + expect(out).to eq("false") + + ENV["BUNDLE_FROZEN"] = "0" + + run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end" + expect(out).to eq("false") + + ENV["BUNDLE_FROZEN"] = "" + + run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end" + expect(out).to eq("false") + end + end +end diff --git a/spec/commands/console_spec.rb b/spec/commands/console_spec.rb new file mode 100644 index 0000000000..b72883a01c --- /dev/null +++ b/spec/commands/console_spec.rb @@ -0,0 +1,54 @@ +require "spec_helper" + +describe "bundle console" do + before :each do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "activesupport", :group => :test + gem "rack_middleware", :group => :development + G + end + + it "starts IRB with the default group loaded" do + bundle "console" do |input| + input.puts("puts RACK") + input.puts("exit") + end + expect(out).to include("0.9.1") + end + + it "doesn't load any other groups" do + bundle "console" do |input| + input.puts("puts ACTIVESUPPORT") + input.puts("exit") + end + expect(out).to include("NameError") + end + + describe "when given a group" do + it "loads the given group" do + bundle "console test" do |input| + input.puts("puts ACTIVESUPPORT") + input.puts("exit") + end + expect(out).to include("2.3.5") + end + + it "loads the default group" do + bundle "console test" do |input| + input.puts("puts RACK") + input.puts("exit") + end + expect(out).to include("0.9.1") + end + + it "doesn't load other groups" do + bundle "console test" do |input| + input.puts("puts RACK_MIDDLEWARE") + input.puts("exit") + end + expect(out).to include("NameError") + end + end +end diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb new file mode 100644 index 0000000000..ed03e2b0a9 --- /dev/null +++ b/spec/commands/exec_spec.rb @@ -0,0 +1,270 @@ +require "spec_helper" + +describe "bundle exec" do + before :each do + system_gems "rack-1.0.0", "rack-0.9.1" + end + + it "activates the correct gem" do + gemfile <<-G + gem "rack", "0.9.1" + G + + bundle "exec rackup" + expect(out).to eq("0.9.1") + end + + it "works when the bins are in ~/.bundle" do + install_gemfile <<-G + gem "rack" + G + + bundle "exec rackup" + expect(out).to eq("1.0.0") + end + + it "works when running from a random directory" do + install_gemfile <<-G + gem "rack" + G + + bundle "exec 'cd #{tmp('gems')} && rackup'" + + expect(out).to eq("1.0.0") + end + + it "works when exec'ing something else" do + install_gemfile 'gem "rack"' + bundle "exec echo exec" + expect(out).to eq("exec") + end + + it "works when exec'ing to ruby" do + install_gemfile 'gem "rack"' + bundle "exec ruby -e 'puts %{hi}'" + expect(out).to eq("hi") + end + + it "accepts --verbose" do + install_gemfile 'gem "rack"' + bundle "exec --verbose echo foobar" + expect(out).to eq("foobar") + end + + it "passes --verbose to command if it is given after the command" do + install_gemfile 'gem "rack"' + bundle "exec echo --verbose" + expect(out).to eq("--verbose") + end + + it "can run a command named --verbose" do + install_gemfile 'gem "rack"' + File.open("--verbose", 'w') do |f| + f.puts "#!/bin/sh" + f.puts "echo foobar" + end + File.chmod(0744, "--verbose") + ENV['PATH'] = "." + bundle "exec -- --verbose" + expect(out).to eq("foobar") + end + + it "handles different versions in different bundles" do + build_repo2 do + build_gem "rack_two", "1.0.0" do |s| + s.executables = "rackup" + end + end + + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", "0.9.1" + G + + Dir.chdir bundled_app2 do + install_gemfile bundled_app2('Gemfile'), <<-G + source "file://#{gem_repo2}" + gem "rack_two", "1.0.0" + G + end + + bundle "exec rackup" + + expect(out).to eq("0.9.1") + + Dir.chdir bundled_app2 do + bundle "exec rackup" + expect(out).to eq("1.0.0") + end + end + + it "handles gems installed with --without" do + install_gemfile <<-G, :without => :middleware + source "file://#{gem_repo1}" + gem "rack" # rack 0.9.1 and 1.0 exist + + group :middleware do + gem "rack_middleware" # rack_middleware depends on rack 0.9.1 + end + G + + bundle "exec rackup" + + expect(out).to eq("0.9.1") + should_not_be_installed "rack_middleware 1.0" + end + + it "does not duplicate already exec'ed RUBYOPT" do + install_gemfile <<-G + gem "rack" + G + + rubyopt = ENV['RUBYOPT'] + rubyopt = "-rbundler/setup #{rubyopt}" + + bundle "exec 'echo $RUBYOPT'" + expect(out).to have_rubyopts(rubyopt) + + bundle "exec 'echo $RUBYOPT'", :env => {"RUBYOPT" => rubyopt} + expect(out).to have_rubyopts(rubyopt) + end + + it "does not duplicate already exec'ed RUBYLIB" do + install_gemfile <<-G + gem "rack" + G + + rubylib = ENV['RUBYLIB'] + rubylib = "#{rubylib}".split(File::PATH_SEPARATOR).unshift "#{bundler_path}" + rubylib = rubylib.uniq.join(File::PATH_SEPARATOR) + + bundle "exec 'echo $RUBYLIB'" + expect(out).to eq(rubylib) + + bundle "exec 'echo $RUBYLIB'", :env => {"RUBYLIB" => rubylib} + expect(out).to eq(rubylib) + end + + it "errors nicely when the argument doesn't exist" do + install_gemfile <<-G + gem "rack" + G + + bundle "exec foobarbaz", :exitstatus => true + expect(exitstatus).to eq(127) + expect(out).to include("bundler: command not found: foobarbaz") + expect(out).to include("Install missing gem executables with `bundle install`") + end + + it "errors nicely when the argument is not executable" do + install_gemfile <<-G + gem "rack" + G + + bundle "exec touch foo" + bundle "exec ./foo", :exitstatus => true + expect(exitstatus).to eq(126) + expect(out).to include("bundler: not executable: ./foo") + end + + it "errors nicely when no arguments are passed" do + install_gemfile <<-G + gem "rack" + G + + bundle "exec", :exitstatus => true + expect(exitstatus).to eq(128) + expect(out).to include("bundler: exec needs a command to run") + end + + describe "with gem executables" do + describe "run from a random directory" do + before(:each) do + install_gemfile <<-G + gem "rack" + G + end + + it "works when unlocked" do + bundle "exec 'cd #{tmp('gems')} && rackup'" + expect(out).to eq("1.0.0") + end + + it "works when locked" do + should_be_locked + bundle "exec 'cd #{tmp('gems')} && rackup'" + expect(out).to eq("1.0.0") + end + end + + describe "from gems bundled via :path" do + before(:each) do + build_lib "fizz", :path => home("fizz") do |s| + s.executables = "fizz" + end + + install_gemfile <<-G + gem "fizz", :path => "#{File.expand_path(home("fizz"))}" + G + end + + it "works when unlocked" do + bundle "exec fizz" + expect(out).to eq("1.0") + end + + it "works when locked" do + should_be_locked + + bundle "exec fizz" + expect(out).to eq("1.0") + end + end + + describe "from gems bundled via :git" do + before(:each) do + build_git "fizz_git" do |s| + s.executables = "fizz_git" + end + + install_gemfile <<-G + gem "fizz_git", :git => "#{lib_path('fizz_git-1.0')}" + G + end + + it "works when unlocked" do + bundle "exec fizz_git" + expect(out).to eq("1.0") + end + + it "works when locked" do + should_be_locked + bundle "exec fizz_git" + expect(out).to eq("1.0") + end + end + + describe "from gems bundled via :git with no gemspec" do + before(:each) do + build_git "fizz_no_gemspec", :gemspec => false do |s| + s.executables = "fizz_no_gemspec" + end + + install_gemfile <<-G + gem "fizz_no_gemspec", "1.0", :git => "#{lib_path('fizz_no_gemspec-1.0')}" + G + end + + it "works when unlocked" do + bundle "exec fizz_no_gemspec" + expect(out).to eq("1.0") + end + + it "works when locked" do + should_be_locked + bundle "exec fizz_no_gemspec" + expect(out).to eq("1.0") + end + end + end +end diff --git a/spec/commands/help_spec.rb b/spec/commands/help_spec.rb new file mode 100644 index 0000000000..739f62224e --- /dev/null +++ b/spec/commands/help_spec.rb @@ -0,0 +1,39 @@ +require "spec_helper" + +describe "bundle help" do + # Rubygems 1.4+ no longer load gem plugins so this test is no longer needed + rubygems_under_14 = Gem::Requirement.new("< 1.4").satisfied_by?(Gem::Version.new(Gem::VERSION)) + it "complains if older versions of bundler are installed", :if => rubygems_under_14 do + system_gems "bundler-0.8.1" + + bundle "help", :expect_err => true + expect(err).to include("older than 0.9") + expect(err).to include("running `gem cleanup bundler`.") + end + + it "uses mann when available" do + fake_man! + + bundle "help gemfile" + expect(out).to eq(%|["#{root}/lib/bundler/man/gemfile.5"]|) + end + + it "prefixes bundle commands with bundle- when finding the groff files" do + fake_man! + + bundle "help install" + expect(out).to eq(%|["#{root}/lib/bundler/man/bundle-install"]|) + end + + it "simply outputs the txt file when there is no man on the path" do + kill_path! + + bundle "help install", :expect_err => true + expect(out).to match(/BUNDLE-INSTALL/) + end + + it "still outputs the old help for commands that do not have man pages yet" do + bundle "help check" + expect(out).to include("Check searches the local machine") + end +end diff --git a/spec/commands/init_spec.rb b/spec/commands/init_spec.rb new file mode 100644 index 0000000000..8bd566dcf5 --- /dev/null +++ b/spec/commands/init_spec.rb @@ -0,0 +1,39 @@ +require "spec_helper" + +describe "bundle init" do + it "generates a Gemfile" do + bundle :init + expect(bundled_app("Gemfile")).to exist + end + + it "does not change existing Gemfiles" do + gemfile <<-G + gem "rails" + G + + expect { + bundle :init + }.not_to change { File.read(bundled_app("Gemfile")) } + end + + it "should generate from an existing gemspec" do + spec_file = tmp.join('test.gemspec') + File.open(spec_file, 'w') do |file| + file << <<-S + Gem::Specification.new do |s| + s.name = 'test' + s.add_dependency 'rack', '= 1.0.1' + s.add_development_dependency 'rspec', '1.2' + end + S + end + + bundle :init, :gemspec => spec_file + + gemfile = bundled_app("Gemfile").read + expect(gemfile).to match(/source :gemcutter/) + expect(gemfile.scan(/gem "rack", "= 1.0.1"/).size).to eq(1) + expect(gemfile.scan(/gem "rspec", "= 1.2"/).size).to eq(1) + expect(gemfile.scan(/group :development/).size).to eq(1) + end +end diff --git a/spec/commands/licenses_spec.rb b/spec/commands/licenses_spec.rb new file mode 100644 index 0000000000..c8d5ff739e --- /dev/null +++ b/spec/commands/licenses_spec.rb @@ -0,0 +1,18 @@ +require "spec_helper" + +describe "bundle licenses" do + before :each do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + gem "with_license" + G + end + + it "prints license information for all gems in the bundle" do + bundle "licenses" + + expect(out).to include("actionpack: Unknown") + expect(out).to include("with_license: MIT") + end +end diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb new file mode 100644 index 0000000000..7694e94740 --- /dev/null +++ b/spec/commands/newgem_spec.rb @@ -0,0 +1,403 @@ +require "spec_helper" + +describe "bundle gem" do + before do + @git_name = `git config --global user.name`.chomp + `git config --global user.name "Bundler User"` + @git_email = `git config --global user.email`.chomp + `git config --global user.email user@example.com` + end + + after do + `git config --global user.name "#{@git_name}"` + `git config --global user.email #{@git_email}` + end + + shared_examples_for "git config is present" do + context "git config user.{name,email} present" do + it "sets gemspec author to git user.name if available" do + expect(generated_gem.gemspec.authors.first).to eq("Bundler User") + end + + it "sets gemspec email to git user.email if available" do + expect(generated_gem.gemspec.email.first).to eq("user@example.com") + end + end + end + + shared_examples_for "git config is absent" do |hoge| + it "sets gemspec author to default message if git user.name is not set or empty" do + expect(generated_gem.gemspec.authors.first).to eq("TODO: Write your name") + end + + it "sets gemspec email to default message if git user.email is not set or empty" do + expect(generated_gem.gemspec.email.first).to eq("TODO: Write your email address") + end + end + + context "gem naming with underscore" do + let(:gem_name) { 'test_gem' } + + before do + bundle "gem #{gem_name}" + # reset gemspec cache for each test because of commit 3d4163a + Bundler.clear_gemspec_cache + end + + let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) } + + it "generates a gem skeleton" do + expect(bundled_app("test_gem/test_gem.gemspec")).to exist + expect(bundled_app("test_gem/LICENSE.txt")).to exist + expect(bundled_app("test_gem/Gemfile")).to exist + expect(bundled_app("test_gem/Rakefile")).to exist + expect(bundled_app("test_gem/lib/test_gem.rb")).to exist + expect(bundled_app("test_gem/lib/test_gem/version.rb")).to exist + end + + it "starts with version 0.0.1" do + expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/VERSION = "0.0.1"/) + end + + it "does not nest constants" do + expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/module TestGem/) + expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/module TestGem/) + end + + it_should_behave_like "git config is present" + + context "git config user.{name,email} is not set" do + before do + `git config --global --unset user.name` + `git config --global --unset user.email` + reset! + in_app_root + bundle "gem #{gem_name}" + end + + it_should_behave_like "git config is absent" + end + + it "sets gemspec license to MIT by default" do + expect(generated_gem.gemspec.license).to eq("MIT") + end + + it "requires the version file" do + expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/require "test_gem\/version"/) + end + + it "runs rake without problems" do + system_gems ["rake-10.0.2"] + + rakefile = strip_whitespace <<-RAKEFILE + task :default do + puts 'SUCCESS' + end + RAKEFILE + File.open(bundled_app("test_gem/Rakefile"), 'w') do |file| + file.puts rakefile + end + + Dir.chdir(bundled_app(gem_name)) do + sys_exec("rake") + expect(out).to include("SUCCESS") + end + end + + context "--bin parameter set" do + before do + reset! + in_app_root + bundle "gem #{gem_name} --bin" + end + + it "builds bin skeleton" do + expect(bundled_app("test_gem/bin/test_gem")).to exist + end + + it "requires 'test-gem'" do + expect(bundled_app("test_gem/bin/test_gem").read).to match(/require 'test_gem'/) + end + end + + context "no --test parameter" do + before do + reset! + in_app_root + bundle "gem #{gem_name}" + end + + it "doesn't create any spec/test file" do + expect(bundled_app("test_gem/.rspec")).to_not exist + expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to_not exist + expect(bundled_app("test_gem/spec/spec_helper.rb")).to_not exist + expect(bundled_app("test_gem/test/test_test_gem.rb")).to_not exist + expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist + end + end + + context "--test parameter set to rspec" do + before do + reset! + in_app_root + bundle "gem #{gem_name} --test=rspec" + end + + it "builds spec skeleton" do + expect(bundled_app("test_gem/.rspec")).to exist + expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to exist + expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist + end + + it "requires 'test-gem'" do + expect(bundled_app("test_gem/spec/spec_helper.rb").read).to match(/require 'test_gem'/) + end + + it "creates a default test which fails" do + expect(bundled_app("test_gem/spec/test_gem_spec.rb").read).to match(/false.should be_true/) + end + end + + context "--test parameter set to minitest" do + before do + reset! + in_app_root + bundle "gem #{gem_name} --test=minitest" + end + + it "builds spec skeleton" do + expect(bundled_app("test_gem/test/test_test_gem.rb")).to exist + expect(bundled_app("test_gem/test/minitest_helper.rb")).to exist + end + + it "requires 'test-gem'" do + expect(bundled_app("test_gem/test/minitest_helper.rb").read).to match(/require 'test_gem'/) + end + + it "requires 'minitest_helper'" do + expect(bundled_app("test_gem/test/test_test_gem.rb").read).to match(/require 'minitest_helper'/) + end + + it "creates a default test which fails" do + expect(bundled_app("test_gem/test/test_test_gem.rb").read).to match(/assert false/) + end + end + + context "--test with no arguments" do + before do + reset! + in_app_root + bundle "gem #{gem_name} --test" + end + + it "defaults to rspec" do + expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist + expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist + end + + it "creates a .travis.yml file to test the library against the current Ruby version on Travis CI" do + expect(bundled_app("test_gem/.travis.yml").read).to match(%r(- #{RUBY_VERSION})) + end + end + + context "--edit option" do + it "opens the generated gemspec in the user's text editor" do + reset! + in_app_root + output = bundle "gem #{gem_name} --edit=echo" + gemspec_path = File.join(Dir.pwd, gem_name, "#{gem_name}.gemspec") + expect(output).to include("echo \"#{gemspec_path}\"") + end + end + end + + context "gem naming with dashed" do + let(:gem_name) { 'test-gem' } + + before do + bundle "gem #{gem_name}" + # reset gemspec cache for each test because of commit 3d4163a + Bundler.clear_gemspec_cache + end + + let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) } + + it "generates a gem skeleton" do + expect(bundled_app("test-gem/test-gem.gemspec")).to exist + expect(bundled_app("test-gem/LICENSE.txt")).to exist + expect(bundled_app("test-gem/Gemfile")).to exist + expect(bundled_app("test-gem/Rakefile")).to exist + expect(bundled_app("test-gem/lib/test/gem.rb")).to exist + expect(bundled_app("test-gem/lib/test/gem/version.rb")).to exist + end + + it "starts with version 0.0.1" do + expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/VERSION = "0.0.1"/) + end + + it "nests constants so they work" do + expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/module Test\n module Gem/) + expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(/module Test\n module Gem/) + end + + it_should_behave_like "git config is present" + + context "git config user.{name,email} is not set" do + before do + `git config --global --unset user.name` + `git config --global --unset user.email` + reset! + in_app_root + bundle "gem #{gem_name}" + end + + it_should_behave_like "git config is absent" + end + + it "sets gemspec license to MIT by default" do + expect(generated_gem.gemspec.license).to eq("MIT") + end + + it "requires the version file" do + expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(/require "test\/gem\/version"/) + end + + it "runs rake without problems" do + system_gems ["rake-10.0.2"] + + rakefile = strip_whitespace <<-RAKEFILE + task :default do + puts 'SUCCESS' + end + RAKEFILE + File.open(bundled_app("test-gem/Rakefile"), 'w') do |file| + file.puts rakefile + end + + Dir.chdir(bundled_app(gem_name)) do + sys_exec("rake") + expect(out).to include("SUCCESS") + end + end + + context "--bin parameter set" do + before do + reset! + in_app_root + bundle "gem #{gem_name} --bin" + end + + it "builds bin skeleton" do + expect(bundled_app("test-gem/bin/test-gem")).to exist + end + + it "requires 'test/gem'" do + expect(bundled_app("test-gem/bin/test-gem").read).to match(/require 'test\/gem'/) + end + end + + context "no --test parameter" do + before do + reset! + in_app_root + bundle "gem #{gem_name}" + end + + it "doesn't create any spec/test file" do + expect(bundled_app("test-gem/.rspec")).to_not exist + expect(bundled_app("test-gem/spec/test/gem_spec.rb")).to_not exist + expect(bundled_app("test-gem/spec/spec_helper.rb")).to_not exist + expect(bundled_app("test-gem/test/test_test/gem.rb")).to_not exist + expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist + end + end + + context "--test parameter set to rspec" do + before do + reset! + in_app_root + bundle "gem #{gem_name} --test=rspec" + end + + it "builds spec skeleton" do + expect(bundled_app("test-gem/.rspec")).to exist + expect(bundled_app("test-gem/spec/test/gem_spec.rb")).to exist + expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist + end + + it "requires 'test/gem'" do + expect(bundled_app("test-gem/spec/spec_helper.rb").read).to match(/require 'test\/gem'/) + end + + it "creates a default test which fails" do + expect(bundled_app("test-gem/spec/test/gem_spec.rb").read).to match(/false.should be_true/) + end + + it "creates a default rake task to run the specs" do + rakefile = strip_whitespace <<-RAKEFILE + require "bundler/gem_tasks" + require "rspec/core/rake_task" + + RSpec::Core::RakeTask.new(:spec) + + task :default => :spec + RAKEFILE + + expect(bundled_app("test-gem/Rakefile").read).to eq(rakefile) + end + end + + context "--test parameter set to minitest" do + before do + reset! + in_app_root + bundle "gem #{gem_name} --test=minitest" + end + + it "builds spec skeleton" do + expect(bundled_app("test-gem/test/test_test/gem.rb")).to exist + expect(bundled_app("test-gem/test/minitest_helper.rb")).to exist + end + + it "requires 'test/gem'" do + expect(bundled_app("test-gem/test/minitest_helper.rb").read).to match(/require 'test\/gem'/) + end + + it "requires 'minitest_helper'" do + expect(bundled_app("test-gem/test/test_test/gem.rb").read).to match(/require 'minitest_helper'/) + end + + it "creates a default test which fails" do + expect(bundled_app("test-gem/test/test_test/gem.rb").read).to match(/assert false/) + end + + it "creates a default rake task to run the test suite" do + rakefile = strip_whitespace <<-RAKEFILE + require "bundler/gem_tasks" + require "rake/testtask" + + Rake::TestTask.new(:test) do |t| + t.libs << "test" + end + + task :default => :test + RAKEFILE + + expect(bundled_app("test-gem/Rakefile").read).to eq(rakefile) + end + end + + context "--test with no arguments" do + before do + reset! + in_app_root + bundle "gem #{gem_name} --test" + end + + it "defaults to rspec" do + expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist + expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist + end + end + end +end diff --git a/spec/commands/open_spec.rb b/spec/commands/open_spec.rb new file mode 100644 index 0000000000..b586376254 --- /dev/null +++ b/spec/commands/open_spec.rb @@ -0,0 +1,55 @@ +require "spec_helper" + +describe "bundle open" do + before :each do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + end + + it "opens the gem with BUNDLER_EDITOR as highest priority" do + bundle "open rails", :env => {"EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor"} + expect(out).to eq("bundler_editor #{default_bundle_path('gems', 'rails-2.3.2')}") + end + + it "opens the gem with VISUAL as 2nd highest priority" do + bundle "open rails", :env => {"EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => ""} + expect(out).to eq("visual #{default_bundle_path('gems', 'rails-2.3.2')}") + end + + it "opens the gem with EDITOR as 3rd highest priority" do + bundle "open rails", :env => {"EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => ""} + expect(out).to eq("editor #{default_bundle_path('gems', 'rails-2.3.2')}") + end + + it "complains if no EDITOR is set" do + bundle "open rails", :env => {"EDITOR" => "", "VISUAL" => "", "BUNDLER_EDITOR" => ""} + expect(out).to eq("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR") + end + + it "complains if gem not in bundle" do + bundle "open missing", :env => {"EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => ""} + expect(out).to match(/could not find gem 'missing'/i) + end + + it "suggests alternatives for similar-sounding gems" do + bundle "open Rails", :env => {"EDITOR" => "echo editor", "VISUAL" => "", "BUNDLER_EDITOR" => ""} + expect(out).to match(/did you mean rails\?/i) + end + + it "opens the gem with short words" do + bundle "open rec" , :env => {"EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor"} + + expect(out).to eq("bundler_editor #{default_bundle_path('gems', 'activerecord-2.3.2')}") + end + + it "select the gem from many match gems" do + env = {"EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor"} + bundle "open active" , :env => env do |input| + input.puts '2' + end + + expect(out).to match(/bundler_editor #{default_bundle_path('gems', 'activerecord-2.3.2')}\z/) + end +end diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb new file mode 100644 index 0000000000..b498510ff7 --- /dev/null +++ b/spec/commands/outdated_spec.rb @@ -0,0 +1,116 @@ +require "spec_helper" + +describe "bundle outdated" do + before :each do + build_repo2 do + build_git "foo", :path => lib_path("foo") + build_git "zebra", :path => lib_path("zebra") + end + + install_gemfile <<-G + source "file://#{gem_repo2}" + gem "zebra", :git => "#{lib_path('zebra')}" + gem "foo", :git => "#{lib_path('foo')}" + gem "activesupport", "2.3.5" + G + end + + describe "with no arguments" do + it "returns a sorted list of outdated gems" do + update_repo2 do + build_gem "activesupport", "3.0" + update_git "foo", :path => lib_path("foo") + update_git "zebra", :path => lib_path("zebra") + end + + bundle "outdated" + + expect(out).to include("activesupport (3.0 > 2.3.5) Gemfile specifies \"= 2.3.5\"") + expect(out).to include("foo (1.0") + + # Gem names are one per-line, between "*" and their parenthesized version. + gem_list = out.split("\n").map { |g| g[ /\* (.*) \(/, 1] }.compact + expect(gem_list).to eq(gem_list.sort) + end + + it "returns non zero exit status if outdated gems present" do + update_repo2 do + build_gem "activesupport", "3.0" + update_git "foo", :path => lib_path("foo") + end + + bundle "outdated", :exitstatus => true + + expect(exitstatus).to_not be_zero + end + + it "returns success exit status if no outdated gems present" do + bundle "outdated", :exitstatus => true + + expect(exitstatus).to be_zero + end + end + + describe "with --local option" do + it "doesn't hit repo2" do + FileUtils.rm_rf(gem_repo2) + + bundle "outdated --local" + expect(out).not_to match(/Fetching/) + end + end + + describe "with specified gems" do + it "returns list of outdated gems" do + update_repo2 do + build_gem "activesupport", "3.0" + update_git "foo", :path => lib_path("foo") + end + + bundle "outdated foo" + expect(out).not_to include("activesupport (3.0 > 2.3.5)") + expect(out).to include("foo (1.0") + end + end + + describe "pre-release gems" do + context "without the --pre option" do + it "ignores pre-release versions" do + update_repo2 do + build_gem "activesupport", "3.0.0.beta" + end + + bundle "outdated" + expect(out).not_to include("activesupport (3.0.0.beta > 2.3.5)") + end + end + + context "with the --pre option" do + it "includes pre-release versions" do + update_repo2 do + build_gem "activesupport", "3.0.0.beta" + end + + bundle "outdated --pre" + expect(out).to include("activesupport (3.0.0.beta > 2.3.5) Gemfile specifies \"= 2.3.5\"") + end + end + + context "when current gem is a pre-release" do + it "includes the gem" do + update_repo2 do + build_gem "activesupport", "3.0.0.beta.1" + build_gem "activesupport", "3.0.0.beta.2" + end + + install_gemfile <<-G + source "file://#{gem_repo2}" + gem "activesupport", "3.0.0.beta.1" + G + + bundle "outdated" + expect(out).to include("activesupport (3.0.0.beta.2 > 3.0.0.beta.1) Gemfile specifies \"= 3.0.0.beta.1\"") + end + end + end +end diff --git a/spec/commands/show_spec.rb b/spec/commands/show_spec.rb new file mode 100644 index 0000000000..bdd3a1f6a2 --- /dev/null +++ b/spec/commands/show_spec.rb @@ -0,0 +1,102 @@ +require "spec_helper" + +describe "bundle show" do + before :each do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + end + + it "creates a Gemfile.lock if one did not exist" do + FileUtils.rm("Gemfile.lock") + + bundle "show" + + expect(bundled_app("Gemfile.lock")).to exist + end + + it "creates a Gemfile.lock when invoked with a gem name" do + FileUtils.rm("Gemfile.lock") + + bundle "show rails" + + expect(bundled_app("Gemfile.lock")).to exist + end + + it "prints path if gem exists in bundle" do + bundle "show rails" + expect(out).to eq(default_bundle_path('gems', 'rails-2.3.2').to_s) + end + + it "warns if path no longer exists on disk" do + FileUtils.rm_rf("#{system_gem_path}/gems/rails-2.3.2") + + bundle "show rails" + + expect(out).to match(/has been deleted/i) + expect(out).to include(default_bundle_path('gems', 'rails-2.3.2').to_s) + end + + it "prints the path to the running bundler" do + bundle "show bundler" + expect(out).to eq(File.expand_path('../../../', __FILE__)) + end + + it "complains if gem not in bundle" do + bundle "show missing" + expect(out).to match(/could not find gem 'missing'/i) + end + + it "prints path of all gems in bundle sorted by name" do + bundle "show --paths" + + expect(out).to include(default_bundle_path('gems', 'rake-10.0.2').to_s) + expect(out).to include(default_bundle_path('gems', 'rails-2.3.2').to_s) + + # Gem names are the last component of their path. + gem_list = out.split.map { |p| p.split('/').last } + expect(gem_list).to eq(gem_list.sort) + end +end + +describe "bundle show with a git repo" do + before :each do + @git = build_git "foo", "1.0" + end + + it "prints out git info" do + install_gemfile <<-G + gem "foo", :git => "#{lib_path('foo-1.0')}" + G + should_be_installed "foo 1.0" + + bundle :show + expect(out).to include("foo (1.0 #{@git.ref_for('master', 6)}") + end + + it "prints out branch names other than master" do + update_git "foo", :branch => "omg" do |s| + s.write "lib/foo.rb", "FOO = '1.0.omg'" + end + @revision = revision_for(lib_path("foo-1.0"))[0...6] + + install_gemfile <<-G + gem "foo", :git => "#{lib_path('foo-1.0')}", :branch => "omg" + G + should_be_installed "foo 1.0.omg" + + bundle :show + expect(out).to include("foo (1.0 #{@git.ref_for('omg', 6)}") + end + + it "doesn't print the branch when tied to a ref" do + sha = revision_for(lib_path("foo-1.0")) + install_gemfile <<-G + gem "foo", :git => "#{lib_path('foo-1.0')}", :ref => "#{sha}" + G + + bundle :show + expect(out).to include("foo (1.0 #{sha[0..6]})") + end +end |