summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--DEVELOPMENT.md2
-rw-r--r--lib/bundler.rb15
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/cli/lock.rb9
-rw-r--r--lib/bundler/definition.rb8
-rw-r--r--lib/bundler/deployment.rb2
-rw-r--r--lib/bundler/endpoint_specification.rb2
-rw-r--r--lib/bundler/errors.rb1
-rw-r--r--lib/bundler/feature_flag.rb13
-rw-r--r--lib/bundler/lazy_specification.rb6
-rw-r--r--lib/bundler/ruby_version.rb4
-rw-r--r--lib/bundler/rubygems_integration.rb24
-rw-r--r--lib/bundler/settings.rb2
-rw-r--r--lib/bundler/source.rb2
-rw-r--r--lib/bundler/source/path.rb7
-rw-r--r--man/bundle-exec.ronn9
-rw-r--r--spec/bundler/bundler_spec.rb4
-rw-r--r--spec/bundler/endpoint_specification_spec.rb13
-rw-r--r--spec/bundler/ruby_version_spec.rb8
-rw-r--r--spec/bundler/settings_spec.rb10
-rw-r--r--spec/bundler/source_spec.rb2
-rw-r--r--spec/commands/exec_spec.rb25
-rw-r--r--spec/commands/lock_spec.rb32
-rw-r--r--spec/install/gemfile/eval_gemfile_spec.rb18
-rw-r--r--spec/install/gemfile/gemspec_spec.rb33
-rw-r--r--spec/install/gemfile_spec.rb29
-rw-r--r--spec/realworld/edgecases_spec.rb12
-rw-r--r--spec/support/helpers.rb28
28 files changed, 282 insertions, 40 deletions
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index ab95db363a..67e1527677 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -12,7 +12,7 @@ If you have any questions after reading this page, please feel free to contact e
## How you can help
-We track [small bugs and features](https://github.com/bundler/bundler/issues?labels=small) so that anyone who wants to help can start with something that's not too overwhelming. We also keep a [list of things anyone can help with, any time](https://github.com/bundler/bundler/blob/master/CONTRIBUTING.md#contributing). If nothing on those lists looks good, talk to us, and we'll figure out what you can help with. We can absolutely use your help, no matter what level of programming skill you have at the moment.
+We track [small bugs and features](https://github.com/bundler/bundler/labels/contribution%3A%20small) so that anyone who wants to help can start with something that's not too overwhelming. We also keep a [list of things anyone can help with, any time](https://github.com/bundler/bundler/blob/master/CONTRIBUTING.md#contributing). If nothing on those lists looks good, talk to us, and we'll figure out what you can help with. We can absolutely use your help, no matter what level of programming skill you have at the moment.
# Development setup
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 8806ae01ef..249c4e2dc6 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -329,17 +329,23 @@ EOF
def sudo(str)
SUDO_MUTEX.synchronize do
prompt = "\n\n" + <<-PROMPT.gsub(/^ {6}/, "").strip + " "
- Your user account isn't allowed to install to the system Rubygems.
+ Your user account isn't allowed to install to the system RubyGems.
You can cancel this installation and run:
bundle install --path vendor/bundle
to install the gems into ./vendor/bundle/, or you can enter your password
- and install the bundled gems to Rubygems using sudo.
+ and install the bundled gems to RubyGems using sudo.
Password:
PROMPT
+ unless @prompted_for_sudo ||= system(%(sudo -k -p "#{prompt}" true))
+ raise SudoNotPermittedError,
+ "Bundler requires sudo access to install at the moment. " \
+ "Try installing again, granting Bundler sudo access when prompted, or installing into a different path."
+ end
+
`sudo -p "#{prompt}" #{str}`
end
end
@@ -443,7 +449,10 @@ EOF
def configure_gem_path(env = ENV, settings = self.settings)
blank_home = env["GEM_HOME"].nil? || env["GEM_HOME"].empty?
if settings[:disable_shared_gems]
- env["GEM_PATH"] = nil
+ # this needs to be empty string to cause
+ # PathSupport.split_gem_path to only load up the
+ # Bundler --path setting as the GEM_PATH.
+ env["GEM_PATH"] = ""
elsif blank_home || Bundler.rubygems.gem_dir != bundle_path.to_s
possibles = [Bundler.rubygems.gem_dir, Bundler.rubygems.gem_path]
paths = possibles.flatten.compact.uniq.reject(&:empty?)
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 8b48be35d2..ee18767a73 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -441,7 +441,7 @@ module Bundler
end
desc "lock", "Creates a lockfile without installing"
- method_option "update", :type => :array, :lazy_default => [], :banner =>
+ method_option "update", :type => :array, :lazy_default => true, :banner =>
"ignore the existing lockfile, update all gems by default, or update list of given gems"
method_option "local", :type => :boolean, :default => false, :banner =>
"do not attempt to fetch remote gemspecs and use the local gem cache only"
diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb
index a6a95f895c..d4256ad4b9 100644
--- a/lib/bundler/cli/lock.rb
+++ b/lib/bundler/cli/lock.rb
@@ -17,14 +17,11 @@ module Bundler
ui = Bundler.ui
Bundler.ui = UI::Silent.new if print
- gems = options[:update]
Bundler::Fetcher.disable_endpoint = options["full-index"]
- if gems && !gems.empty?
- definition = Bundler.definition(:gems => gems)
- else
- definition = Bundler.definition(true)
- end
+ update = options[:update]
+ update = { :gems => update } if update.is_a?(Array)
+ definition = Bundler.definition(update)
options["remove-platform"].each do |platform|
definition.remove_platform(platform)
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 8bd60168c7..6c8fc1ddde 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -135,17 +135,15 @@ module Bundler
end
def create_gem_version_promoter
- locked_specs = begin
+ locked_specs =
if @unlocking && @locked_specs.empty? && !@lockfile_contents.empty?
# Definition uses an empty set of locked_specs to indicate all gems
# are unlocked, but GemVersionPromoter needs the locked_specs
# for conservative comparison.
- locked = Bundler::LockfileParser.new(@lockfile_contents)
- Bundler::SpecSet.new(locked.specs)
+ Bundler::SpecSet.new(@locked_gems.specs)
else
@locked_specs
end
- end
GemVersionPromoter.new(locked_specs, @unlock[:gems])
end
@@ -888,7 +886,7 @@ module Bundler
end
def additional_base_requirements_for_resolve
- return [] unless @locked_gems && Bundler.settings[:only_update_to_newer_versions]
+ return [] unless @locked_gems && Bundler.feature_flag.only_update_to_newer_versions?
@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)
diff --git a/lib/bundler/deployment.rb b/lib/bundler/deployment.rb
index 94f2fac620..a62fa232fb 100644
--- a/lib/bundler/deployment.rb
+++ b/lib/bundler/deployment.rb
@@ -15,7 +15,7 @@ module Bundler
else
context_name = "vlad"
role_default = "[:app]"
- error_type = ::Rake::CommandFailedError
+ error_type = ::Vlad::CommandFailedError
end
roles = context.fetch(:bundle_roles, false)
diff --git a/lib/bundler/endpoint_specification.rb b/lib/bundler/endpoint_specification.rb
index 69d05167e8..4f5377d3cc 100644
--- a/lib/bundler/endpoint_specification.rb
+++ b/lib/bundler/endpoint_specification.rb
@@ -113,6 +113,8 @@ module Bundler
@required_ruby_version = Gem::Requirement.new(v)
end
end
+ rescue => e
+ raise GemspecError, "There was an error parsing the metadata for the gem #{name} (#{version}): #{e.class}\n#{e}\nThe metadata was #{data.inspect}"
end
def build_dependency(name, requirements)
diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb
index 7681ea73ae..dd5782fb3d 100644
--- a/lib/bundler/errors.rb
+++ b/lib/bundler/errors.rb
@@ -52,6 +52,7 @@ module Bundler
class CyclicDependencyError < BundlerError; status_code(21); end
class GemfileLockNotFound < BundlerError; status_code(22); end
class PluginError < BundlerError; status_code(29); end
+ class SudoNotPermittedError < BundlerError; status_code(30); end
class GemfileEvalError < GemfileError; end
class MarshalError < StandardError; end
diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb
index 80bf2a5150..150cac1e67 100644
--- a/lib/bundler/feature_flag.rb
+++ b/lib/bundler/feature_flag.rb
@@ -1,17 +1,22 @@
# frozen_string_literal: true
module Bundler
class FeatureFlag
- def self.settings_flag(flag)
+ def self.settings_flag(flag, &default)
unless Bundler::Settings::BOOL_KEYS.include?(flag.to_s)
raise "Cannot use `#{flag}` as a settings feature flag since it isn't a bool key"
end
- define_method("#{flag}?") { Bundler.settings[flag] }
+ define_method("#{flag}?") do
+ value = Bundler.settings[flag]
+ value = instance_eval(&default) if value.nil? && !default.nil?
+ value
+ end
end
(1..10).each {|v| define_method("bundler_#{v}_mode?") { major_version >= v } }
- settings_flag :allow_offline_install
- settings_flag :plugins
+ settings_flag(:allow_offline_install) { bundler_2_mode? }
+ settings_flag(:only_update_to_newer_versions) { bundler_2_mode? }
+ settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
def initialize(bundler_version)
@bundler_version = Gem::Version.create(bundler_version)
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb
index 0b667f7dbe..13e7f5fc3c 100644
--- a/lib/bundler/lazy_specification.rb
+++ b/lib/bundler/lazy_specification.rb
@@ -70,7 +70,11 @@ module Bundler
def __materialize__
search_object = Bundler.settings[:specific_platform] ? self : Dependency.new(name, version)
- @specification = source.specs.search(search_object).last
+ @specification = if source.is_a?(Source::Gemspec) && source.gemspec.name == name
+ source.gemspec.tap {|s| s.source = source }
+ else
+ source.specs.search(search_object).last
+ end
end
def respond_to?(*args)
diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb
index 8c050c6d31..ebdefe63fc 100644
--- a/lib/bundler/ruby_version.rb
+++ b/lib/bundler/ruby_version.rb
@@ -23,8 +23,8 @@ module Bundler
@versions = Array(versions)
@gem_version = Gem::Requirement.create(@versions.first).requirements.first.last
- @input_engine = engine
- @engine = engine || "ruby"
+ @input_engine = engine && engine.to_s
+ @engine = engine && engine.to_s || "ruby"
@engine_versions = (engine_version && Array(engine_version)) || @versions
@engine_gem_version = Gem::Requirement.create(@engine_versions.first).requirements.first.last
@patchlevel = patchlevel
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index c1bb6c7ab8..1c44ef3ddd 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -397,6 +397,17 @@ module Bundler
spec
end
+ redefine_method(gem_class, :activate_bin_path) do |name, *args|
+ exec_name = args.first
+ return ENV["BUNDLE_BIN_PATH"] if exec_name == "bundle"
+
+ # Copy of Rubygems activate_bin_path impl
+ requirement = args.last
+ spec = find_spec_for_exe name, exec_name, [requirement]
+ Gem::LOADED_SPECS_MUTEX.synchronize { spec.activate }
+ spec.bin_file exec_name
+ end
+
redefine_method(gem_class, :bin_path) do |name, *args|
exec_name = args.first
return ENV["BUNDLE_BIN_PATH"] if exec_name == "bundle"
@@ -489,6 +500,7 @@ module Bundler
end
def redefine_method(klass, method, unbound_method = nil, &block)
+ visibility = method_visibility(klass, method)
begin
if (instance_method = klass.instance_method(method)) && method != :initialize
# doing this to ensure we also get private methods
@@ -501,8 +513,20 @@ module Bundler
@replaced_methods[[method, klass]] = instance_method
if unbound_method
klass.send(:define_method, method, unbound_method)
+ klass.send(visibility, method)
elsif block
klass.send(:define_method, method, &block)
+ klass.send(visibility, method)
+ end
+ end
+
+ def method_visibility(klass, method)
+ if klass.private_method_defined?(method)
+ :private
+ elsif klass.protected_method_defined?(method)
+ :protected
+ else
+ :public
end
end
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index bed875420e..db6a4ab6ad 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -296,7 +296,7 @@ module Bundler
}xo
def load_config(config_file)
- return unless config_file
+ return {} unless config_file
SharedHelpers.filesystem_access(config_file, :read) do |file|
valid_file = file.exist? && !file.size.zero?
return {} if ignore_config? || !valid_file
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index 166c1d241c..9d65d4613b 100644
--- a/lib/bundler/source.rb
+++ b/lib/bundler/source.rb
@@ -20,7 +20,7 @@ module Bundler
locked_spec = Bundler.locked_gems.specs.find {|s| s.name == spec.name }
locked_spec_version = locked_spec.version if locked_spec
if locked_spec_version && spec.version != locked_spec_version
- message += " (#{Bundler.ui.add_color("was #{locked_spec_version}", :green)})"
+ message += Bundler.ui.add_color(" (was #{locked_spec_version})", :green)
end
end
diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb
index 69bb0c1af2..87a490446c 100644
--- a/lib/bundler/source/path.rb
+++ b/lib/bundler/source/path.rb
@@ -46,7 +46,7 @@ module Bundler
def to_lock
out = String.new("PATH\n")
- out << " remote: #{relative_path}\n"
+ out << " remote: #{lockfile_path}\n"
out << " glob: #{@glob}\n" unless @glob == DEFAULT_GLOB
out << " specs:\n"
end
@@ -129,6 +129,11 @@ module Bundler
"`#{somepath}`.\nThe error message was: #{e.message}."
end
+ def lockfile_path
+ return relative_path if path.absolute?
+ expand(path).relative_path_from(Bundler.root)
+ end
+
def app_cache_path(custom_path = nil)
@app_cache_path ||= Bundler.app_cache(custom_path).join(app_cache_dirname)
end
diff --git a/man/bundle-exec.ronn b/man/bundle-exec.ronn
index ba6844c5c2..c9ab2309e4 100644
--- a/man/bundle-exec.ronn
+++ b/man/bundle-exec.ronn
@@ -63,6 +63,15 @@ It also modifies Rubygems:
making system executables work
* Add all gems in the bundle into Gem.loaded_specs
+### Loading
+
+By default, when attempting to `bundle exec` to a file with a ruby shebang,
+Bundler will `Kernel.load` that file instead of using `Kernel.exec`. For the
+vast majority of cases, this is a performance improvement. In a rare few cases,
+this could cause some subtle side-effects (such as dependence on the exact
+contents of `$0` or `__FILE__`) and the optimization can be disabled by enabling
+the `disable_exec_load` setting.
+
### Shelling out
Any Ruby code that opens a subshell (like `system`, backticks, or `%x{}`) will
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb
index 2ff9920614..cf6de26ac3 100644
--- a/spec/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler_spec.rb
@@ -143,12 +143,12 @@ describe Bundler do
describe "configuration" do
context "disable_shared_gems" do
- it "should unset GEM_PATH with nil" do
+ it "should unset GEM_PATH with empty string" do
env = {}
settings = { :disable_shared_gems => true }
Bundler.send(:configure_gem_path, env, settings)
expect(env.keys).to include("GEM_PATH")
- expect(env["GEM_PATH"]).to be_nil
+ expect(env["GEM_PATH"]).to eq ""
end
end
end
diff --git a/spec/bundler/endpoint_specification_spec.rb b/spec/bundler/endpoint_specification_spec.rb
index 6718b24971..b1e71df39a 100644
--- a/spec/bundler/endpoint_specification_spec.rb
+++ b/spec/bundler/endpoint_specification_spec.rb
@@ -50,4 +50,17 @@ describe Bundler::EndpointSpecification do
end
end
end
+
+ describe "#parse_metadata" do
+ context "when the metadata has malformed requirements" do
+ let(:metadata) { { "rubygems" => ">\n" } }
+ it "raises a helpful error message" do
+ expect { subject }.to raise_error(
+ Bundler::GemspecError,
+ a_string_including("There was an error parsing the metadata for the gem foo (1.0.0)").
+ and(a_string_including('The metadata was {"rubygems"=>">\n"}'))
+ )
+ end
+ end
+ end
end
diff --git a/spec/bundler/ruby_version_spec.rb b/spec/bundler/ruby_version_spec.rb
index abcd0303d0..e983c18484 100644
--- a/spec/bundler/ruby_version_spec.rb
+++ b/spec/bundler/ruby_version_spec.rb
@@ -35,6 +35,14 @@ describe "Bundler::RubyVersion and its subclasses" do
end
end
+ context "with engine in symbol" do
+ let(:engine) { :jruby }
+
+ it "should coerce engine to string" do
+ expect(subject.engine).to eq("jruby")
+ end
+ end
+
context "is called with multiple requirements" do
let(:version) { ["<= 2.0.0", "> 1.9.3"] }
let(:engine_version) { nil }
diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb
index 31ca13903c..5a9d0cb08b 100644
--- a/spec/bundler/settings_spec.rb
+++ b/spec/bundler/settings_spec.rb
@@ -54,6 +54,16 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow
end
describe "#[]" do
+ context "when the local config file is not found" do
+ subject(:settings) { described_class.new }
+
+ it "does not raise" do
+ expect do
+ subject["foo"]
+ end.not_to raise_error
+ end
+ end
+
context "when not set" do
context "when default value present" do
it "retrieves value" do
diff --git a/spec/bundler/source_spec.rb b/spec/bundler/source_spec.rb
index 4e99411a17..ea171d387c 100644
--- a/spec/bundler/source_spec.rb
+++ b/spec/bundler/source_spec.rb
@@ -61,7 +61,7 @@ describe Bundler::Source do
before { Bundler.ui = Bundler::UI::Shell.new }
it "should return a string with the spec name and version and locked spec version" do
- expect(subject.version_message(spec)).to eq("nokogiri >= 1.6 (\e[32mwas < 1.5\e[0m)")
+ expect(subject.version_message(spec)).to eq("nokogiri >= 1.6\e[32m (was < 1.5)\e[0m")
end
end
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb
index 42afbd24ba..4dc47919de 100644
--- a/spec/commands/exec_spec.rb
+++ b/spec/commands/exec_spec.rb
@@ -2,8 +2,9 @@
require "spec_helper"
describe "bundle exec" do
+ let(:system_gems_to_install) { %w(rack-1.0.0 rack-0.9.1) }
before :each do
- system_gems "rack-1.0.0", "rack-0.9.1"
+ system_gems(system_gems_to_install)
end
it "activates the correct gem" do
@@ -627,4 +628,26 @@ __FILE__: #{path.to_s.inspect}
end
end
end
+
+ context "nested bundle exec" do
+ let(:system_gems_to_install) { super() << :bundler }
+ before do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+ bundle :install, :system_bundler => true, :path => "vendor/bundler"
+ end
+
+ it "overrides disable_shared_gems so bundler can be found" do
+ file = bundled_app("file_that_bundle_execs.rb")
+ create_file(file, <<-RB)
+ #!#{Gem.ruby}
+ puts `bundle exec echo foo`
+ RB
+ file.chmod(0o777)
+ bundle! "exec #{file}", :system_bundler => true
+ expect(out).to eq("foo")
+ end
+ end
end
diff --git a/spec/commands/lock_spec.rb b/spec/commands/lock_spec.rb
index fc605dc5a6..590d421ba0 100644
--- a/spec/commands/lock_spec.rb
+++ b/spec/commands/lock_spec.rb
@@ -10,9 +10,11 @@ describe "bundle lock" do
strip_lockfile bundled_app(file).read
end
+ let(:repo) { gem_repo1 }
+
before :each do
gemfile <<-G
- source "file://#{gem_repo1}"
+ source "file://#{repo}"
gem "rails"
gem "with_license"
gem "foo"
@@ -20,7 +22,7 @@ describe "bundle lock" do
@lockfile = strip_lockfile <<-L
GEM
- remote: file:#{gem_repo1}/
+ remote: file:#{repo}/
specs:
actionmailer (2.3.2)
activesupport (= 2.3.2)
@@ -77,7 +79,7 @@ describe "bundle lock" do
it "writes a lockfile when there is an outdated lockfile using --update" do
lockfile @lockfile.gsub("2.3.2", "2.3.1")
- bundle "lock --update"
+ bundle! "lock --update"
expect(read_lockfile).to eq(@lockfile)
end
@@ -223,4 +225,28 @@ describe "bundle lock" do
#{Bundler::VERSION}
G
end
+
+ context "when an update is available" do
+ let(:repo) { gem_repo2 }
+
+ before do
+ lockfile(@lockfile)
+ build_repo2 do
+ build_gem "foo", "2.0"
+ end
+ end
+
+ it "does not implicitly update" do
+ bundle! "lock"
+
+ expect(read_lockfile).to eq(@lockfile)
+ end
+
+ it "accounts for changes in the gemfile" do
+ gemfile gemfile.gsub('"foo"', '"foo", "2.0"')
+ bundle! "lock"
+
+ expect(read_lockfile).to eq(@lockfile.sub("foo (1.0)", "foo (2.0)").sub(/foo$/, "foo (= 2.0)"))
+ end
+ end
end
diff --git a/spec/install/gemfile/eval_gemfile_spec.rb b/spec/install/gemfile/eval_gemfile_spec.rb
index 2660ac98c2..29f27550e4 100644
--- a/spec/install/gemfile/eval_gemfile_spec.rb
+++ b/spec/install/gemfile/eval_gemfile_spec.rb
@@ -26,6 +26,24 @@ describe "bundle install with gemfile that uses eval_gemfile" do
end
end
+ context "eval-ed Gemfile has relative-path gems" do
+ before do
+ build_lib("a", :path => "gems/a")
+ create_file "nested/Gemfile-nested", <<-G
+ gem "a", :path => "../gems/a"
+ G
+
+ gemfile <<-G
+ eval_gemfile "nested/Gemfile-nested"
+ G
+ end
+
+ it "installs the path gem" do
+ bundle! :install
+ expect(the_bundle).to include_gem("a 1.0")
+ end
+ end
+
context "Gemfile uses gemspec paths after eval-ing a Gemfile" do
before { create_file "other/Gemfile-other" }
diff --git a/spec/install/gemfile/gemspec_spec.rb b/spec/install/gemfile/gemspec_spec.rb
index 9a6bd5f1e8..698756525c 100644
--- a/spec/install/gemfile/gemspec_spec.rb
+++ b/spec/install/gemfile/gemspec_spec.rb
@@ -409,4 +409,37 @@ describe "bundle install from an existing gemspec" do
end
end
end
+
+ context "with multiple platforms" do
+ before do
+ build_lib("foo", :path => tmp.join("foo")) do |s|
+ s.version = "1.0.0"
+ s.add_development_dependency "rack"
+ s.write "foo-universal-java.gemspec", build_spec("foo", "1.0.0", "universal-java") {|sj| sj.runtime "rack", "1.0.0" }.first.to_ruby
+ end
+ end
+
+ it "installs the ruby platform gemspec" do
+ simulate_platform "ruby"
+
+ install_gemfile! <<-G
+ source "file://#{gem_repo1}"
+ gemspec :path => '#{tmp.join("foo")}', :name => 'foo'
+ G
+
+ expect(the_bundle).to include_gems "foo 1.0.0", "rack 1.0.0"
+ end
+
+ it "installs the ruby platform gemspec and skips dev deps with --without development" do
+ simulate_platform "ruby"
+
+ install_gemfile! <<-G, :without => "development"
+ source "file://#{gem_repo1}"
+ gemspec :path => '#{tmp.join("foo")}', :name => 'foo'
+ G
+
+ expect(the_bundle).to include_gem "foo 1.0.0"
+ expect(the_bundle).not_to include_gem "rack"
+ end
+ end
end
diff --git a/spec/install/gemfile_spec.rb b/spec/install/gemfile_spec.rb
index 98abc30c86..03ae344987 100644
--- a/spec/install/gemfile_spec.rb
+++ b/spec/install/gemfile_spec.rb
@@ -66,4 +66,33 @@ describe "bundle install" do
expect(out).to match(/You passed :lib as an option for gem 'rack', but it is invalid/)
end
end
+
+ context "with engine specified in symbol" do
+ it "does not raise any error parsing Gemfile" do
+ simulate_ruby_version "2.3.0" do
+ simulate_ruby_engine "jruby", "9.1.2.0" do
+ install_gemfile! <<-G
+ source "https://rubygems.org"
+ ruby "2.3.0", :engine => :jruby, :engine_version => "9.1.2.0"
+ G
+
+ expect(out).to match(/Bundle complete!/)
+ end
+ end
+ end
+
+ it "installation succeeds" do
+ simulate_ruby_version "2.3.0" do
+ simulate_ruby_engine "jruby", "9.1.2.0" do
+ install_gemfile! <<-G
+ source "file://#{gem_repo1}"
+ ruby "2.3.0", :engine => :jruby, :engine_version => "9.1.2.0"
+ gem "rack"
+ G
+
+ expect(the_bundle).to include_gems "rack 1.0.0"
+ end
+ end
+ end
+ end
end
diff --git a/spec/realworld/edgecases_spec.rb b/spec/realworld/edgecases_spec.rb
index 7a78a114b4..06e588044c 100644
--- a/spec/realworld/edgecases_spec.rb
+++ b/spec/realworld/edgecases_spec.rb
@@ -48,8 +48,16 @@ describe "real world edgecases", :realworld => true, :sometimes => true do
gem 'capybara', '~> 2.2.0'
gem 'rack-cache', '1.2.0' # last version that works on Ruby 1.9
G
- bundle :lock
- expect(lockfile).to include("rails (3.2.22.4)")
+ bundle! :lock
+ rails_version = ruby(<<-R)
+ require 'rubygems'
+ require 'bundler'
+ fetcher = Bundler::Fetcher.new(Bundler::Source::Rubygems::Remote.new(URI('https://rubygems.org')))
+ index = fetcher.specs(%w(rails), nil)
+ rails = index.search(Gem::Dependency.new("rails", "~> 3.0")).last
+ puts rails.version
+ R
+ expect(lockfile).to include("rails (#{rails_version})")
expect(lockfile).to include("capybara (2.2.1)")
end
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index fe79604f30..6b30afd480 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -88,18 +88,28 @@ module Spec
bundle_bin = options.delete("bundle_bin") || File.expand_path("../../../exe/bundle", __FILE__)
+ if system_bundler = options.delete(:system_bundler)
+ bundle_bin = "-S bundle"
+ end
+
requires = options.delete(:requires) || []
requires << File.expand_path("../fakeweb/" + options.delete(:fakeweb) + ".rb", __FILE__) if options.key?(:fakeweb)
requires << File.expand_path("../artifice/" + options.delete(:artifice) + ".rb", __FILE__) if options.key?(:artifice)
requires << "support/hax"
requires_str = requires.map {|r| "-r#{r}" }.join(" ")
+ load_path = []
+ load_path << lib unless system_bundler
+ load_path << spec
+ load_path_str = "-I#{load_path.join(File::PATH_SEPARATOR)}"
+
env = (options.delete(:env) || {}).map {|k, v| "#{k}='#{v}'" }.join(" ")
+ env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler
args = options.map do |k, v|
v == true ? " --#{k}" : " --#{k} #{v}" if v
end.join
- cmd = "#{env} #{sudo} #{Gem.ruby} -I#{lib}:#{spec} #{requires_str} #{bundle_bin} #{cmd}#{args}"
+ cmd = "#{env} #{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}"
sys_exec(cmd) {|i, o, thr| yield i, o, thr if block_given? }
end
bang :bundle
@@ -208,7 +218,11 @@ module Spec
end
def gemfile(*args)
- create_file("Gemfile", *args)
+ if args.empty?
+ File.open("Gemfile", "r", &:read)
+ else
+ create_file("Gemfile", *args)
+ end
end
def lockfile(*args)
@@ -242,11 +256,17 @@ module Spec
def install_gems(*gems)
gems.each do |g|
- path = "#{gem_repo1}/gems/#{g}.gem"
+ path = if g == :bundler
+ Dir.chdir(root) { gem_command! :build, "#{root}/bundler.gemspec" }
+ bundler_path = root + "bundler-#{Bundler::VERSION}.gem"
+ else
+ "#{gem_repo1}/gems/#{g}.gem"
+ end
raise "OMG `#{path}` does not exist!" unless File.exist?(path)
- gem_command! :install, "--no-rdoc --no-ri --ignore-dependencies #{path}"
+ gem_command! :install, "--no-rdoc --no-ri --ignore-dependencies '#{path}'"
+ bundler_path && bundler_path.rmtree
end
end