diff options
Diffstat (limited to 'spec/ruby/library')
-rw-r--r-- | spec/ruby/library/coverage/running_spec.rb | 20 | ||||
-rw-r--r-- | spec/ruby/library/date/civil_spec.rb | 7 | ||||
-rw-r--r-- | spec/ruby/library/objectspace/fixtures/trace.rb | 5 | ||||
-rw-r--r-- | spec/ruby/library/objectspace/trace_spec.rb | 15 | ||||
-rw-r--r-- | spec/ruby/library/openssl/x509/name/verify_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/library/stringio/initialize_spec.rb | 85 | ||||
-rw-r--r-- | spec/ruby/library/stringio/new_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/library/stringio/shared/write.rb | 22 |
8 files changed, 158 insertions, 8 deletions
diff --git a/spec/ruby/library/coverage/running_spec.rb b/spec/ruby/library/coverage/running_spec.rb new file mode 100644 index 0000000000..745270164f --- /dev/null +++ b/spec/ruby/library/coverage/running_spec.rb @@ -0,0 +1,20 @@ +require_relative '../../spec_helper' +require 'coverage' + +describe 'Coverage.running?' do + it "returns false if coverage is not started" do + Coverage.running?.should == false + end + + it "returns true if coverage is started" do + Coverage.start + Coverage.running?.should == true + Coverage.result + end + + it "returns false if coverage was started and stopped" do + Coverage.start + Coverage.result + Coverage.running?.should == false + end +end
\ No newline at end of file diff --git a/spec/ruby/library/date/civil_spec.rb b/spec/ruby/library/date/civil_spec.rb index f3537c2f84..1c780fce56 100644 --- a/spec/ruby/library/date/civil_spec.rb +++ b/spec/ruby/library/date/civil_spec.rb @@ -2,11 +2,6 @@ require_relative '../../spec_helper' require_relative 'shared/civil' require 'date' -describe "Date#civil" do - it_behaves_like :date_civil, :civil -end - - describe "Date.civil" do - it "needs to be reviewed for spec completeness" + it_behaves_like :date_civil, :civil end diff --git a/spec/ruby/library/objectspace/fixtures/trace.rb b/spec/ruby/library/objectspace/fixtures/trace.rb new file mode 100644 index 0000000000..fd4524b0ba --- /dev/null +++ b/spec/ruby/library/objectspace/fixtures/trace.rb @@ -0,0 +1,5 @@ +require "objspace/trace" +a = "foo" +b = "b" + "a" + "r" +c = 42 +p a, b, c diff --git a/spec/ruby/library/objectspace/trace_spec.rb b/spec/ruby/library/objectspace/trace_spec.rb new file mode 100644 index 0000000000..59952a006c --- /dev/null +++ b/spec/ruby/library/objectspace/trace_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../spec_helper' + +ruby_version_is "3.1" do + describe 'require "objspace/trace"' do + it "shows object allocation sites" do + file = fixture(__FILE__ , "trace.rb") + ruby_exe(file, args: "2>&1").lines(chomp: true).should == [ + "objspace/trace is enabled", + "\"foo\" @ #{file}:2", + "\"bar\" @ #{file}:3", + "42" + ] + end + end +end diff --git a/spec/ruby/library/openssl/x509/name/verify_spec.rb b/spec/ruby/library/openssl/x509/name/verify_spec.rb index a8bf865bda..6dcfc99466 100644 --- a/spec/ruby/library/openssl/x509/name/verify_spec.rb +++ b/spec/ruby/library/openssl/x509/name/verify_spec.rb @@ -12,7 +12,7 @@ describe "OpenSSL::X509::Name.verify" do cert.public_key = key.public_key cert.not_before = Time.now - 10 cert.not_after = cert.not_before + 365 * 24 * 60 * 60 - cert.sign key, OpenSSL::Digest.new('SHA1') + cert.sign key, OpenSSL::Digest.new('SHA256') store = OpenSSL::X509::Store.new store.add_cert(cert) [store.verify(cert), store.error, store.error_string].should == [true, 0, "ok"] @@ -28,7 +28,7 @@ describe "OpenSSL::X509::Name.verify" do cert.public_key = key.public_key cert.not_before = Time.now - 10 cert.not_after = Time.now - 5 - cert.sign key, OpenSSL::Digest.new('SHA1') + cert.sign key, OpenSSL::Digest.new('SHA256') store = OpenSSL::X509::Store.new store.add_cert(cert) store.verify(cert).should == false diff --git a/spec/ruby/library/stringio/initialize_spec.rb b/spec/ruby/library/stringio/initialize_spec.rb index 1e8096e3bb..c597e328d3 100644 --- a/spec/ruby/library/stringio/initialize_spec.rb +++ b/spec/ruby/library/stringio/initialize_spec.rb @@ -163,6 +163,91 @@ describe "StringIO#initialize when passed [Object]" do end end +# NOTE: Synchronise with core/io/new_spec.rb (core/io/shared/new.rb) +describe "StringIO#initialize when passed keyword arguments" do + it "sets the mode based on the passed :mode option" do + io = StringIO.new("example", "r") + io.closed_read?.should be_false + io.closed_write?.should be_true + end + + it "accepts a mode argument set to nil with a valid :mode option" do + @io = StringIO.new('', nil, mode: "w") + @io.write("foo").should == 3 + end + + it "accepts a mode argument with a :mode option set to nil" do + @io = StringIO.new('', "w", mode: nil) + @io.write("foo").should == 3 + end + + it "sets binmode from :binmode option" do + @io = StringIO.new('', 'w', binmode: true) + @io.external_encoding.to_s.should == "ASCII-8BIT" # #binmode? isn't implemented in StringIO + end + + it "does not set binmode from false :binmode" do + @io = StringIO.new('', 'w', binmode: false) + @io.external_encoding.to_s.should == "UTF-8" # #binmode? isn't implemented in StringIO + end +end + +# NOTE: Synchronise with core/io/new_spec.rb (core/io/shared/new.rb) +describe "StringIO#initialize when passed keyword arguments and error happens" do + it "raises an error if passed encodings two ways" do + -> { + @io = StringIO.new('', 'w:ISO-8859-1', encoding: 'ISO-8859-1') + }.should raise_error(ArgumentError) + -> { + @io = StringIO.new('', 'w:ISO-8859-1', external_encoding: 'ISO-8859-1') + }.should raise_error(ArgumentError) + -> { + @io = StringIO.new('', 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1') + }.should raise_error(ArgumentError) + end + + it "raises an error if passed matching binary/text mode two ways" do + -> { + @io = StringIO.new('', "wb", binmode: true) + }.should raise_error(ArgumentError) + -> { + @io = StringIO.new('', "wt", textmode: true) + }.should raise_error(ArgumentError) + + -> { + @io = StringIO.new('', "wb", textmode: false) + }.should raise_error(ArgumentError) + -> { + @io = StringIO.new('', "wt", binmode: false) + }.should raise_error(ArgumentError) + end + + it "raises an error if passed conflicting binary/text mode two ways" do + -> { + @io = StringIO.new('', "wb", binmode: false) + }.should raise_error(ArgumentError) + -> { + @io = StringIO.new('', "wt", textmode: false) + }.should raise_error(ArgumentError) + + -> { + @io = StringIO.new('', "wb", textmode: true) + }.should raise_error(ArgumentError) + -> { + @io = StringIO.new('', "wt", binmode: true) + }.should raise_error(ArgumentError) + end + + it "raises an error when trying to set both binmode and textmode" do + -> { + @io = StringIO.new('', "w", textmode: true, binmode: true) + }.should raise_error(ArgumentError) + -> { + @io = StringIO.new('', File::Constants::WRONLY, textmode: true, binmode: true) + }.should raise_error(ArgumentError) + end +end + describe "StringIO#initialize when passed no arguments" do before :each do @io = StringIO.allocate diff --git a/spec/ruby/library/stringio/new_spec.rb b/spec/ruby/library/stringio/new_spec.rb new file mode 100644 index 0000000000..e36d210caa --- /dev/null +++ b/spec/ruby/library/stringio/new_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require 'stringio' + +describe "StringIO.new" do + it "warns when called with a block" do + -> { eval("StringIO.new {}") }.should complain(/StringIO::new\(\) does not take block; use StringIO::open\(\) instead/) + end +end
\ No newline at end of file diff --git a/spec/ruby/library/stringio/shared/write.rb b/spec/ruby/library/stringio/shared/write.rb index c5a0f8f513..d9c21028e0 100644 --- a/spec/ruby/library/stringio/shared/write.rb +++ b/spec/ruby/library/stringio/shared/write.rb @@ -66,6 +66,28 @@ describe :stringio_write_string, shared: true do @io.tainted?.should be_false end end + + it "handles writing non-ASCII UTF-8 after seek" do + @io.binmode + @io << "\x80" + @io.pos = 0 + @io << "\x81" + @io.string.should == "\x812345".b + end + + it "handles writing with position < buffer size" do + @io.pos = 2 + @io.write "abc" + @io.string.should == "12abc" + + @io.pos = 2 + @io.write "de" + @io.string.should == "12dec" + + @io.pos = 2 + @io.write "fghi" + @io.string.should == "12fghi" + end end describe :stringio_write_not_writable, shared: true do |