diff options
author | The Bundler Bot <bot@bundler.io> | 2017-04-11 23:33:20 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-04-11 23:33:20 +0000 |
commit | fac4b7b519039199581b9d5eb62ed6ba31b247b3 (patch) | |
tree | 818f660062d7fd88782582382155cafec63ddfb6 /spec | |
parent | 9f3cac0d05a40ca37a865d7ada66bbe5f8b3427b (diff) | |
parent | d7adcaa9e42973ee75f23f28280aed16e806c620 (diff) | |
download | bundler-fac4b7b519039199581b9d5eb62ed6ba31b247b3.tar.gz |
Auto merge of #5503 - denniss:ds-bundle-pristine, r=segiddins
Implementation of `bundle pristine`
Initial implementation of bundle pristine
Addressing:
https://github.com/bundler/bundler/issues/4509
https://github.com/bundler/bundler-features/issues/5
Diffstat (limited to 'spec')
-rw-r--r-- | spec/commands/pristine_spec.rb | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb new file mode 100644 index 0000000000..ff327e190b --- /dev/null +++ b/spec/commands/pristine_spec.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true +require "spec_helper" +require "fileutils" + +RSpec.describe "bundle pristine" do + before :each do + build_lib "baz", :path => bundled_app do |s| + s.version = "1.0.0" + s.add_development_dependency "baz-dev", "=1.0.0" + end + + build_repo2 do + build_gem "weakling" + build_gem "baz-dev", "1.0.0" + build_git "foo", :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("bar")}" + + gemspec + G + + bundle "install" + end + + context "when sourced from Rubygems" do + it "reverts using cached .gem file" do + spec = Bundler.definition.specs["weakling"].first + changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt") + + FileUtils.touch(changes_txt) + expect(changes_txt).to be_file + + bundle "pristine" + expect(changes_txt).to_not be_file + end + end + + context "when sourced from git repo" do + it "reverts by resetting to current revision`" do + spec = Bundler.definition.specs["foo"].first + changed_file = Pathname.new(spec.full_gem_path).join("lib/foo.rb") + diff = "#Pristine spec changes" + + File.open(changed_file, "a") {|f| f.puts "#Pristine spec changes" } + expect(File.read(changed_file)).to include(diff) + + bundle "pristine" + expect(File.read(changed_file)).to_not include(diff) + end + end + + context "when sourced from gemspec" do + it "displays warning and ignores changes when sourced from gemspec" do + spec = Bundler.definition.specs["baz"].first + changed_file = Pathname.new(spec.full_gem_path).join("lib/baz.rb") + diff = "#Pristine spec changes" + + File.open(changed_file, "a") {|f| f.puts "#Pristine spec changes" } + expect(File.read(changed_file)).to include(diff) + + bundle "pristine" + expect(File.read(changed_file)).to include(diff) + expect(out).to include("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}). Gem is sourced from local path.") + end + + it "reinstall gemspec dependency" do + spec = Bundler.definition.specs["baz-dev"].first + changed_file = Pathname.new(spec.full_gem_path).join("lib/baz-dev.rb") + diff = "#Pristine spec changes" + + File.open(changed_file, "a") {|f| f.puts "#Pristine spec changes" } + expect(File.read(changed_file)).to include(diff) + + bundle "pristine" + expect(File.read(changed_file)).to_not include(diff) + end + end + + context "when sourced from path" do + it "displays warning and ignores changes when sourced from local path" do + spec = Bundler.definition.specs["bar"].first + changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt") + FileUtils.touch(changes_txt) + expect(changes_txt).to be_file + bundle "pristine" + expect(out).to include("Cannot pristine #{spec.name} (#{spec.version}#{spec.git_version}). Gem is sourced from local path.") + expect(changes_txt).to be_file + end + end +end |