diff options
author | Dennis Suratna <dennis.suratna@gmail.com> | 2017-03-06 18:37:22 -0800 |
---|---|---|
committer | Dennis Suratna <dennis.suratna@gmail.com> | 2017-04-11 18:33:29 +0700 |
commit | 03bfeaaf842210519a9b057d2e0475daa60d7090 (patch) | |
tree | 652a13835c45fec3dbdcb8472f3d669c116ea270 | |
parent | cebcfee68f9814bb39eb8317756fa3f00b10591a (diff) | |
download | bundler-03bfeaaf842210519a9b057d2e0475daa60d7090.tar.gz |
Add more specs and handle git source
-rw-r--r-- | lib/bundler/cli/pristine.rb | 21 | ||||
-rw-r--r-- | spec/commands/pristine_spec.rb | 49 |
2 files changed, 41 insertions, 29 deletions
diff --git a/lib/bundler/cli/pristine.rb b/lib/bundler/cli/pristine.rb index 539e38f2ff..64772c70d2 100644 --- a/lib/bundler/cli/pristine.rb +++ b/lib/bundler/cli/pristine.rb @@ -9,30 +9,29 @@ module Bundler gem_name = "#{spec.name} (#{spec.version}#{spec.git_version})" - if spec.source.is_a?(Source::Path) + if spec.source.instance_of? Source::Path ::Bundler.ui.warn("Cannot pristine #{gem_name} Gem is sourced from path.") next end - if spec.source.is_a?(Source::Rubygems) + if spec.source.instance_of? Source::Rubygems cached_gem = spec.cache_file unless File.exists?(cached_gem) + # TODO: Refetch from ruby gem? ::Bundler.ui.error("Failed to pristine #{gem_name}. Cached gem #{cached_gem} does not exist.") next end - installer = Gem::Installer.at(cached_gem, - :wrappers => true, - :force => true, - :install_dir => spec.base_dir, - :build_args => spec.build_args) - installer.install - - elsif spec.source.is_a?(Source::Git) + Gem::Installer.at(cached_gem, + :wrappers => true, + :force => true, + :install_dir => spec.base_dir, + :build_args => spec.build_args).install + elsif spec.source.instance_of? Source::Git + `git -C "#{spec.full_gem_path}" checkout --force` end - end end end diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb index 0a546a14a6..ec44b68930 100644 --- a/spec/commands/pristine_spec.rb +++ b/spec/commands/pristine_spec.rb @@ -7,44 +7,57 @@ RSpec.describe "bundle pristine" do build_repo2 do build_gem "weakling" build_git "foo", :path => lib_path("foo") - build_lib "bar", :path => lib_path("foo") + build_lib "bar", :path => lib_path("bar") end install_gemfile <<-G source "file://#{gem_repo2}" gem "weakling" gem "foo", :git => "#{lib_path("foo")}" - gem "bar", :path => "#{lib_path("foo")}" + gem "bar", :path => "#{lib_path("bar")}" G bundle "install" end - it "reverts gem sourced from Rubygems to its cached .gem file" do + context "when sourced from Rubygems" do + it "reverts using cached .gem file" do - spec = Bundler.definition.specs["weakling"].first - changes_txt = "#{spec.full_gem_path}/lib/changes.txt" - expect(File.exist?(changes_txt)).to be_falsey - expect(File.exist?(spec.cache_file)).to be_truthy + spec = Bundler.definition.specs["weakling"].first + changes_txt = "#{spec.full_gem_path}/lib/changes.txt" - FileUtils.touch(changes_txt) + FileUtils.touch(changes_txt) + expect(File.exist?(changes_txt)).to be_truthy - expect(File.exist?(changes_txt)).to be_truthy + bundle "pristine" + expect(File.exist?(changes_txt)).to be_falsey - bundle "pristine" - - expect(File.exist?(changes_txt)).to be_falsey + end end - it "reverts gem sourced from Git by issuing `git checkout --force`" do + context "when sourced from git repo" do + it "reverts by issuing `git checkout --force`" do - spec = Bundler.definition.specs["foo"].first + spec = Bundler.definition.specs["foo"].first + changed_file = "#{spec.full_gem_path}/lib/foo.rb" - end + `echo '#Pristine spec changes' >> #{changed_file}` + expect(File.read(changed_file)).to include('#Pristine spec changes') - it "ignores gem sourced from local path" do - - spec = Bundler.definition.specs["bar"].first + bundle "pristine" + expect(File.read(changed_file)).to_not include('#Pristine spec changes') + end end + + # context "when sourced from path" do + # it "ignores and warns sourced from local path" do + # + # spec = Bundler.definition.specs["bar"].first + # expect(Bundler.ui).to receive(:warn).with("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}) Gem is sourced from path.") + # bundle "pristine" + # + # end + # end + end |