diff --git a/lib/bundler/stub_specification.rb b/lib/bundler/stub_specification.rb index d5f6a883f97..aeacf245a35 100644 --- a/lib/bundler/stub_specification.rb +++ b/lib/bundler/stub_specification.rb @@ -4,6 +4,7 @@ module Bundler class StubSpecification < RemoteSpecification def self.from_stub(stub) + return stub if stub.is_a?(Bundler::StubSpecification) spec = new(stub.name, stub.version, stub.platform, nil) spec.stub = stub spec diff --git a/spec/bundler/stub_specification_spec.rb b/spec/bundler/stub_specification_spec.rb new file mode 100644 index 00000000000..f1ddf43bb43 --- /dev/null +++ b/spec/bundler/stub_specification_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true +require "spec_helper" + +RSpec.describe Bundler::StubSpecification do + let(:gemspec) do + Gem::Specification.new do |s| + s.name = "gemname" + s.version = "1.0.0" + s.loaded_from = __FILE__ + end + end + + let(:with_bundler_stub_spec) do + described_class.from_stub(gemspec) + end + + if Bundler.rubygems.provides?(">= 2.1") + describe "#from_stub" do + it "returns the same stub if already a Bundler::StubSpecification" do + stub = described_class.from_stub(with_bundler_stub_spec) + expect(stub).to be(with_bundler_stub_spec) + end + end + end +end