summaryrefslogtreecommitdiff
path: root/spec/bundler/commands/pristine_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/commands/pristine_spec.rb')
-rw-r--r--spec/bundler/commands/pristine_spec.rb56
1 files changed, 50 insertions, 6 deletions
diff --git a/spec/bundler/commands/pristine_spec.rb b/spec/bundler/commands/pristine_spec.rb
index 3aca313e0f..ee75934380 100644
--- a/spec/bundler/commands/pristine_spec.rb
+++ b/spec/bundler/commands/pristine_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require "spec_helper"
-require "fileutils"
+
+require "bundler/vendored_fileutils"
RSpec.describe "bundle pristine", :ruby_repo do
before :each do
@@ -28,7 +28,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
G
end
- context "when sourced from Rubygems" do
+ 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")
@@ -55,12 +55,23 @@ RSpec.describe "bundle pristine", :ruby_repo do
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" }
+ File.open(changed_file, "a") {|f| f.puts diff }
expect(File.read(changed_file)).to include(diff)
- bundle "pristine"
+ bundle! "pristine"
expect(File.read(changed_file)).to_not include(diff)
end
+
+ it "removes added files" do
+ spec = Bundler.definition.specs["foo"].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).not_to be_file
+ end
end
context "when sourced from gemspec" do
@@ -69,7 +80,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
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" }
+ File.open(changed_file, "a") {|f| f.puts diff }
expect(File.read(changed_file)).to include(diff)
bundle "pristine"
@@ -102,6 +113,39 @@ RSpec.describe "bundle pristine", :ruby_repo do
end
end
+ context "when passing a list of gems to pristine" do
+ it "resets them" do
+ foo = Bundler.definition.specs["foo"].first
+ foo_changes_txt = Pathname.new(foo.full_gem_path).join("lib/changes.txt")
+ FileUtils.touch(foo_changes_txt)
+ expect(foo_changes_txt).to be_file
+
+ bar = Bundler.definition.specs["bar"].first
+ bar_changes_txt = Pathname.new(bar.full_gem_path).join("lib/changes.txt")
+ FileUtils.touch(bar_changes_txt)
+ expect(bar_changes_txt).to be_file
+
+ weakling = Bundler.definition.specs["weakling"].first
+ weakling_changes_txt = Pathname.new(weakling.full_gem_path).join("lib/changes.txt")
+ FileUtils.touch(weakling_changes_txt)
+ expect(weakling_changes_txt).to be_file
+
+ bundle! "pristine foo bar weakling"
+
+ expect(out).to include("Cannot pristine bar (1.0). Gem is sourced from local path.").
+ and include("Installing weakling 1.0")
+
+ expect(weakling_changes_txt).not_to be_file
+ expect(foo_changes_txt).not_to be_file
+ expect(bar_changes_txt).to be_file
+ end
+
+ it "raises when one of them is not in the lockfile" do
+ bundle "pristine abcabcabc"
+ expect(out).to include("Could not find gem 'abcabcabc'.")
+ end
+ end
+
context "when a build config exists for one of the gems" do
let(:very_simple_binary) { Bundler.definition.specs["very_simple_binary"].first }
let(:c_ext_dir) { Pathname.new(very_simple_binary.full_gem_path).join("ext") }