diff options
| author | Agis- <corestudiosinc@gmail.com> | 2015-09-06 16:10:01 +0300 |
|---|---|---|
| committer | Andre Arko <andre@arko.net> | 2015-09-06 18:26:18 -0700 |
| commit | 2d86ea2efe0c03940f4e46b1fb90490c7152ad87 (patch) | |
| tree | ce9841015b99835eebbb01d9ef171a1d9b5fb94a | |
| parent | 1131091bbe0c300ccc69c2cec0ff6be398af57bf (diff) | |
| download | bundler-backport-3978.tar.gz | |
Dsl#with_source should restore the previous sourcebackport-3978
Before this change, a gem inside a rubygems source block that also
defined a custom source, would cause subsequent gems inside that same
block to be fetched from rubygems.org.
For example:
source "https://rubygems.org"
source "https://foo.bar" do
gem "rails", git: "git@github.com/rails/rails.git"
gem "i18n"
end
In that case, i18n would be fetched from rubygems.org instead of
foo.bar.
Fixes #3974.
Backport of #3978
| -rw-r--r-- | lib/bundler/dsl.rb | 3 | ||||
| -rw-r--r-- | spec/bundler/dsl_spec.rb | 16 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index e5432fa467..56355d321a 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -226,13 +226,14 @@ module Bundler end def with_source(source) + old_source = @source if block_given? @source = source yield end source ensure - @source = nil + @source = old_source end def normalize_hash(opts) diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index 5b4a52f8d3..1a0264368c 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -188,4 +188,20 @@ describe Bundler::Dsl do end end + describe "#with_source" do + context "if there was a rubygem source already defined" do + it "restores it after it's done" do + other_source = double("other-source") + allow(Bundler::Source::Rubygems).to receive(:new).and_return(other_source) + + subject.source("https://other-source.org") do + subject.gem("dobry-pies", :path => "foo") + subject.gem("foo") + end + + expect(subject.dependencies.last.source).to eq(other_source) + end + end + end + end |
