Permalink
Browse files

Add workaround for buggy yaml output from 1.9.2

  • Loading branch information...
1 parent 038ffe9 commit 4e8dd58c0c6b150fb1ccdf6f76156341a5f32a9f @evanphx evanphx committed Mar 22, 2012
Showing with 40 additions and 0 deletions.
  1. +11 −0 lib/rubygems/psych_tree.rb
  2. +29 −0 test/rubygems/test_gem_specification.rb
View
@@ -11,6 +11,17 @@ def visit_String(str)
# Noop this out so there are no anchors
def register(target, obj)
end
+
+ # This is ported over from the yaml_tree in 1.9.3
+ def format_time time
+ if time.utc?
+ time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
+ else
+ time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
+ end
+ end
+
+ private :format_time
end
end
end
@@ -432,6 +432,17 @@ def test_handles_private_null_type
assert_equal nil, data.rubyforge_project
end
+ def test_emits_zulu_timestamps_properly
+ skip "bug only on 1.9.2" unless RUBY_VERSION =~ /1\.9\.2/
+
+ t = Time.utc(2012, 3, 12)
+ @a2.date = t
+
+ yaml = with_psych { @a2.to_yaml }
+
+ assert_match %r!date: 2012-03-12 00:00:00\.000000000 Z!, yaml
+ end
+
def test_initialize
spec = Gem::Specification.new do |s|
s.name = "blah"
@@ -1870,6 +1881,24 @@ def with_syck
end
end
+ def with_psych
+ begin
+ require "yaml"
+ old_engine = YAML::ENGINE.yamler
+ YAML::ENGINE.yamler = 'psych'
+ rescue NameError
+ # probably on 1.8, ignore
+ end
+
+ yield
+ ensure
+ begin
+ YAML::ENGINE.yamler = old_engine
+ rescue NameError
+ # ignore
+ end
+ end
+
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, false
yield

0 comments on commit 4e8dd58

Please sign in to comment.