diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2016-05-16 21:54:45 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-06-02 16:51:13 -0500 |
commit | ec276c318319799da37831a8c57c38797c143a84 (patch) | |
tree | 2c4273246626457d2e5328c5e8bfb7ae114ed2f7 | |
parent | 1e0939f3dfafde098f423155cd2dd699ecef24ea (diff) | |
download | bundler-ec276c318319799da37831a8c57c38797c143a84.tar.gz |
[EndpointSpecification] Stop allocating intermediary arrays
-rw-r--r-- | lib/bundler/endpoint_specification.rb | 4 | ||||
-rw-r--r-- | spec/bundler/endpoint_specification_spec.rb | 11 |
2 files changed, 8 insertions, 7 deletions
diff --git a/lib/bundler/endpoint_specification.rb b/lib/bundler/endpoint_specification.rb index b26fdaf9cc..69d05167e8 100644 --- a/lib/bundler/endpoint_specification.rb +++ b/lib/bundler/endpoint_specification.rb @@ -115,8 +115,8 @@ module Bundler end end - def build_dependency(name, *requirements) - Gem::Dependency.new(name, *requirements) + def build_dependency(name, requirements) + Gem::Dependency.new(name, requirements) rescue ArgumentError => e raise unless e.message.include?(ILLFORMED_MESSAGE) puts # we shouldn't print the error message on the "fetching info" status line diff --git a/spec/bundler/endpoint_specification_spec.rb b/spec/bundler/endpoint_specification_spec.rb index fccf1842fc..cdf81cd0f7 100644 --- a/spec/bundler/endpoint_specification_spec.rb +++ b/spec/bundler/endpoint_specification_spec.rb @@ -16,25 +16,26 @@ describe Bundler::EndpointSpecification do let(:requirement2) { ">= 1.1.7" } it "should return a Gem::Dependency" do - expect(subject.send(:build_dependency, name, requirement1, requirement2)).to be_instance_of(Gem::Dependency) + expect(subject.send(:build_dependency, name, [requirement1, requirement2])). + to eq(Gem::Dependency.new(name, requirement1, requirement2)) end context "when an ArgumentError occurs" do before do - allow(Gem::Dependency).to receive(:new).with(name, requirement1, requirement2) { + allow(Gem::Dependency).to receive(:new).with(name, [requirement1, requirement2]) { raise ArgumentError.new("Some error occurred") } end it "should raise the original error" do - expect { subject.send(:build_dependency, name, requirement1, requirement2) }.to raise_error( + expect { subject.send(:build_dependency, name, [requirement1, requirement2]) }.to raise_error( ArgumentError, "Some error occurred") end end context "when there is an ill formed requirement" do before do - allow(Gem::Dependency).to receive(:new).with(name, requirement1, requirement2) { + allow(Gem::Dependency).to receive(:new).with(name, [requirement1, requirement2]) { raise ArgumentError.new("Ill-formed requirement [\"#<YAML::Syck::DefaultKey") } # Eliminate extra line break in rspec output due to `puts` in `#build_dependency` @@ -42,7 +43,7 @@ describe Bundler::EndpointSpecification do end it "should raise a Bundler::GemspecError with invalid gemspec message" do - expect { subject.send(:build_dependency, name, requirement1, requirement2) }.to raise_error( + expect { subject.send(:build_dependency, name, [requirement1, requirement2]) }.to raise_error( Bundler::GemspecError, /Unfortunately, the gem foo \(1\.0\.0\) has an invalid gemspec/) end end |