spec/yaml_spec.rb in asir-1.2.1 vs spec/yaml_spec.rb in asir-1.2.2
- old
+ new
@@ -17,20 +17,23 @@
123.45,
'String',
[ :Symbol, ':Symbol' ],
].each do | x |
x, str = *x
- if x == nil and RUBY_VERSION == '1.9.2'
- str = '!!null '
+ if x == nil
+ if RUBY_VERSION == '1.9.2'
+ str = '!!null '
+ end
end
str ||= x.to_s
- str = "--- #{str}\n"
- str << "...\n" if RUBY_VERSION !~ /^1\.8/
+ unless x == nil and RUBY_VERSION !~ /^1\.8/ and RUBY_ENGINE =~ /jruby/i
+ str = " #{str}"
+ end
basic_objs << [ x, str ]
it "should handle #{x.inspect}" do
out = @enc.prepare.encode(x)
- out.should == str
+ out.should =~ /\A---#{str} ?\n(\.\.\.\n)?\Z/
@dec.prepare.decode(out).should == x
end
end
it 'should handle :never_binary.' do
@@ -41,11 +44,11 @@
when /^1\.8/
out.should =~ /^ :binary: !binary /m
when '1.9.2'
out.should =~ /^ :binary: |-\n/m
else
- out.should =~ /^ :binary: ! "\\x04/m
+ out.should =~ /^ :binary: (! )?"\\x04/m
end
end
it 'should handle :ASCII_8BIT_ok.' do
@enc.yaml_options = { :ASCII_8BIT_ok => true }
@@ -76,10 +79,14 @@
if ''.methods.include?(:force_encoding)
it 'should extend Psych with :never_binary option.' do
require 'socket'
hostname = Socket.gethostname
enc = hostname.encoding
+ if enc.inspect != "#<Encoding:ASCII-8BIT>" # JRUBY?
+ hostname.force_encoding('ASCII-8BIT')
+ enc = hostname.encoding
+ end
enc.inspect.should == "#<Encoding:ASCII-8BIT>"
str = enc.inspect
str.force_encoding(hostname.encoding)
str.encoding.inspect.should == "#<Encoding:ASCII-8BIT>"
@@ -91,29 +98,39 @@
else
yaml.should == "--- !binary |-\n IzxFbmNvZGluZzpBU0NJSS04QklUPg==\n"
end
yaml = ::YAML.dump(str, nil, :never_binary => true)
- yaml.should == "--- ! '#<Encoding:ASCII-8BIT>'\n"
+ yaml.should =~ /\A--- (! )?['"]\#<Encoding:ASCII-8BIT>['"]\n/
end
it 'should handle :never_binary options.' do
str = '8bitascii'.force_encoding('ASCII-8BIT')
@enc.yaml_options = @dec.yaml_options = nil
out = @enc.prepare.encode(str)
case RUBY_VERSION
when '1.9.2'
- out.should == "--- 8bitascii\n...\n"
+ case RUBY_ENGINE
+ when /jruby/i
+ out.should == "--- 8bitascii\n"
+ else
+ out.should == "--- 8bitascii\n...\n"
+ end
else
out.should == "--- !binary |-\n OGJpdGFzY2lp\n"
end
@dec.prepare.decode(str).should == str
@enc.yaml_options = { :never_binary => true }
@dec.yaml_options = @enc.yaml_options
out = @enc.prepare.encode(str)
- out.should == "--- 8bitascii\n...\n"
+ case RUBY_ENGINE
+ when /jruby/i
+ out.should == "--- 8bitascii\n"
+ else
+ out.should == "--- 8bitascii\n...\n"
+ end
inp = @dec.prepare.decode(str)
inp.should == str
inp.encoding.inspect.should == "#<Encoding:UTF-8>"
end
end