Skip to content

Commit

Permalink
Make ruby_code method handle OpenSSL::PKey::RSA objects
Browse files Browse the repository at this point in the history
  • Loading branch information
bronzdoc committed Sep 17, 2019
1 parent 5c1636d commit b1d825a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,7 @@ def ruby_code(obj)
when Time then obj.strftime('%Y-%m-%d').dump
when Numeric then obj.inspect
when true, false, nil then obj.inspect
when OpenSSL::PKey::RSA then obj.class
when Gem::Platform then "Gem::Platform.new(#{obj.to_a.inspect})"
when Gem::Requirement then
list = obj.as_list
Expand Down
30 changes: 30 additions & 0 deletions test/rubygems/test_gem_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2445,6 +2445,36 @@ def test_to_ruby
assert_equal @a2, same_spec
end

def test_to_ruby_with_rsa_key
rsa_key = OpenSSL::PKey::RSA.new(2048)
@a2.signing_key = rsa_key
ruby_code = @a2.to_ruby

expected = <<-SPEC
# -*- encoding: utf-8 -*-
# stub: a 2 ruby lib
Gem::Specification.new do |s|
s.name = "a".freeze
s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["A User".freeze]
s.date = "2019-05-30"
s.description = "This is a test description".freeze
s.email = "example@example.com".freeze
s.files = ["lib/code.rb".freeze]
s.homepage = "http://example.com".freeze
s.rubygems_version = "3.1.0.pre1".freeze
s.signing_key = OpenSSL::PKey::RSA
s.summary = "this is a summary".freeze
end
SPEC

assert_equal expected, ruby_code
end

def test_to_ruby_for_cache
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
Expand Down

0 comments on commit b1d825a

Please sign in to comment.