Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5800 - bundler:seg-bundler-2-specs, r=segiddins
Browse files Browse the repository at this point in the history
[2.0] Update the specs to pass under Bundler 2

### What was the end-user problem that led to this PR?

The problem was we have all these _amazing_ Bundler 2.0 features hidden behind feature flags. But we weren't testing all of bundler in that 2.0 mode.

### Was was your diagnosis of the problem?

My diagnosis was we needed to get the bundler 2 specs running, and passing!

### What is your fix for the problem, implemented in this PR?

My fix is to add a travis build entry to change `version.rb` to a 2.0 version and run the tests!

### Why did you choose this fix out of the possible options?

I chose this fix because it will completely imitate what happens once we change the version on `master`, and by keeping the test suite passing on both 1.0 and 2.0 modes, we'll be in a position to release a 1.16 to which we'll be able to (relatively easily) backport fixes that land after master switches to completely target 2.0.
  • Loading branch information
bundlerbot committed Jun 23, 2017
2 parents 82626eb + 717d194 commit a14b5c0
Show file tree
Hide file tree
Showing 49 changed files with 418 additions and 260 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: ruby
script: rake spec:travis
before_script:
- travis_retry rake spec:travis:deps
- travis_retry rake spec:travis:sub_version
- travis_retry rake man:build
- travis_retry rake spec:rubygems:clone_rubygems_$RGV

Expand Down Expand Up @@ -43,6 +44,8 @@ env:

matrix:
include:
- rvm: 2.4.1
env: RGV=v2.6.8 BUNDLER_SPEC_SUB_VERSION=2.0.0
# Ruby 2.4, Rubygems 2.6.8 and up
# Ruby 2.3, Rubygems 2.5.1 and up
- rvm: 2.2.6
Expand Down
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ begin
raise "Spec run failed, please review the log for more information"
end
end

namespace :travis do
task :sub_version do
next unless version = ENV["BUNDLER_SPEC_SUB_VERSION"]
version_file = File.expand_path("../lib/bundler/version.rb", __FILE__)
contents = File.read(version_file)
unless contents.sub!(/(^\s+VERSION\s*=\s*)"#{Gem::Version::VERSION_PATTERN}"/, %(\\1"#{version}"))
abort("Failed to change bundler version")
end
File.open(version_file, "w") {|f| f << contents }
end
end
end

rescue LoadError
Expand Down
8 changes: 6 additions & 2 deletions lib/bundler/cli/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(options)

def run
if File.exist?(gemfile)
Bundler.ui.error "#{gemfile} already exists at #{SharedHelpers.pwd}/#{gemfile}"
Bundler.ui.error "#{gemfile} already exists at #{File.expand_path(gemfile)}"
exit 1
end

Expand All @@ -35,7 +35,11 @@ def run
private

def gemfile
@gemfile ||= Bundler.feature_flag.init_gems_rb? ? "gems.rb" : "Gemfile"
@gemfile ||= begin
Bundler.default_gemfile
rescue GemfileNotFound
Bundler.feature_flag.init_gems_rb? ? "gems.rb" : "Gemfile"
end
end
end
end
7 changes: 5 additions & 2 deletions lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,12 @@ def compute_requires

def additional_base_requirements_for_resolve
return [] unless @locked_gems && Bundler.feature_flag.only_update_to_newer_versions?
dependencies_by_name = dependencies.group_by(&:name)
@locked_gems.specs.reduce({}) do |requirements, locked_spec|
dep = Gem::Dependency.new(locked_spec.name, ">= #{locked_spec.version}")
requirements[locked_spec.name] = DepProxy.new(dep, locked_spec.platform)
name = locked_spec.name
next requirements if @locked_deps[name] != dependencies_by_name[name]
dep = Gem::Dependency.new(name, ">= #{locked_spec.version}")
requirements[name] = DepProxy.new(dep, locked_spec.platform)
requirements
end.values
end
Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/source/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ def git_proxy

def fetch
git_proxy.checkout
rescue GitError
rescue GitError => e
raise unless Bundler.feature_flag.allow_offline_install?
Bundler.ui.warn "Using cached git data because of network errors"
Bundler.ui.warn "Using cached git data because of network errors:\n#{e}"
end

# no-op, since we validate when re-serializing the gemspec
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/source/git/git_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def revision
begin
@revision ||= find_local_revision
rescue GitCommandError
raise MissingGitRevisionError.new(ref, uri)
raise MissingGitRevisionError.new(ref, URICredentialsFilter.credential_filtered_uri(uri))
end

@revision
Expand Down
5 changes: 4 additions & 1 deletion lib/bundler/ui/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ def confirm(msg, newline = nil)
end

def warn(msg, newline = nil)
return unless level("warn")
return if @warning_history.include? msg
@warning_history << msg
tell_me(msg, :yellow, newline) if level("warn")

return tell_err(msg, :yellow, newline) if Bundler.feature_flag.error_on_stderr?
tell_me(msg, :yellow, newline)
end

def error(msg, newline = nil)
Expand Down
12 changes: 5 additions & 7 deletions spec/bundler/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@
context "with --verbose" do
it "prints the running command" do
bundle! "config", :verbose => true
expect(out).to start_with("Running `bundle config --verbose` with bundler #{Bundler::VERSION}")
expect(last_command.stdout).to start_with("Running `bundle config --verbose` with bundler #{Bundler::VERSION}")
end

it "doesn't print defaults" do
install_gemfile! "", :verbose => true
expect(out).to start_with("Running `bundle install --no-color --retry 0 --verbose` with bundler #{Bundler::VERSION}")
expect(last_command.stdout).to start_with("Running `bundle install --no-color --retry 0 --verbose` with bundler #{Bundler::VERSION}")
end
end

describe "printing the outdated warning" do
shared_examples_for "no warning" do
it "prints no warning" do
bundle "fail"
expect(err + out).to eq("Could not find command \"fail\".")
expect(last_command.stdboth).to eq("Could not find command \"fail\".")
end
end

Expand Down Expand Up @@ -103,10 +103,9 @@
let(:latest_version) { "2.0" }
it "prints the version warning" do
bundle "fail"
expect(err + out).to eq(<<-EOS.strip)
expect(last_command.stdout).to start_with(<<-EOS.strip)
The latest bundler is #{latest_version}, but you are currently running #{bundler_version}.
To update, run `gem install bundler`
Could not find command "fail".
EOS
end

Expand All @@ -119,10 +118,9 @@
let(:latest_version) { "2.0.0.pre.4" }
it "prints the version warning" do
bundle "fail"
expect(err + out).to eq(<<-EOS.strip)
expect(last_command.stdout).to start_with(<<-EOS.strip)
The latest bundler is #{latest_version}, but you are currently running #{bundler_version}.
To update, run `gem install bundler --pre`
Could not find command "fail".
EOS
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/bundler/friendly_errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

bundle :install, :env => { "DEBUG" => true }

expect(err).to include("Failed to load #{home(".gemrc")}")
expect(last_command.stderr).to include("Failed to load #{home(".gemrc")}")
expect(exitstatus).to eq(0) if exitstatus
end
end
Expand Down
20 changes: 18 additions & 2 deletions spec/bundler/ui/shell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@

describe "#warn" do
before { subject.level = "warn" }
it "prints to stdout" do
it "prints to stdout", :bundler => "< 2" do
expect { subject.warn("warning") }.to output("warning\n").to_stdout
end

it "prints to stderr", :bundler => "2" do
expect { subject.warn("warning") }.to output("warning\n").to_stderr
end

context "when stderr flag is enabled" do
before { Bundler.settings.temporary(:error_on_stderr => true) }
it "prints to stderr" do
expect { subject.warn("warning!") }.to output("warning!\n").to_stderr
end
end
end

describe "#debug" do
Expand All @@ -34,10 +45,15 @@

describe "#error" do
before { subject.level = "error" }
it "prints to stdout" do

it "prints to stdout", :bundler => "< 2" do
expect { subject.error("error!!!") }.to output("error!!!\n").to_stdout
end

it "prints to stderr", :bundler => "2" do
expect { subject.error("error!!!") }.to output("error!!!\n").to_stderr
end

context "when stderr flag is enabled" do
before { Bundler.settings.temporary(:error_on_stderr => true) }
it "prints to stderr" do
Expand Down
2 changes: 1 addition & 1 deletion spec/cache/gems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@

it "adds and removes when gems are updated" do
update_repo2
bundle "update"
bundle "update", :all => bundle_update_requires_all?
expect(cached_gem("rack-1.2")).to exist
expect(cached_gem("rack-1.0.0")).not_to exist
end
Expand Down
14 changes: 7 additions & 7 deletions spec/cache/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
it "runs twice without exploding" do
build_git "foo"

install_gemfile <<-G
install_gemfile! <<-G
gem "foo", :git => '#{lib_path("foo-1.0")}'
G

bundle "#{cmd} --all"
bundle "#{cmd} --all"
bundle! "#{cmd} --all"
bundle! "#{cmd} --all"

expect(err).to lack_errors
expect(last_command.stdout).to include "Updating files in vendor/cache"
FileUtils.rm_rf lib_path("foo-1.0")
expect(the_bundle).to include_gems "foo 1.0"
end
Expand All @@ -81,14 +81,14 @@
ref = git.ref_for("master", 11)
expect(ref).not_to eq(old_ref)

bundle "update"
bundle "#{cmd} --all"
bundle! "update", :all => bundle_update_requires_all?
bundle! "#{cmd} --all"

expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist
expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist

FileUtils.rm_rf lib_path("foo-1.0")
run "require 'foo'"
run! "require 'foo'"
expect(out).to eq("CACHE")
end

Expand Down
8 changes: 2 additions & 6 deletions spec/cache/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@
end

it "ensures that a successful bundle install does not delete gems for other platforms" do
bundle "install"

expect(exitstatus).to eq 0 if exitstatus
bundle! "install"

expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist
expect(bundled_app("vendor/cache/activesupport-2.3.5.gem")).to exist
end

it "ensures that a successful bundle update does not delete gems for other platforms" do
bundle "update"

expect(exitstatus).to eq 0 if exitstatus
bundle! "update", :all => bundle_update_requires_all?

expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist
expect(bundled_app("vendor/cache/activesupport-2.3.5.gem")).to exist
Expand Down
6 changes: 2 additions & 4 deletions spec/commands/check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@
3.times do
bundle :check
expect(out).to eq(last_out)
expect(err).to lack_errors
end
end

Expand Down Expand Up @@ -329,9 +328,8 @@ def lock_with(bundler_version = nil)
context "is newer" do
it "does not change the lock but warns" do
lockfile lock_with(Bundler::VERSION.succ)
bundle :check
expect(out).to include("the running version of Bundler (#{Bundler::VERSION}) is older than the version that created the lockfile (#{Bundler::VERSION.succ})")
expect(err).to lack_errors
bundle! :check
expect(last_command.bundler_err).to include("the running version of Bundler (#{Bundler::VERSION}) is older than the version that created the lockfile (#{Bundler::VERSION.succ})")
lockfile_should_be lock_with(Bundler::VERSION.succ)
end
end
Expand Down
26 changes: 13 additions & 13 deletions spec/commands/clean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ def should_not_have_gems(*gems)
gem "foo"
G

bundle "install --path vendor/bundle --no-clean"
bundle! "install --path vendor/bundle --no-clean"

gemfile <<-G
source "file://#{gem_repo1}"
gem "rack", "0.9.1"
gem "foo"
G
bundle "install"
bundle! "update rack"

bundle :clean
bundle! :clean

expect(out).to include("Removing rack (1.0.0)")

Expand Down Expand Up @@ -195,13 +195,13 @@ def should_not_have_gems(*gems)
end
G

bundle "install --path vendor/bundle"
bundle! "install --path vendor/bundle"

update_git "foo", :path => lib_path("foo-bar")
revision2 = revision_for(lib_path("foo-bar"))

bundle "update"
bundle :clean
bundle! "update", :all => bundle_update_requires_all?
bundle! :clean

expect(out).to include("Removing foo-bar (#{revision[0..11]})")

Expand Down Expand Up @@ -366,13 +366,13 @@ def should_not_have_gems(*gems)
gem "foo"
G
bundle "install --path vendor/bundle --clean"
bundle! "install --path vendor/bundle --clean"

update_repo2 do
build_gem "foo", "1.0.1"
end

bundle "update"
bundle! "update", :all => bundle_update_requires_all?

should_have_gems "foo-1.0.1"
should_not_have_gems "foo-1.0"
Expand Down Expand Up @@ -405,13 +405,13 @@ def should_not_have_gems(*gems)
gem "foo"
G
bundle "install --path vendor/bundle"
bundle! "install --path vendor/bundle"

update_repo2 do
build_gem "foo", "1.0.1"
end

bundle :update
bundle! :update, :all => bundle_update_requires_all?
should_have_gems "foo-1.0", "foo-1.0.1"
end

Expand All @@ -423,14 +423,14 @@ def should_not_have_gems(*gems)
gem "foo"
G
bundle "install"
bundle! "install"

update_repo2 do
build_gem "foo", "1.0.1"
end
bundle :update
bundle! :update, :all => bundle_update_requires_all?

sys_exec "gem list"
sys_exec! "gem list"
expect(out).to include("foo (1.0.1, 1.0)")
end

Expand Down
Loading

0 comments on commit a14b5c0

Please sign in to comment.