summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rubygems/psych_tree.rb4
-rw-r--r--lib/rubygems/specification.rb3
-rw-r--r--test/rubygems/test_gem_specification.rb20
3 files changed, 26 insertions, 1 deletions
diff --git a/lib/rubygems/psych_tree.rb b/lib/rubygems/psych_tree.rb
index 2d478c94d9..7d17fc29cf 100644
--- a/lib/rubygems/psych_tree.rb
+++ b/lib/rubygems/psych_tree.rb
@@ -14,6 +14,10 @@ module Gem
@emitter.scalar str, nil, nil, false, true, quote
end
+ def visit_Hash(o)
+ super(o.dup.delete_if {|_, v| v.nil? })
+ end
+
# Noop this out so there are no anchors
def register(target, obj)
end
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 61ea3fcfdc..29139cf725 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1890,7 +1890,8 @@ class Gem::Specification < Gem::BasicSpecification
attributes = @@attributes.map(&:to_s) - %w[name version platform]
attributes.each do |name|
- coder.add name, instance_variable_get("@#{name}")
+ value = instance_variable_get("@#{name}")
+ coder.add name, value unless value.nil?
end
end
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 977e8b2965..9aa88fd5a3 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -2517,6 +2517,26 @@ end
assert_match(/^platform: ruby$/, @a1.to_yaml)
end
+ def test_to_yaml_no_autorequire
+ yaml_str = @a1.to_yaml
+
+ refute_match(/^autorequire:/, yaml_str)
+ end
+
+ def test_to_yaml_no_signing_key
+ @a1.signing_key = nil
+ yaml_str = @a1.to_yaml
+
+ refute_match(/^signing_key:/, yaml_str)
+ end
+
+ def test_to_yaml_no_post_install_message
+ @a1.post_install_message = nil
+ yaml_str = @a1.to_yaml
+
+ refute_match(/^post_install_message:/, yaml_str)
+ end
+
def test_validate
util_setup_validate