diff options
author | Homu <homu@barosl.com> | 2015-09-07 10:28:09 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2015-09-07 10:28:09 +0900 |
commit | 90c6d3ad2afcd9085db2d8ef8b5c55f1e8e37284 (patch) | |
tree | f42435222aa2d638ce5eacd17ebacfe59750c652 | |
parent | 9d61e4ff81114e6e42bc4d40305c4f993b1a7988 (diff) | |
parent | a2ae13c5045c060033d0b62a2b8272f8a0bfb082 (diff) | |
download | bundler-90c6d3ad2afcd9085db2d8ef8b5c55f1e8e37284.tar.gz |
Auto merge of #3978 - agis-:issue-3974, r=indirect
Dsl#with_source should restore the previous source
Fixes #3974.
-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 2da9de4da1..8ed5cd6a93 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -229,13 +229,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 00242f037f..4949ad66c4 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -195,4 +195,20 @@ describe Bundler::Dsl do to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: can't modify frozen String. Bundler cannot continue./i) 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 |