summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringio
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/stringio')
-rw-r--r--spec/ruby/library/stringio/append_spec.rb10
-rw-r--r--spec/ruby/library/stringio/binmode_spec.rb2
-rw-r--r--spec/ruby/library/stringio/close_read_spec.rb6
-rw-r--r--spec/ruby/library/stringio/close_spec.rb8
-rw-r--r--spec/ruby/library/stringio/close_write_spec.rb6
-rw-r--r--spec/ruby/library/stringio/closed_read_spec.rb4
-rw-r--r--spec/ruby/library/stringio/closed_spec.rb6
-rw-r--r--spec/ruby/library/stringio/closed_write_spec.rb4
-rw-r--r--spec/ruby/library/stringio/each_line_spec.rb4
-rw-r--r--spec/ruby/library/stringio/each_spec.rb4
-rw-r--r--spec/ruby/library/stringio/fcntl_spec.rb2
-rw-r--r--spec/ruby/library/stringio/fileno_spec.rb5
-rw-r--r--spec/ruby/library/stringio/flush_spec.rb2
-rw-r--r--spec/ruby/library/stringio/fsync_spec.rb2
-rw-r--r--spec/ruby/library/stringio/gets_spec.rb263
-rw-r--r--spec/ruby/library/stringio/initialize_spec.rb140
-rw-r--r--spec/ruby/library/stringio/inspect_spec.rb2
-rw-r--r--spec/ruby/library/stringio/lineno_spec.rb8
-rw-r--r--spec/ruby/library/stringio/open_spec.rb120
-rw-r--r--spec/ruby/library/stringio/path_spec.rb2
-rw-r--r--spec/ruby/library/stringio/pid_spec.rb2
-rw-r--r--spec/ruby/library/stringio/pos_spec.rb2
-rw-r--r--spec/ruby/library/stringio/print_spec.rb14
-rw-r--r--spec/ruby/library/stringio/printf_spec.rb14
-rw-r--r--spec/ruby/library/stringio/putc_spec.rb8
-rw-r--r--spec/ruby/library/stringio/puts_spec.rb8
-rw-r--r--spec/ruby/library/stringio/read_nonblock_spec.rb2
-rw-r--r--spec/ruby/library/stringio/read_spec.rb4
-rw-r--r--spec/ruby/library/stringio/readline_spec.rb160
-rw-r--r--spec/ruby/library/stringio/readlines_spec.rb14
-rw-r--r--spec/ruby/library/stringio/readpartial_spec.rb44
-rw-r--r--spec/ruby/library/stringio/reopen_spec.rb74
-rw-r--r--spec/ruby/library/stringio/rewind_spec.rb2
-rw-r--r--spec/ruby/library/stringio/seek_spec.rb24
-rw-r--r--spec/ruby/library/stringio/set_encoding_by_bom_spec.rb6
-rw-r--r--spec/ruby/library/stringio/shared/codepoints.rb10
-rw-r--r--spec/ruby/library/stringio/shared/each.rb90
-rw-r--r--spec/ruby/library/stringio/shared/each_byte.rb10
-rw-r--r--spec/ruby/library/stringio/shared/each_char.rb8
-rw-r--r--spec/ruby/library/stringio/shared/eof.rb10
-rw-r--r--spec/ruby/library/stringio/shared/getc.rb20
-rw-r--r--spec/ruby/library/stringio/shared/gets.rb249
-rw-r--r--spec/ruby/library/stringio/shared/isatty.rb2
-rw-r--r--spec/ruby/library/stringio/shared/read.rb30
-rw-r--r--spec/ruby/library/stringio/shared/readchar.rb6
-rw-r--r--spec/ruby/library/stringio/shared/sysread.rb2
-rw-r--r--spec/ruby/library/stringio/shared/write.rb8
-rw-r--r--spec/ruby/library/stringio/string_spec.rb12
-rw-r--r--spec/ruby/library/stringio/stringio_spec.rb2
-rw-r--r--spec/ruby/library/stringio/sync_spec.rb4
-rw-r--r--spec/ruby/library/stringio/sysread_spec.rb2
-rw-r--r--spec/ruby/library/stringio/truncate_spec.rb16
-rw-r--r--spec/ruby/library/stringio/ungetc_spec.rb14
53 files changed, 758 insertions, 715 deletions
diff --git a/spec/ruby/library/stringio/append_spec.rb b/spec/ruby/library/stringio/append_spec.rb
index cb50d73d1b..c21ba00508 100644
--- a/spec/ruby/library/stringio/append_spec.rb
+++ b/spec/ruby/library/stringio/append_spec.rb
@@ -7,7 +7,7 @@ describe "StringIO#<< when passed [Object]" do
end
it "returns self" do
- (@io << "just testing").should equal(@io)
+ (@io << "just testing").should.equal?(@io)
end
it "writes the passed argument onto self" do
@@ -31,7 +31,7 @@ describe "StringIO#<< when passed [Object]" do
it "updates self's position" do
@io << "test"
- @io.pos.should eql(4)
+ @io.pos.should.eql?(4)
end
it "tries to convert the passed argument to a String using #to_s" do
@@ -45,11 +45,11 @@ end
describe "StringIO#<< when self is not writable" do
it "raises an IOError" do
io = StringIO.new(+"test", "r")
- -> { io << "test" }.should raise_error(IOError)
+ -> { io << "test" }.should.raise(IOError)
io = StringIO.new(+"test")
io.close_write
- -> { io << "test" }.should raise_error(IOError)
+ -> { io << "test" }.should.raise(IOError)
end
end
@@ -69,6 +69,6 @@ describe "StringIO#<< when in append mode" do
it "correctly updates self's position" do
@io << ", testing"
- @io.pos.should eql(16)
+ @io.pos.should.eql?(16)
end
end
diff --git a/spec/ruby/library/stringio/binmode_spec.rb b/spec/ruby/library/stringio/binmode_spec.rb
index 9e92c63814..bc7ccda0a2 100644
--- a/spec/ruby/library/stringio/binmode_spec.rb
+++ b/spec/ruby/library/stringio/binmode_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
describe "StringIO#binmode" do
it "returns self" do
io = StringIO.new(+"example")
- io.binmode.should equal(io)
+ io.binmode.should.equal?(io)
end
it "changes external encoding to BINARY" do
diff --git a/spec/ruby/library/stringio/close_read_spec.rb b/spec/ruby/library/stringio/close_read_spec.rb
index 0f08e1ff2e..dd46a927be 100644
--- a/spec/ruby/library/stringio/close_read_spec.rb
+++ b/spec/ruby/library/stringio/close_read_spec.rb
@@ -7,12 +7,12 @@ describe "StringIO#close_read" do
end
it "returns nil" do
- @io.close_read.should be_nil
+ @io.close_read.should == nil
end
it "prevents further reading" do
@io.close_read
- -> { @io.read(1) }.should raise_error(IOError)
+ -> { @io.read(1) }.should.raise(IOError)
end
it "allows further writing" do
@@ -22,7 +22,7 @@ describe "StringIO#close_read" do
it "raises an IOError when in write-only mode" do
io = StringIO.new(+"example", "w")
- -> { io.close_read }.should raise_error(IOError)
+ -> { io.close_read }.should.raise(IOError)
io = StringIO.new("example")
io.close_read
diff --git a/spec/ruby/library/stringio/close_spec.rb b/spec/ruby/library/stringio/close_spec.rb
index 520a8de782..6febd14a26 100644
--- a/spec/ruby/library/stringio/close_spec.rb
+++ b/spec/ruby/library/stringio/close_spec.rb
@@ -7,17 +7,17 @@ describe "StringIO#close" do
end
it "returns nil" do
- @io.close.should be_nil
+ @io.close.should == nil
end
it "prevents further reading and/or writing" do
@io.close
- -> { @io.read(1) }.should raise_error(IOError)
- -> { @io.write('x') }.should raise_error(IOError)
+ -> { @io.read(1) }.should.raise(IOError)
+ -> { @io.write('x') }.should.raise(IOError)
end
it "does not raise anything when self was already closed" do
@io.close
- -> { @io.close }.should_not raise_error(IOError)
+ -> { @io.close }.should_not.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/close_write_spec.rb b/spec/ruby/library/stringio/close_write_spec.rb
index c86c3f9826..b74b996166 100644
--- a/spec/ruby/library/stringio/close_write_spec.rb
+++ b/spec/ruby/library/stringio/close_write_spec.rb
@@ -7,12 +7,12 @@ describe "StringIO#close_write" do
end
it "returns nil" do
- @io.close_write.should be_nil
+ @io.close_write.should == nil
end
it "prevents further writing" do
@io.close_write
- -> { @io.write('x') }.should raise_error(IOError)
+ -> { @io.write('x') }.should.raise(IOError)
end
it "allows further reading" do
@@ -22,7 +22,7 @@ describe "StringIO#close_write" do
it "raises an IOError when in read-only mode" do
io = StringIO.new(+"example", "r")
- -> { io.close_write }.should raise_error(IOError)
+ -> { io.close_write }.should.raise(IOError)
io = StringIO.new(+"example")
io.close_write
diff --git a/spec/ruby/library/stringio/closed_read_spec.rb b/spec/ruby/library/stringio/closed_read_spec.rb
index b4dcadc3a4..2e3813b1bc 100644
--- a/spec/ruby/library/stringio/closed_read_spec.rb
+++ b/spec/ruby/library/stringio/closed_read_spec.rb
@@ -5,8 +5,8 @@ describe "StringIO#closed_read?" do
it "returns true if self is not readable" do
io = StringIO.new(+"example", "r+")
io.close_write
- io.closed_read?.should be_false
+ io.closed_read?.should == false
io.close_read
- io.closed_read?.should be_true
+ io.closed_read?.should == true
end
end
diff --git a/spec/ruby/library/stringio/closed_spec.rb b/spec/ruby/library/stringio/closed_spec.rb
index bf7ba63184..647fe445da 100644
--- a/spec/ruby/library/stringio/closed_spec.rb
+++ b/spec/ruby/library/stringio/closed_spec.rb
@@ -5,12 +5,12 @@ describe "StringIO#closed?" do
it "returns true if self is completely closed" do
io = StringIO.new(+"example", "r+")
io.close_read
- io.closed?.should be_false
+ io.closed?.should == false
io.close_write
- io.closed?.should be_true
+ io.closed?.should == true
io = StringIO.new(+"example", "r+")
io.close
- io.closed?.should be_true
+ io.closed?.should == true
end
end
diff --git a/spec/ruby/library/stringio/closed_write_spec.rb b/spec/ruby/library/stringio/closed_write_spec.rb
index 2bd3e6fa8b..339691cd82 100644
--- a/spec/ruby/library/stringio/closed_write_spec.rb
+++ b/spec/ruby/library/stringio/closed_write_spec.rb
@@ -5,8 +5,8 @@ describe "StringIO#closed_write?" do
it "returns true if self is not writable" do
io = StringIO.new(+"example", "r+")
io.close_read
- io.closed_write?.should be_false
+ io.closed_write?.should == false
io.close_write
- io.closed_write?.should be_true
+ io.closed_write?.should == true
end
end
diff --git a/spec/ruby/library/stringio/each_line_spec.rb b/spec/ruby/library/stringio/each_line_spec.rb
index c68f7dae82..4ac0db7c45 100644
--- a/spec/ruby/library/stringio/each_line_spec.rb
+++ b/spec/ruby/library/stringio/each_line_spec.rb
@@ -21,3 +21,7 @@ end
describe "StringIO#each_line when passed limit" do
it_behaves_like :stringio_each_limit, :each_line
end
+
+describe "StringIO#each when passed separator and limit" do
+ it_behaves_like :stringio_each_separator_and_limit, :each_line
+end
diff --git a/spec/ruby/library/stringio/each_spec.rb b/spec/ruby/library/stringio/each_spec.rb
index 2c30ed5cda..7eb322f3ff 100644
--- a/spec/ruby/library/stringio/each_spec.rb
+++ b/spec/ruby/library/stringio/each_spec.rb
@@ -25,3 +25,7 @@ end
describe "StringIO#each when passed limit" do
it_behaves_like :stringio_each_limit, :each
end
+
+describe "StringIO#each when passed separator and limit" do
+ it_behaves_like :stringio_each_separator_and_limit, :each
+end
diff --git a/spec/ruby/library/stringio/fcntl_spec.rb b/spec/ruby/library/stringio/fcntl_spec.rb
index a78004d868..6108130db7 100644
--- a/spec/ruby/library/stringio/fcntl_spec.rb
+++ b/spec/ruby/library/stringio/fcntl_spec.rb
@@ -3,6 +3,6 @@ require_relative 'fixtures/classes'
describe "StringIO#fcntl" do
it "raises a NotImplementedError" do
- -> { StringIO.new("boom").fcntl }.should raise_error(NotImplementedError)
+ -> { StringIO.new("boom").fcntl }.should.raise(NotImplementedError)
end
end
diff --git a/spec/ruby/library/stringio/fileno_spec.rb b/spec/ruby/library/stringio/fileno_spec.rb
index eea03a5af3..f5d1e83776 100644
--- a/spec/ruby/library/stringio/fileno_spec.rb
+++ b/spec/ruby/library/stringio/fileno_spec.rb
@@ -1,9 +1,8 @@
require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/each'
+require 'stringio'
describe "StringIO#fileno" do
it "returns nil" do
- StringIO.new("nuffin").fileno.should be_nil
+ StringIO.new("nuffin").fileno.should == nil
end
end
diff --git a/spec/ruby/library/stringio/flush_spec.rb b/spec/ruby/library/stringio/flush_spec.rb
index 4dc58b1d48..48be44773c 100644
--- a/spec/ruby/library/stringio/flush_spec.rb
+++ b/spec/ruby/library/stringio/flush_spec.rb
@@ -4,6 +4,6 @@ require_relative 'fixtures/classes'
describe "StringIO#flush" do
it "returns self" do
io = StringIO.new(+"flush")
- io.flush.should equal(io)
+ io.flush.should.equal?(io)
end
end
diff --git a/spec/ruby/library/stringio/fsync_spec.rb b/spec/ruby/library/stringio/fsync_spec.rb
index 85053cb2e5..30fae15c8e 100644
--- a/spec/ruby/library/stringio/fsync_spec.rb
+++ b/spec/ruby/library/stringio/fsync_spec.rb
@@ -4,6 +4,6 @@ require_relative 'fixtures/classes'
describe "StringIO#fsync" do
it "returns zero" do
io = StringIO.new(+"fsync")
- io.fsync.should eql(0)
+ io.fsync.should.eql?(0)
end
end
diff --git a/spec/ruby/library/stringio/gets_spec.rb b/spec/ruby/library/stringio/gets_spec.rb
index 4af7704a41..5dc572fba5 100644
--- a/spec/ruby/library/stringio/gets_spec.rb
+++ b/spec/ruby/library/stringio/gets_spec.rb
@@ -1,250 +1,61 @@
require_relative '../../spec_helper'
require "stringio"
+require_relative "shared/gets"
-describe "StringIO#gets when passed [separator]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
-
- it "returns the data read till the next occurrence of the passed separator" do
- @io.gets(">").should == "this>"
- @io.gets(">").should == "is>"
- @io.gets(">").should == "an>"
- @io.gets(">").should == "example"
- end
-
- it "sets $_ to the read content" do
- @io.gets(">")
- $_.should == "this>"
- @io.gets(">")
- $_.should == "is>"
- @io.gets(">")
- $_.should == "an>"
- @io.gets(">")
- $_.should == "example"
- @io.gets(">")
- $_.should be_nil
- end
-
- it "accepts string as separator" do
- @io.gets("is>")
- $_.should == "this>"
- @io.gets("an>")
- $_.should == "is>an>"
- @io.gets("example")
- $_.should == "example"
- @io.gets("ple")
- $_.should be_nil
- end
-
- it "updates self's lineno by one" do
- @io.gets(">")
- @io.lineno.should eql(1)
-
- @io.gets(">")
- @io.lineno.should eql(2)
-
- @io.gets(">")
- @io.lineno.should eql(3)
- end
-
- it "returns the next paragraph when the passed separator is an empty String" do
- io = StringIO.new("this is\n\nan example")
- io.gets("").should == "this is\n\n"
- io.gets("").should == "an example"
- end
-
- it "returns the remaining content starting at the current position when passed nil" do
- io = StringIO.new("this is\n\nan example")
- io.pos = 5
- io.gets(nil).should == "is\n\nan example"
- end
+describe "StringIO#gets" do
+ describe "when passed [separator]" do
+ it_behaves_like :stringio_gets_separator, :gets
- it "tries to convert the passed separator to a String using #to_str" do
- obj = mock('to_str')
- obj.should_receive(:to_str).and_return(">")
- @io.gets(obj).should == "this>"
- end
-end
-
-describe "StringIO#gets when passed no argument" do
- before :each do
- @io = StringIO.new("this is\nan example\nfor StringIO#gets")
- end
+ it "returns nil if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- it "returns the data read till the next occurrence of $/ or till eof" do
- @io.gets.should == "this is\n"
-
- begin
- old_sep = $/
- suppress_warning {$/ = " "}
- @io.gets.should == "an "
- @io.gets.should == "example\nfor "
- @io.gets.should == "StringIO#gets"
- ensure
- suppress_warning {$/ = old_sep}
+ @io.pos = 36
+ @io.gets(">").should == nil
+ @io.gets(">").should == nil
end
end
- it "sets $_ to the read content" do
- @io.gets
- $_.should == "this is\n"
- @io.gets
- $_.should == "an example\n"
- @io.gets
- $_.should == "for StringIO#gets"
- @io.gets
- $_.should be_nil
- end
-
- it "updates self's position" do
- @io.gets
- @io.pos.should eql(8)
-
- @io.gets
- @io.pos.should eql(19)
-
- @io.gets
- @io.pos.should eql(36)
- end
-
- it "updates self's lineno" do
- @io.gets
- @io.lineno.should eql(1)
-
- @io.gets
- @io.lineno.should eql(2)
-
- @io.gets
- @io.lineno.should eql(3)
- end
-
- it "returns nil if self is at the end" do
- @io.pos = 36
- @io.gets.should be_nil
- @io.gets.should be_nil
- end
-end
-
-describe "StringIO#gets when passed [limit]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
-
- it "returns the data read until the limit is met" do
- @io.gets(4).should == "this"
- @io.gets(3).should == ">is"
- @io.gets(5).should == ">an>e"
- @io.gets(6).should == "xample"
- end
-
- it "sets $_ to the read content" do
- @io.gets(4)
- $_.should == "this"
- @io.gets(3)
- $_.should == ">is"
- @io.gets(5)
- $_.should == ">an>e"
- @io.gets(6)
- $_.should == "xample"
- @io.gets(3)
- $_.should be_nil
- end
-
- it "updates self's lineno by one" do
- @io.gets(3)
- @io.lineno.should eql(1)
-
- @io.gets(3)
- @io.lineno.should eql(2)
-
- @io.gets(3)
- @io.lineno.should eql(3)
- end
-
- it "tries to convert the passed limit to an Integer using #to_int" do
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(4)
- @io.gets(obj).should == "this"
- end
-
- it "returns a blank string when passed a limit of 0" do
- @io.gets(0).should == ""
- end
-
- it "ignores it when passed a negative limit" do
- @io.gets(-4).should == "this>is>an>example"
- end
-end
+ describe "when passed [limit]" do
+ it_behaves_like :stringio_gets_limit, :gets
-describe "StringIO#gets when passed [separator] and [limit]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
-
- it "returns the data read until the limit is consumed or the separator is met" do
- @io.gets('>', 8).should == "this>"
- @io.gets('>', 2).should == "is"
- @io.gets('>', 10).should == ">"
- @io.gets('>', 6).should == "an>"
- @io.gets('>', 5).should == "examp"
- end
+ it "returns nil if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- it "sets $_ to the read content" do
- @io.gets('>', 8)
- $_.should == "this>"
- @io.gets('>', 2)
- $_.should == "is"
- @io.gets('>', 10)
- $_.should == ">"
- @io.gets('>', 6)
- $_.should == "an>"
- @io.gets('>', 5)
- $_.should == "examp"
+ @io.pos = 36
+ @io.gets(3).should == nil
+ @io.gets(3).should == nil
+ end
end
- it "updates self's lineno by one" do
- @io.gets('>', 3)
- @io.lineno.should eql(1)
+ describe "when passed [separator] and [limit]" do
+ it_behaves_like :stringio_gets_separator_and_limit, :gets
- @io.gets('>', 3)
- @io.lineno.should eql(2)
+ it "returns nil if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- @io.gets('>', 3)
- @io.lineno.should eql(3)
+ @io.pos = 36
+ @io.gets(">", 3).should == nil
+ @io.gets(">", 3).should == nil
+ end
end
- it "tries to convert the passed separator to a String using #to_str" do
- obj = mock('to_str')
- obj.should_receive(:to_str).and_return('>')
- @io.gets(obj, 5).should == "this>"
- end
+ describe "when passed no argument" do
+ it_behaves_like :stringio_gets_no_argument, :gets
- it "does not raise TypeError if passed separator is nil" do
- @io.gets(nil, 5).should == "this>"
- end
+ it "returns nil if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- it "tries to convert the passed limit to an Integer using #to_int" do
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(5)
- @io.gets('>', obj).should == "this>"
+ @io.pos = 36
+ @io.gets.should == nil
+ @io.gets.should == nil
+ end
end
-end
-
-describe "StringIO#gets when in write-only mode" do
- it "raises an IOError" do
- io = StringIO.new(+"xyz", "w")
- -> { io.gets }.should raise_error(IOError)
- io = StringIO.new("xyz")
- io.close_read
- -> { io.gets }.should raise_error(IOError)
+ describe "when passed [chomp]" do
+ it_behaves_like :stringio_gets_chomp, :gets
end
-end
-describe "StringIO#gets when passed [chomp]" do
- it "returns the data read without a trailing newline character" do
- io = StringIO.new("this>is>an>example\n")
- io.gets(chomp: true).should == "this>is>an>example"
+ describe "when in write-only mode" do
+ it_behaves_like :stringio_gets_write_only, :gets
end
end
diff --git a/spec/ruby/library/stringio/initialize_spec.rb b/spec/ruby/library/stringio/initialize_spec.rb
index 6f4d2e456c..413e0aacc0 100644
--- a/spec/ruby/library/stringio/initialize_spec.rb
+++ b/spec/ruby/library/stringio/initialize_spec.rb
@@ -8,111 +8,111 @@ describe "StringIO#initialize when passed [Object, mode]" do
it "uses the passed Object as the StringIO backend" do
@io.send(:initialize, str = "example", "r")
- @io.string.should equal(str)
+ @io.string.should.equal?(str)
end
it "sets the mode based on the passed mode" do
io = StringIO.allocate
io.send(:initialize, +"example", "r")
- io.closed_read?.should be_false
- io.closed_write?.should be_true
+ io.closed_read?.should == false
+ io.closed_write?.should == true
io = StringIO.allocate
io.send(:initialize, +"example", "rb")
- io.closed_read?.should be_false
- io.closed_write?.should be_true
+ io.closed_read?.should == false
+ io.closed_write?.should == true
io = StringIO.allocate
io.send(:initialize, +"example", "r+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", "rb+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", "w")
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", "wb")
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", "w+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", "wb+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", "a")
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", "ab")
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", "a+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", "ab+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
end
it "allows passing the mode as an Integer" do
io = StringIO.allocate
io.send(:initialize, +"example", IO::RDONLY)
- io.closed_read?.should be_false
- io.closed_write?.should be_true
+ io.closed_read?.should == false
+ io.closed_write?.should == true
io = StringIO.allocate
io.send(:initialize, +"example", IO::RDWR)
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", IO::WRONLY)
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", IO::WRONLY | IO::TRUNC)
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", IO::RDWR | IO::TRUNC)
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", IO::WRONLY | IO::APPEND)
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.allocate
io.send(:initialize, +"example", IO::RDWR | IO::APPEND)
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
end
it "raises a FrozenError when passed a frozen String in truncate mode as StringIO backend" do
io = StringIO.allocate
- -> { io.send(:initialize, "example".freeze, IO::TRUNC) }.should raise_error(FrozenError)
+ -> { io.send(:initialize, "example".freeze, IO::TRUNC) }.should.raise(FrozenError)
end
it "tries to convert the passed mode to a String using #to_str" do
@@ -120,15 +120,15 @@ describe "StringIO#initialize when passed [Object, mode]" do
obj.should_receive(:to_str).and_return("r")
@io.send(:initialize, +"example", obj)
- @io.closed_read?.should be_false
- @io.closed_write?.should be_true
+ @io.closed_read?.should == false
+ @io.closed_write?.should == true
end
it "raises an Errno::EACCES error when passed a frozen string with a write-mode" do
(str = "example").freeze
- -> { @io.send(:initialize, str, "r+") }.should raise_error(Errno::EACCES)
- -> { @io.send(:initialize, str, "w") }.should raise_error(Errno::EACCES)
- -> { @io.send(:initialize, str, "a") }.should raise_error(Errno::EACCES)
+ -> { @io.send(:initialize, str, "r+") }.should.raise(Errno::EACCES)
+ -> { @io.send(:initialize, str, "w") }.should.raise(Errno::EACCES)
+ -> { @io.send(:initialize, str, "a") }.should.raise(Errno::EACCES)
end
it "truncates all the content if passed w mode" do
@@ -159,19 +159,19 @@ describe "StringIO#initialize when passed [Object]" do
it "uses the passed Object as the StringIO backend" do
@io.send(:initialize, str = "example")
- @io.string.should equal(str)
+ @io.string.should.equal?(str)
end
it "sets the mode to read-write if the string is mutable" do
@io.send(:initialize, +"example")
- @io.closed_read?.should be_false
- @io.closed_write?.should be_false
+ @io.closed_read?.should == false
+ @io.closed_write?.should == false
end
it "sets the mode to read if the string is frozen" do
@io.send(:initialize, -"example")
- @io.closed_read?.should be_false
- @io.closed_write?.should be_true
+ @io.closed_read?.should == false
+ @io.closed_write?.should == true
end
it "tries to convert the passed Object to a String using #to_str" do
@@ -184,8 +184,8 @@ describe "StringIO#initialize when passed [Object]" do
it "automatically sets the mode to read-only when passed a frozen string" do
(str = "example").freeze
@io.send(:initialize, str)
- @io.closed_read?.should be_false
- @io.closed_write?.should be_true
+ @io.closed_read?.should == false
+ @io.closed_write?.should == true
end
end
@@ -193,8 +193,8 @@ end
describe "StringIO#initialize when passed keyword arguments" do
it "sets the mode based on the passed :mode option" do
io = StringIO.new("example", mode: "r")
- io.closed_read?.should be_false
- io.closed_write?.should be_true
+ io.closed_read?.should == false
+ io.closed_write?.should == true
end
it "accepts a mode argument set to nil with a valid :mode option" do
@@ -223,54 +223,54 @@ describe "StringIO#initialize when passed keyword arguments and error happens" d
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)
+ }.should.raise(ArgumentError)
-> {
@io = StringIO.new(+'', 'w:ISO-8859-1', external_encoding: 'ISO-8859-1')
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
-> {
@io = StringIO.new(+'', 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1')
- }.should raise_error(ArgumentError)
+ }.should.raise(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)
+ }.should.raise(ArgumentError)
-> {
@io = StringIO.new(+'', "wt", textmode: true)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
-> {
@io = StringIO.new(+'', "wb", textmode: false)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
-> {
@io = StringIO.new(+'', "wt", binmode: false)
- }.should raise_error(ArgumentError)
+ }.should.raise(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)
+ }.should.raise(ArgumentError)
-> {
@io = StringIO.new(+'', "wt", textmode: false)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
-> {
@io = StringIO.new(+'', "wb", textmode: true)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
-> {
@io = StringIO.new(+'', "wt", binmode: true)
- }.should raise_error(ArgumentError)
+ }.should.raise(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)
+ }.should.raise(ArgumentError)
-> {
@io = StringIO.new(+'', File::Constants::WRONLY, textmode: true, binmode: true)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
@@ -280,13 +280,13 @@ describe "StringIO#initialize when passed no arguments" do
end
it "is private" do
- StringIO.should have_private_instance_method(:initialize)
+ StringIO.private_instance_methods(false).should.include?(:initialize)
end
it "sets the mode to read-write" do
@io.send(:initialize)
- @io.closed_read?.should be_false
- @io.closed_write?.should be_false
+ @io.closed_read?.should == false
+ @io.closed_write?.should == false
end
it "uses an empty String as the StringIO backend" do
diff --git a/spec/ruby/library/stringio/inspect_spec.rb b/spec/ruby/library/stringio/inspect_spec.rb
index 7c02f8d360..962d858e48 100644
--- a/spec/ruby/library/stringio/inspect_spec.rb
+++ b/spec/ruby/library/stringio/inspect_spec.rb
@@ -9,7 +9,7 @@ describe "StringIO#inspect" do
it "does not include the contents" do
io = StringIO.new("contents")
- io.inspect.should_not include("contents")
+ io.inspect.should_not.include?("contents")
end
it "uses the regular Object#inspect without any instance variable" do
diff --git a/spec/ruby/library/stringio/lineno_spec.rb b/spec/ruby/library/stringio/lineno_spec.rb
index c620a1a686..a96dc05927 100644
--- a/spec/ruby/library/stringio/lineno_spec.rb
+++ b/spec/ruby/library/stringio/lineno_spec.rb
@@ -10,7 +10,7 @@ describe "StringIO#lineno" do
@io.gets
@io.gets
@io.gets
- @io.lineno.should eql(3)
+ @io.lineno.should.eql?(3)
end
end
@@ -21,10 +21,10 @@ describe "StringIO#lineno=" do
it "sets the current line number, but has no impact on the position" do
@io.lineno = 3
- @io.pos.should eql(0)
+ @io.pos.should.eql?(0)
@io.gets.should == "this\n"
- @io.lineno.should eql(4)
- @io.pos.should eql(5)
+ @io.lineno.should.eql?(4)
+ @io.pos.should.eql?(5)
end
end
diff --git a/spec/ruby/library/stringio/open_spec.rb b/spec/ruby/library/stringio/open_spec.rb
index b7c90661f9..23c7b34e09 100644
--- a/spec/ruby/library/stringio/open_spec.rb
+++ b/spec/ruby/library/stringio/open_spec.rb
@@ -4,24 +4,24 @@ require 'stringio'
describe "StringIO.open when passed [Object, mode]" do
it "uses the passed Object as the StringIO backend" do
io = StringIO.open(str = "example", "r")
- io.string.should equal(str)
+ io.string.should.equal?(str)
end
it "returns the blocks return value when yielding" do
ret = StringIO.open(+"example", "r") { :test }
- ret.should equal(:test)
+ ret.should.equal?(:test)
end
it "yields self to the passed block" do
io = nil
StringIO.open(+"example", "r") { |strio| io = strio }
- io.should be_kind_of(StringIO)
+ io.should.is_a?(StringIO)
end
it "closes self after yielding" do
io = nil
StringIO.open(+"example", "r") { |strio| io = strio }
- io.closed?.should be_true
+ io.closed?.should == true
end
it "even closes self when an exception is raised while yielding" do
@@ -33,13 +33,13 @@ describe "StringIO.open when passed [Object, mode]" do
end
rescue
end
- io.closed?.should be_true
+ io.closed?.should == true
end
it "sets self's string to nil after yielding" do
io = nil
StringIO.open(+"example", "r") { |strio| io = strio }
- io.string.should be_nil
+ io.string.should == nil
end
it "even sets self's string to nil when an exception is raised while yielding" do
@@ -51,91 +51,91 @@ describe "StringIO.open when passed [Object, mode]" do
end
rescue
end
- io.string.should be_nil
+ io.string.should == nil
end
it "sets the mode based on the passed mode" do
io = StringIO.open(+"example", "r")
- io.closed_read?.should be_false
- io.closed_write?.should be_true
+ io.closed_read?.should == false
+ io.closed_write?.should == true
io = StringIO.open(+"example", "rb")
- io.closed_read?.should be_false
- io.closed_write?.should be_true
+ io.closed_read?.should == false
+ io.closed_write?.should == true
io = StringIO.open(+"example", "r+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.open(+"example", "rb+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.open(+"example", "w")
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.open(+"example", "wb")
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.open(+"example", "w+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.open(+"example", "wb+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.open(+"example", "a")
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.open(+"example", "ab")
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.open(+"example", "a+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.open(+"example", "ab+")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
end
it "allows passing the mode as an Integer" do
io = StringIO.open(+"example", IO::RDONLY)
- io.closed_read?.should be_false
- io.closed_write?.should be_true
+ io.closed_read?.should == false
+ io.closed_write?.should == true
io = StringIO.open(+"example", IO::RDWR)
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.open(+"example", IO::WRONLY)
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.open(+"example", IO::WRONLY | IO::TRUNC)
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.open(+"example", IO::RDWR | IO::TRUNC)
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.open(+"example", IO::WRONLY | IO::APPEND)
- io.closed_read?.should be_true
- io.closed_write?.should be_false
+ io.closed_read?.should == true
+ io.closed_write?.should == false
io = StringIO.open(+"example", IO::RDWR | IO::APPEND)
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
end
it "raises a FrozenError when passed a frozen String in truncate mode as StringIO backend" do
- -> { StringIO.open("example".freeze, IO::TRUNC) }.should raise_error(FrozenError)
+ -> { StringIO.open("example".freeze, IO::TRUNC) }.should.raise(FrozenError)
end
it "tries to convert the passed mode to a String using #to_str" do
@@ -143,34 +143,34 @@ describe "StringIO.open when passed [Object, mode]" do
obj.should_receive(:to_str).and_return("r")
io = StringIO.open(+"example", obj)
- io.closed_read?.should be_false
- io.closed_write?.should be_true
+ io.closed_read?.should == false
+ io.closed_write?.should == true
end
it "raises an Errno::EACCES error when passed a frozen string with a write-mode" do
(str = "example").freeze
- -> { StringIO.open(str, "r+") }.should raise_error(Errno::EACCES)
- -> { StringIO.open(str, "w") }.should raise_error(Errno::EACCES)
- -> { StringIO.open(str, "a") }.should raise_error(Errno::EACCES)
+ -> { StringIO.open(str, "r+") }.should.raise(Errno::EACCES)
+ -> { StringIO.open(str, "w") }.should.raise(Errno::EACCES)
+ -> { StringIO.open(str, "a") }.should.raise(Errno::EACCES)
end
end
describe "StringIO.open when passed [Object]" do
it "uses the passed Object as the StringIO backend" do
io = StringIO.open(str = "example")
- io.string.should equal(str)
+ io.string.should.equal?(str)
end
it "yields self to the passed block" do
io = nil
ret = StringIO.open(+"example") { |strio| io = strio }
- io.should equal(ret)
+ io.should.equal?(ret)
end
it "sets the mode to read-write (r+)" do
io = StringIO.open(+"example")
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.new(+"example")
io.printf("%d", 123)
@@ -187,8 +187,8 @@ describe "StringIO.open when passed [Object]" do
it "automatically sets the mode to read-only when passed a frozen string" do
(str = "example").freeze
io = StringIO.open(str)
- io.closed_read?.should be_false
- io.closed_write?.should be_true
+ io.closed_read?.should == false
+ io.closed_write?.should == true
end
end
@@ -196,13 +196,13 @@ describe "StringIO.open when passed no arguments" do
it "yields self to the passed block" do
io = nil
ret = StringIO.open { |strio| io = strio }
- io.should equal(ret)
+ io.should.equal?(ret)
end
it "sets the mode to read-write (r+)" do
io = StringIO.open
- io.closed_read?.should be_false
- io.closed_write?.should be_false
+ io.closed_read?.should == false
+ io.closed_write?.should == false
io = StringIO.new(+"example")
io.printf("%d", 123)
diff --git a/spec/ruby/library/stringio/path_spec.rb b/spec/ruby/library/stringio/path_spec.rb
index 1184ca523f..dcb77b1df8 100644
--- a/spec/ruby/library/stringio/path_spec.rb
+++ b/spec/ruby/library/stringio/path_spec.rb
@@ -3,6 +3,6 @@ require_relative 'fixtures/classes'
describe "StringIO#path" do
it "is not defined" do
- -> { StringIO.new("path").path }.should raise_error(NoMethodError)
+ -> { StringIO.new("path").path }.should.raise(NoMethodError)
end
end
diff --git a/spec/ruby/library/stringio/pid_spec.rb b/spec/ruby/library/stringio/pid_spec.rb
index 08f2d7ab1a..7a729fbe41 100644
--- a/spec/ruby/library/stringio/pid_spec.rb
+++ b/spec/ruby/library/stringio/pid_spec.rb
@@ -3,6 +3,6 @@ require_relative 'fixtures/classes'
describe "StringIO#pid" do
it "returns nil" do
- StringIO.new("pid").pid.should be_nil
+ StringIO.new("pid").pid.should == nil
end
end
diff --git a/spec/ruby/library/stringio/pos_spec.rb b/spec/ruby/library/stringio/pos_spec.rb
index 81be5f01a5..ba640f8c18 100644
--- a/spec/ruby/library/stringio/pos_spec.rb
+++ b/spec/ruby/library/stringio/pos_spec.rb
@@ -17,7 +17,7 @@ describe "StringIO#pos=" do
end
it "raises an EINVAL if given a negative argument" do
- -> { @io.pos = -10 }.should raise_error(Errno::EINVAL)
+ -> { @io.pos = -10 }.should.raise(Errno::EINVAL)
end
it "updates the current byte offset after reaching EOF" do
diff --git a/spec/ruby/library/stringio/print_spec.rb b/spec/ruby/library/stringio/print_spec.rb
index 00c33367dc..48728e5f14 100644
--- a/spec/ruby/library/stringio/print_spec.rb
+++ b/spec/ruby/library/stringio/print_spec.rb
@@ -29,7 +29,7 @@ describe "StringIO#print" do
end
it "returns nil" do
- @io.print(1, 2, 3).should be_nil
+ @io.print(1, 2, 3).should == nil
end
it "pads self with \\000 when the current position is after the end" do
@@ -52,10 +52,10 @@ describe "StringIO#print" do
it "updates the current position" do
@io.print(1, 2, 3)
- @io.pos.should eql(3)
+ @io.pos.should.eql?(3)
@io.print(1, 2, 3)
- @io.pos.should eql(6)
+ @io.pos.should.eql?(6)
end
it "correctly updates the current position when honoring the output record separator global" do
@@ -64,7 +64,7 @@ describe "StringIO#print" do
begin
@io.print(5, 6, 7, 8)
- @io.pos.should eql(5)
+ @io.pos.should.eql?(5)
ensure
suppress_warning {$\ = old_rs}
end
@@ -86,17 +86,17 @@ describe "StringIO#print when in append mode" do
it "correctly updates self's position" do
@io.print(", testing")
- @io.pos.should eql(16)
+ @io.pos.should.eql?(16)
end
end
describe "StringIO#print when self is not writable" do
it "raises an IOError" do
io = StringIO.new(+"test", "r")
- -> { io.print("test") }.should raise_error(IOError)
+ -> { io.print("test") }.should.raise(IOError)
io = StringIO.new(+"test")
io.close_write
- -> { io.print("test") }.should raise_error(IOError)
+ -> { io.print("test") }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/printf_spec.rb b/spec/ruby/library/stringio/printf_spec.rb
index ca82e84757..ae7e0af729 100644
--- a/spec/ruby/library/stringio/printf_spec.rb
+++ b/spec/ruby/library/stringio/printf_spec.rb
@@ -8,7 +8,7 @@ describe "StringIO#printf" do
end
it "returns nil" do
- @io.printf("%d %04x", 123, 123).should be_nil
+ @io.printf("%d %04x", 123, 123).should == nil
end
it "pads self with \\000 when the current position is after the end" do
@@ -24,10 +24,10 @@ describe "StringIO#printf" do
it "updates the current position" do
@io.printf("%d %04x", 123, 123)
- @io.pos.should eql(8)
+ @io.pos.should.eql?(8)
@io.printf("%d %04x", 123, 123)
- @io.pos.should eql(16)
+ @io.pos.should.eql?(16)
end
describe "formatting" do
@@ -56,7 +56,7 @@ describe "StringIO#printf when in read-write mode" do
it "correctly updates self's position" do
@io.printf("%s", "abc")
- @io.pos.should eql(3)
+ @io.pos.should.eql?(3)
end
end
@@ -75,17 +75,17 @@ describe "StringIO#printf when in append mode" do
it "correctly updates self's position" do
@io.printf("%d %04x", 123, 123)
- @io.pos.should eql(15)
+ @io.pos.should.eql?(15)
end
end
describe "StringIO#printf when self is not writable" do
it "raises an IOError" do
io = StringIO.new(+"test", "r")
- -> { io.printf("test") }.should raise_error(IOError)
+ -> { io.printf("test") }.should.raise(IOError)
io = StringIO.new(+"test")
io.close_write
- -> { io.printf("test") }.should raise_error(IOError)
+ -> { io.printf("test") }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/putc_spec.rb b/spec/ruby/library/stringio/putc_spec.rb
index 9f1ac8ffb2..742f8623eb 100644
--- a/spec/ruby/library/stringio/putc_spec.rb
+++ b/spec/ruby/library/stringio/putc_spec.rb
@@ -22,7 +22,7 @@ describe "StringIO#putc when passed [String]" do
it "returns the passed String" do
str = "test"
- @io.putc(str).should equal(str)
+ @io.putc(str).should.equal?(str)
end
it "correctly updates the current position" do
@@ -79,7 +79,7 @@ describe "StringIO#putc when passed [Object]" do
end
it "raises a TypeError when the passed argument can't be coerced to Integer" do
- -> { @io.putc(Object.new) }.should raise_error(TypeError)
+ -> { @io.putc(Object.new) }.should.raise(TypeError)
end
end
@@ -94,10 +94,10 @@ end
describe "StringIO#putc when self is not writable" do
it "raises an IOError" do
io = StringIO.new(+"test", "r")
- -> { io.putc(?a) }.should raise_error(IOError)
+ -> { io.putc(?a) }.should.raise(IOError)
io = StringIO.new(+"test")
io.close_write
- -> { io.putc("t") }.should raise_error(IOError)
+ -> { io.putc("t") }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/puts_spec.rb b/spec/ruby/library/stringio/puts_spec.rb
index 054ec8227f..ebe74d4a45 100644
--- a/spec/ruby/library/stringio/puts_spec.rb
+++ b/spec/ruby/library/stringio/puts_spec.rb
@@ -123,7 +123,7 @@ describe "StringIO#puts when passed no arguments" do
end
it "returns nil" do
- @io.puts.should be_nil
+ @io.puts.should == nil
end
it "prints a newline" do
@@ -158,18 +158,18 @@ describe "StringIO#puts when in append mode" do
it "correctly updates self's position" do
@io.puts(", testing")
- @io.pos.should eql(17)
+ @io.pos.should.eql?(17)
end
end
describe "StringIO#puts when self is not writable" do
it "raises an IOError" do
io = StringIO.new(+"test", "r")
- -> { io.puts }.should raise_error(IOError)
+ -> { io.puts }.should.raise(IOError)
io = StringIO.new(+"test")
io.close_write
- -> { io.puts }.should raise_error(IOError)
+ -> { io.puts }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/read_nonblock_spec.rb b/spec/ruby/library/stringio/read_nonblock_spec.rb
index 74736f7792..38ae7541ca 100644
--- a/spec/ruby/library/stringio/read_nonblock_spec.rb
+++ b/spec/ruby/library/stringio/read_nonblock_spec.rb
@@ -45,7 +45,7 @@ describe "StringIO#read_nonblock" do
stringio.rewind
stringio.read_nonblock(5).should == "hello"
- stringio.read_nonblock(5, exception: false).should be_nil
+ stringio.read_nonblock(5, exception: false).should == nil
end
end
end
diff --git a/spec/ruby/library/stringio/read_spec.rb b/spec/ruby/library/stringio/read_spec.rb
index e49f262127..9a2086a682 100644
--- a/spec/ruby/library/stringio/read_spec.rb
+++ b/spec/ruby/library/stringio/read_spec.rb
@@ -39,7 +39,7 @@ describe "StringIO#read when passed [length]" do
it "returns nil when self's position is at the end" do
@io.pos = 7
- @io.read(10).should be_nil
+ @io.read(10).should == nil
end
it "returns an empty String when length is 0" do
@@ -57,6 +57,6 @@ describe "StringIO#read when passed length and a buffer" do
result = @io.read(10, buf)
buf.should == "abcdefghij"
- result.should equal(buf)
+ result.should.equal?(buf)
end
end
diff --git a/spec/ruby/library/stringio/readline_spec.rb b/spec/ruby/library/stringio/readline_spec.rb
index b16a16e23f..3f026080e2 100644
--- a/spec/ruby/library/stringio/readline_spec.rb
+++ b/spec/ruby/library/stringio/readline_spec.rb
@@ -1,150 +1,58 @@
require_relative '../../spec_helper'
+require "stringio"
require_relative 'fixtures/classes'
+require_relative "shared/gets"
+describe "StringIO#readline" do
+ describe "when passed [separator]" do
+ it_behaves_like :stringio_gets_separator, :readline
-describe "StringIO#readline when passed [separator]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
-
- it "returns the data read till the next occurrence of the passed separator" do
- @io.readline(">").should == "this>"
- @io.readline(">").should == "is>"
- @io.readline(">").should == "an>"
- @io.readline(">").should == "example"
- end
-
- it "sets $_ to the read content" do
- @io.readline(">")
- $_.should == "this>"
- @io.readline(">")
- $_.should == "is>"
- @io.readline(">")
- $_.should == "an>"
- @io.readline(">")
- $_.should == "example"
- end
-
- it "updates self's lineno by one" do
- @io.readline(">")
- @io.lineno.should eql(1)
-
- @io.readline(">")
- @io.lineno.should eql(2)
-
- @io.readline(">")
- @io.lineno.should eql(3)
- end
-
- it "returns the next paragraph when the passed separator is an empty String" do
- io = StringIO.new("this is\n\nan example")
- io.readline("").should == "this is\n\n"
- io.readline("").should == "an example"
- end
-
- it "returns the remaining content starting at the current position when passed nil" do
- io = StringIO.new("this is\n\nan example")
- io.pos = 5
- io.readline(nil).should == "is\n\nan example"
- end
-
- it "tries to convert the passed separator to a String using #to_str" do
- obj = mock('to_str')
- obj.should_receive(:to_str).and_return(">")
- @io.readline(obj).should == "this>"
- end
-end
-
-describe "StringIO#readline when passed no argument" do
- before :each do
- @io = StringIO.new("this is\nan example\nfor StringIO#readline")
- end
-
- it "returns the data read till the next occurrence of $/ or till eof" do
- @io.readline.should == "this is\n"
+ it "raises an IOError if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- begin
- old_sep = $/
- suppress_warning {$/ = " "}
- @io.readline.should == "an "
- @io.readline.should == "example\nfor "
- @io.readline.should == "StringIO#readline"
- ensure
- suppress_warning {$/ = old_sep}
+ @io.pos = 36
+ -> { @io.readline(">") }.should.raise(IOError)
end
end
- it "sets $_ to the read content" do
- @io.readline
- $_.should == "this is\n"
- @io.readline
- $_.should == "an example\n"
- @io.readline
- $_.should == "for StringIO#readline"
- end
+ describe "when passed [limit]" do
+ it_behaves_like :stringio_gets_limit, :readline
- it "updates self's position" do
- @io.readline
- @io.pos.should eql(8)
+ it "raises an IOError if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- @io.readline
- @io.pos.should eql(19)
-
- @io.readline
- @io.pos.should eql(40)
+ @io.pos = 36
+ -> { @io.readline(3) }.should.raise(IOError)
+ end
end
- it "updates self's lineno" do
- @io.readline
- @io.lineno.should eql(1)
+ describe "when passed [separator] and [limit]" do
+ it_behaves_like :stringio_gets_separator_and_limit, :readline
- @io.readline
- @io.lineno.should eql(2)
+ it "raises an IOError if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- @io.readline
- @io.lineno.should eql(3)
- end
-
- it "raises an IOError if self is at the end" do
- @io.pos = 40
- -> { @io.readline }.should raise_error(IOError)
- end
-end
-
-describe "StringIO#readline when in write-only mode" do
- it "raises an IOError" do
- io = StringIO.new(+"xyz", "w")
- -> { io.readline }.should raise_error(IOError)
-
- io = StringIO.new("xyz")
- io.close_read
- -> { io.readline }.should raise_error(IOError)
+ @io.pos = 36
+ -> { @io.readline(">", 3) }.should.raise(IOError)
+ end
end
-end
-describe "StringIO#readline when passed [chomp]" do
- it "returns the data read without a trailing newline character" do
- io = StringIO.new("this>is>an>example\n")
- io.readline(chomp: true).should == "this>is>an>example"
- end
-end
+ describe "when passed no argument" do
+ it_behaves_like :stringio_gets_no_argument, :readline
-describe "StringIO#readline when passed [limit]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
+ it "raises an IOError if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- it "returns the data read until the limit is met" do
- io = StringIO.new("this>is>an>example\n")
- io.readline(3).should == "thi"
+ @io.pos = 36
+ -> { @io.readline }.should.raise(IOError)
+ end
end
- it "returns a blank string when passed a limit of 0" do
- @io.readline(0).should == ""
+ describe "when passed [chomp]" do
+ it_behaves_like :stringio_gets_chomp, :readline
end
- it "ignores it when the limit is negative" do
- seen = []
- @io.readline(-4).should == "this>is>an>example"
+ describe "when in write-only mode" do
+ it_behaves_like :stringio_gets_write_only, :readline
end
end
diff --git a/spec/ruby/library/stringio/readlines_spec.rb b/spec/ruby/library/stringio/readlines_spec.rb
index ed7cc22b3d..821a8169e7 100644
--- a/spec/ruby/library/stringio/readlines_spec.rb
+++ b/spec/ruby/library/stringio/readlines_spec.rb
@@ -12,12 +12,12 @@ describe "StringIO#readlines when passed [separator]" do
it "updates self's position based on the number of read bytes" do
@io.readlines(">")
- @io.pos.should eql(18)
+ @io.pos.should.eql?(18)
end
it "updates self's lineno based on the number of read lines" do
@io.readlines(">")
- @io.lineno.should eql(4)
+ @io.lineno.should.eql?(4)
end
it "does not change $_" do
@@ -61,12 +61,12 @@ describe "StringIO#readlines when passed no argument" do
it "updates self's position based on the number of read bytes" do
@io.readlines
- @io.pos.should eql(41)
+ @io.pos.should.eql?(41)
end
it "updates self's lineno based on the number of read lines" do
@io.readlines
- @io.lineno.should eql(3)
+ @io.lineno.should.eql?(3)
end
it "does not change $_" do
@@ -84,11 +84,11 @@ end
describe "StringIO#readlines when in write-only mode" do
it "raises an IOError" do
io = StringIO.new(+"xyz", "w")
- -> { io.readlines }.should raise_error(IOError)
+ -> { io.readlines }.should.raise(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.readlines }.should raise_error(IOError)
+ -> { io.readlines }.should.raise(IOError)
end
end
@@ -109,7 +109,7 @@ describe "StringIO#readlines when passed [limit]" do
end
it "raises ArgumentError when limit is 0" do
- -> { @io.readlines(0) }.should raise_error(ArgumentError)
+ -> { @io.readlines(0) }.should.raise(ArgumentError)
end
it "ignores it when the limit is negative" do
diff --git a/spec/ruby/library/stringio/readpartial_spec.rb b/spec/ruby/library/stringio/readpartial_spec.rb
index f25cef4014..e05d9bded4 100644
--- a/spec/ruby/library/stringio/readpartial_spec.rb
+++ b/spec/ruby/library/stringio/readpartial_spec.rb
@@ -10,13 +10,7 @@ describe "StringIO#readpartial" do
@string.close unless @string.closed?
end
- it "raises IOError on closed stream" do
- @string.close
- -> { @string.readpartial(10) }.should raise_error(IOError)
- end
-
it "reads at most the specified number of bytes" do
-
# buffered read
@string.read(1).should == 'S'
# return only specified number, not the whole buffer
@@ -30,6 +24,14 @@ describe "StringIO#readpartial" do
@string.readpartial(3).should == ", l"
end
+ it "reads after ungetc with multibyte characters in the buffer" do
+ @string = StringIO.new(+"∂φ/∂x = gaîté")
+ c = @string.getc
+ @string.ungetc(c)
+ @string.readpartial(3).should == "\xE2\x88\x82".b
+ @string.readpartial(3).should == "\xCF\x86/".b
+ end
+
it "reads after ungetc without data in the buffer" do
@string = StringIO.new
@string.write("f").should == 1
@@ -55,26 +57,46 @@ describe "StringIO#readpartial" do
it "raises EOFError on EOF" do
@string.readpartial(18).should == 'Stop, look, listen'
- -> { @string.readpartial(10) }.should raise_error(EOFError)
+ -> { @string.readpartial(10) }.should.raise(EOFError)
end
it "discards the existing buffer content upon error" do
buffer = +'hello'
@string.readpartial(100)
- -> { @string.readpartial(1, buffer) }.should raise_error(EOFError)
- buffer.should be_empty
+ -> { @string.readpartial(1, buffer) }.should.raise(EOFError)
+ buffer.should.empty?
end
it "raises IOError if the stream is closed" do
@string.close
- -> { @string.readpartial(1) }.should raise_error(IOError)
+ -> { @string.readpartial(1) }.should.raise(IOError, "not opened for reading")
end
it "raises ArgumentError if the negative argument is provided" do
- -> { @string.readpartial(-1) }.should raise_error(ArgumentError)
+ -> { @string.readpartial(-1) }.should.raise(ArgumentError, "negative length -1 given")
end
it "immediately returns an empty string if the length argument is 0" do
@string.readpartial(0).should == ""
end
+
+ it "raises IOError if the stream is closed and the length argument is 0" do
+ @string.close
+ -> { @string.readpartial(0) }.should.raise(IOError, "not opened for reading")
+ end
+
+ it "clears and returns the given buffer if the length argument is 0" do
+ buffer = +"existing content"
+ @string.readpartial(0, buffer).should == buffer
+ buffer.should == ""
+ end
+
+ version_is StringIO::VERSION, "3.1.2" do # ruby_version_is "3.4"
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ @string.readpartial(10, buffer)
+
+ buffer.encoding.should == Encoding::ISO_8859_1
+ end
+ end
end
diff --git a/spec/ruby/library/stringio/reopen_spec.rb b/spec/ruby/library/stringio/reopen_spec.rb
index 7021ff17e5..3d4ae3a698 100644
--- a/spec/ruby/library/stringio/reopen_spec.rb
+++ b/spec/ruby/library/stringio/reopen_spec.rb
@@ -8,18 +8,18 @@ describe "StringIO#reopen when passed [Object, Integer]" do
it "reopens self with the passed Object in the passed mode" do
@io.reopen("reopened", IO::RDONLY)
- @io.closed_read?.should be_false
- @io.closed_write?.should be_true
+ @io.closed_read?.should == false
+ @io.closed_write?.should == true
@io.string.should == "reopened"
@io.reopen(+"reopened, twice", IO::WRONLY)
- @io.closed_read?.should be_true
- @io.closed_write?.should be_false
+ @io.closed_read?.should == true
+ @io.closed_write?.should == false
@io.string.should == "reopened, twice"
@io.reopen(+"reopened, another time", IO::RDWR)
- @io.closed_read?.should be_false
- @io.closed_write?.should be_false
+ @io.closed_read?.should == false
+ @io.closed_write?.should == false
@io.string.should == "reopened, another time"
end
@@ -31,16 +31,16 @@ describe "StringIO#reopen when passed [Object, Integer]" do
end
it "raises a TypeError when the passed Object can't be converted to a String" do
- -> { @io.reopen(Object.new, IO::RDWR) }.should raise_error(TypeError)
+ -> { @io.reopen(Object.new, IO::RDWR) }.should.raise(TypeError)
end
it "raises an Errno::EACCES when trying to reopen self with a frozen String in write-mode" do
- -> { @io.reopen("burn".freeze, IO::WRONLY) }.should raise_error(Errno::EACCES)
- -> { @io.reopen("burn".freeze, IO::WRONLY | IO::APPEND) }.should raise_error(Errno::EACCES)
+ -> { @io.reopen("burn".freeze, IO::WRONLY) }.should.raise(Errno::EACCES)
+ -> { @io.reopen("burn".freeze, IO::WRONLY | IO::APPEND) }.should.raise(Errno::EACCES)
end
it "raises a FrozenError when trying to reopen self with a frozen String in truncate-mode" do
- -> { @io.reopen("burn".freeze, IO::RDONLY | IO::TRUNC) }.should raise_error(FrozenError)
+ -> { @io.reopen("burn".freeze, IO::RDONLY | IO::TRUNC) }.should.raise(FrozenError)
end
it "does not raise IOError when passed a frozen String in read-mode" do
@@ -56,23 +56,23 @@ describe "StringIO#reopen when passed [Object, Object]" do
it "reopens self with the passed Object in the passed mode" do
@io.reopen("reopened", "r")
- @io.closed_read?.should be_false
- @io.closed_write?.should be_true
+ @io.closed_read?.should == false
+ @io.closed_write?.should == true
@io.string.should == "reopened"
@io.reopen(+"reopened, twice", "r+")
- @io.closed_read?.should be_false
- @io.closed_write?.should be_false
+ @io.closed_read?.should == false
+ @io.closed_write?.should == false
@io.string.should == "reopened, twice"
@io.reopen(+"reopened, another", "w+")
- @io.closed_read?.should be_false
- @io.closed_write?.should be_false
+ @io.closed_read?.should == false
+ @io.closed_write?.should == false
@io.string.should == ""
@io.reopen(+"reopened, another time", "r+")
- @io.closed_read?.should be_false
- @io.closed_write?.should be_false
+ @io.closed_read?.should == false
+ @io.closed_write?.should == false
@io.string.should == "reopened, another time"
end
@@ -89,35 +89,35 @@ describe "StringIO#reopen when passed [Object, Object]" do
end
it "raises a TypeError when the passed Object can't be converted to a String using #to_str" do
- -> { @io.reopen(Object.new, "r") }.should raise_error(TypeError)
+ -> { @io.reopen(Object.new, "r") }.should.raise(TypeError)
end
it "resets self's position to 0" do
@io.read(5)
@io.reopen(+"reopened")
- @io.pos.should eql(0)
+ @io.pos.should.eql?(0)
end
it "resets self's line number to 0" do
@io.gets
@io.reopen(+"reopened")
- @io.lineno.should eql(0)
+ @io.lineno.should.eql?(0)
end
it "tries to convert the passed mode Object to an Integer using #to_str" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return("r")
@io.reopen("reopened", obj)
- @io.closed_read?.should be_false
- @io.closed_write?.should be_true
+ @io.closed_read?.should == false
+ @io.closed_write?.should == true
@io.string.should == "reopened"
end
it "raises an Errno::EACCES error when trying to reopen self with a frozen String in write-mode" do
- -> { @io.reopen("burn".freeze, 'w') }.should raise_error(Errno::EACCES)
- -> { @io.reopen("burn".freeze, 'w+') }.should raise_error(Errno::EACCES)
- -> { @io.reopen("burn".freeze, 'a') }.should raise_error(Errno::EACCES)
- -> { @io.reopen("burn".freeze, "r+") }.should raise_error(Errno::EACCES)
+ -> { @io.reopen("burn".freeze, 'w') }.should.raise(Errno::EACCES)
+ -> { @io.reopen("burn".freeze, 'w+') }.should.raise(Errno::EACCES)
+ -> { @io.reopen("burn".freeze, 'a') }.should.raise(Errno::EACCES)
+ -> { @io.reopen("burn".freeze, "r+") }.should.raise(Errno::EACCES)
end
it "does not raise IOError if a frozen string is passed in read mode" do
@@ -136,8 +136,8 @@ describe "StringIO#reopen when passed [String]" do
@io.reopen(+"reopened")
- @io.closed_write?.should be_false
- @io.closed_read?.should be_false
+ @io.closed_write?.should == false
+ @io.closed_read?.should == false
@io.string.should == "reopened"
end
@@ -145,13 +145,13 @@ describe "StringIO#reopen when passed [String]" do
it "resets self's position to 0" do
@io.read(5)
@io.reopen(+"reopened")
- @io.pos.should eql(0)
+ @io.pos.should.eql?(0)
end
it "resets self's line number to 0" do
@io.gets
@io.reopen(+"reopened")
- @io.lineno.should eql(0)
+ @io.lineno.should.eql?(0)
end
end
@@ -161,13 +161,13 @@ describe "StringIO#reopen when passed [Object]" do
end
it "raises a TypeError when passed an Object that can't be converted to a StringIO" do
- -> { @io.reopen(Object.new) }.should raise_error(TypeError)
+ -> { @io.reopen(Object.new) }.should.raise(TypeError)
end
it "does not try to convert the passed Object to a String using #to_str" do
obj = mock("not to_str")
obj.should_not_receive(:to_str)
- -> { @io.reopen(obj) }.should raise_error(TypeError)
+ -> { @io.reopen(obj) }.should.raise(TypeError)
end
it "tries to convert the passed Object to a StringIO using #to_strio" do
@@ -186,20 +186,20 @@ describe "StringIO#reopen when passed no arguments" do
it "resets self's mode to read-write" do
@io.close
@io.reopen
- @io.closed_read?.should be_false
- @io.closed_write?.should be_false
+ @io.closed_read?.should == false
+ @io.closed_write?.should == false
end
it "resets self's position to 0" do
@io.read(5)
@io.reopen
- @io.pos.should eql(0)
+ @io.pos.should.eql?(0)
end
it "resets self's line number to 0" do
@io.gets
@io.reopen
- @io.lineno.should eql(0)
+ @io.lineno.should.eql?(0)
end
end
diff --git a/spec/ruby/library/stringio/rewind_spec.rb b/spec/ruby/library/stringio/rewind_spec.rb
index 5f885ecf81..8c48709d89 100644
--- a/spec/ruby/library/stringio/rewind_spec.rb
+++ b/spec/ruby/library/stringio/rewind_spec.rb
@@ -9,7 +9,7 @@ describe "StringIO#rewind" do
end
it "returns 0" do
- @io.rewind.should eql(0)
+ @io.rewind.should.eql?(0)
end
it "resets the position" do
diff --git a/spec/ruby/library/stringio/seek_spec.rb b/spec/ruby/library/stringio/seek_spec.rb
index 253b5027a9..9043e0338f 100644
--- a/spec/ruby/library/stringio/seek_spec.rb
+++ b/spec/ruby/library/stringio/seek_spec.rb
@@ -9,18 +9,18 @@ describe "StringIO#seek" do
it "seeks from the current position when whence is IO::SEEK_CUR" do
@io.pos = 1
@io.seek(1, IO::SEEK_CUR)
- @io.pos.should eql(2)
+ @io.pos.should.eql?(2)
@io.seek(-1, IO::SEEK_CUR)
- @io.pos.should eql(1)
+ @io.pos.should.eql?(1)
end
it "seeks from the end of self when whence is IO::SEEK_END" do
@io.seek(3, IO::SEEK_END)
- @io.pos.should eql(11) # Outside of the StringIO's content
+ @io.pos.should.eql?(11) # Outside of the StringIO's content
@io.seek(-2, IO::SEEK_END)
- @io.pos.should eql(6)
+ @io.pos.should.eql?(6)
end
it "seeks to an absolute position when whence is IO::SEEK_SET" do
@@ -33,25 +33,25 @@ describe "StringIO#seek" do
end
it "raises an Errno::EINVAL error on negative amounts when whence is IO::SEEK_SET" do
- -> { @io.seek(-5, IO::SEEK_SET) }.should raise_error(Errno::EINVAL)
+ -> { @io.seek(-5, IO::SEEK_SET) }.should.raise(Errno::EINVAL)
end
it "raises an Errno::EINVAL error on incorrect whence argument" do
- -> { @io.seek(0, 3) }.should raise_error(Errno::EINVAL)
- -> { @io.seek(0, -1) }.should raise_error(Errno::EINVAL)
- -> { @io.seek(0, 2**16) }.should raise_error(Errno::EINVAL)
- -> { @io.seek(0, -2**16) }.should raise_error(Errno::EINVAL)
+ -> { @io.seek(0, 3) }.should.raise(Errno::EINVAL)
+ -> { @io.seek(0, -1) }.should.raise(Errno::EINVAL)
+ -> { @io.seek(0, 2**16) }.should.raise(Errno::EINVAL)
+ -> { @io.seek(0, -2**16) }.should.raise(Errno::EINVAL)
end
it "tries to convert the passed Object to a String using #to_int" do
obj = mock("to_int")
obj.should_receive(:to_int).and_return(2)
@io.seek(obj)
- @io.pos.should eql(2)
+ @io.pos.should.eql?(2)
end
it "raises a TypeError when the passed Object can't be converted to an Integer" do
- -> { @io.seek(Object.new) }.should raise_error(TypeError)
+ -> { @io.seek(Object.new) }.should.raise(TypeError)
end
end
@@ -62,6 +62,6 @@ describe "StringIO#seek when self is closed" do
end
it "raises an IOError" do
- -> { @io.seek(5) }.should raise_error(IOError)
+ -> { @io.seek(5) }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb b/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb
index 1030aad042..b4583a7ad7 100644
--- a/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb
+++ b/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb
@@ -6,7 +6,7 @@ describe "StringIO#set_encoding_by_bom" do
it "returns nil if not readable" do
io = StringIO.new("".b, "wb")
- io.set_encoding_by_bom.should be_nil
+ io.set_encoding_by_bom.should == nil
io.external_encoding.should == Encoding::ASCII_8BIT
end
@@ -82,7 +82,7 @@ describe "StringIO#set_encoding_by_bom" do
it "returns nil if io is empty" do
io = StringIO.new("".b, "rb")
- io.set_encoding_by_bom.should be_nil
+ io.set_encoding_by_bom.should == nil
io.external_encoding.should == Encoding::ASCII_8BIT
end
@@ -227,7 +227,7 @@ describe "StringIO#set_encoding_by_bom" do
it "raises FrozenError when io is frozen" do
io = StringIO.new()
io.freeze
- -> { io.set_encoding_by_bom }.should raise_error(FrozenError)
+ -> { io.set_encoding_by_bom }.should.raise(FrozenError)
end
it "does not raise FrozenError when initial string is frozen" do
diff --git a/spec/ruby/library/stringio/shared/codepoints.rb b/spec/ruby/library/stringio/shared/codepoints.rb
index 25333bb0fd..e35a02ccb4 100644
--- a/spec/ruby/library/stringio/shared/codepoints.rb
+++ b/spec/ruby/library/stringio/shared/codepoints.rb
@@ -6,7 +6,7 @@ describe :stringio_codepoints, shared: true do
end
it "returns an Enumerator" do
- @enum.should be_an_instance_of(Enumerator)
+ @enum.should.instance_of?(Enumerator)
end
it "yields each codepoint code in turn" do
@@ -20,15 +20,15 @@ describe :stringio_codepoints, shared: true do
it "raises an error if reading invalid sequence" do
@io.pos = 1 # inside of a multibyte sequence
- -> { @enum.first }.should raise_error(ArgumentError)
+ -> { @enum.first }.should.raise(ArgumentError)
end
it "raises an IOError if not readable" do
@io.close_read
- -> { @enum.to_a }.should raise_error(IOError)
+ -> { @enum.to_a }.should.raise(IOError)
io = StringIO.new(+"xyz", "w")
- -> { io.send(@method).to_a }.should raise_error(IOError)
+ -> { io.send(@method).to_a }.should.raise(IOError)
end
@@ -39,7 +39,7 @@ describe :stringio_codepoints, shared: true do
end
it "returns self" do
- @io.send(@method) {|l| l }.should equal(@io)
+ @io.send(@method) {|l| l }.should.equal?(@io)
end
end
diff --git a/spec/ruby/library/stringio/shared/each.rb b/spec/ruby/library/stringio/shared/each.rb
index e0dd3f9b8f..04e40b6b2a 100644
--- a/spec/ruby/library/stringio/shared/each.rb
+++ b/spec/ruby/library/stringio/shared/each.rb
@@ -16,7 +16,7 @@ describe :stringio_each_separator, shared: true do
end
it "returns self" do
- @io.send(@method) {|l| l }.should equal(@io)
+ @io.send(@method) {|l| l }.should.equal?(@io)
end
it "tries to convert the passed separator to a String using #to_str" do
@@ -36,22 +36,11 @@ describe :stringio_each_separator, shared: true do
seen.should == ["2 1 2 1 2"]
end
- version_is StringIO::VERSION, ""..."3.0.4" do #ruby_version_is ""..."3.2" do
- it "yields each paragraph with two separation characters when passed an empty String as separator" do
- seen = []
- io = StringIO.new("para1\n\npara2\n\n\npara3")
- io.send(@method, "") {|s| seen << s}
- seen.should == ["para1\n\n", "para2\n\n", "para3"]
- end
- end
-
- version_is StringIO::VERSION, "3.0.4" do #ruby_version_is "3.2" do
- it "yields each paragraph with all separation characters when passed an empty String as separator" do
- seen = []
- io = StringIO.new("para1\n\npara2\n\n\npara3")
- io.send(@method, "") {|s| seen << s}
- seen.should == ["para1\n\n", "para2\n\n\n", "para3"]
- end
+ it "yields each paragraph with all separation characters when passed an empty String as separator" do
+ seen = []
+ io = StringIO.new("para1\n\npara2\n\n\npara3")
+ io.send(@method, "") {|s| seen << s}
+ seen.should == ["para1\n\n", "para2\n\n\n", "para3"]
end
end
@@ -85,19 +74,19 @@ describe :stringio_each_no_arguments, shared: true do
old_rs = $/
suppress_warning {$/ = " "}
@io.send(@method) {|s| seen << s }
- seen.should eql(["a ", "b ", "c ", "d ", "e\n1 ", "2 ", "3 ", "4 ", "5"])
+ seen.should.eql?(["a ", "b ", "c ", "d ", "e\n1 ", "2 ", "3 ", "4 ", "5"])
ensure
suppress_warning {$/ = old_rs}
end
end
it "returns self" do
- @io.send(@method) {|l| l }.should equal(@io)
+ @io.send(@method) {|l| l }.should.equal?(@io)
end
it "returns an Enumerator when passed no block" do
enum = @io.send(@method)
- enum.instance_of?(Enumerator).should be_true
+ enum.instance_of?(Enumerator).should == true
seen = []
enum.each { |b| seen << b }
@@ -108,11 +97,11 @@ end
describe :stringio_each_not_readable, shared: true do
it "raises an IOError" do
io = StringIO.new(+"a b c d e", "w")
- -> { io.send(@method) { |b| b } }.should raise_error(IOError)
+ -> { io.send(@method) { |b| b } }.should.raise(IOError)
io = StringIO.new("a b c d e")
io.close_read
- -> { io.send(@method) { |b| b } }.should raise_error(IOError)
+ -> { io.send(@method) { |b| b } }.should.raise(IOError)
end
end
@@ -161,3 +150,60 @@ describe :stringio_each_limit, shared: true do
seen.should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"]
end
end
+
+describe :stringio_each_separator_and_limit, shared: true do
+ before :each do
+ @io = StringIO.new("this>is>an>example")
+ end
+
+ it "returns the data read until the limit is consumed or the separator is met" do
+ @io.send(@method, '>', 8) { |s| break s }.should == "this>"
+ @io.send(@method, '>', 2) { |s| break s }.should == "is"
+ @io.send(@method, '>', 10) { |s| break s }.should == ">"
+ @io.send(@method, '>', 6) { |s| break s }.should == "an>"
+ @io.send(@method, '>', 5) { |s| break s }.should == "examp"
+ end
+
+ it "truncates the multi-character separator at the end to meet the limit" do
+ @io.send(@method, "is>an", 7) { |s| break s }.should == "this>is"
+ end
+
+ it "does not change $_" do
+ $_ = "test"
+ @io.send(@method, '>', 8) { |s| s }
+ $_.should == "test"
+ end
+
+ it "updates self's lineno by one" do
+ @io.send(@method, '>', 3) { |s| break s }
+ @io.lineno.should.eql?(1)
+
+ @io.send(@method, '>', 3) { |s| break s }
+ @io.lineno.should.eql?(2)
+
+ @io.send(@method, '>', 3) { |s| break s }
+ @io.lineno.should.eql?(3)
+ end
+
+ it "tries to convert the passed separator to a String using #to_str" do # TODO
+ obj = mock('to_str')
+ obj.should_receive(:to_str).and_return('>')
+
+ seen = []
+ @io.send(@method, obj, 5) { |s| seen << s }
+ seen.should == ["this>", "is>", "an>", "examp", "le"]
+ end
+
+ it "does not raise TypeError if passed separator is nil" do
+ @io.send(@method, nil, 5) { |s| break s }.should == "this>"
+ end
+
+ it "tries to convert the passed limit to an Integer using #to_int" do # TODO
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(5)
+
+ seen = []
+ @io.send(@method, '>', obj) { |s| seen << s }
+ seen.should == ["this>", "is>", "an>", "examp", "le"]
+ end
+end
diff --git a/spec/ruby/library/stringio/shared/each_byte.rb b/spec/ruby/library/stringio/shared/each_byte.rb
index b51fa38f2f..b3939c26de 100644
--- a/spec/ruby/library/stringio/shared/each_byte.rb
+++ b/spec/ruby/library/stringio/shared/each_byte.rb
@@ -19,16 +19,16 @@ describe :stringio_each_byte, shared: true do
@io.pos = 1000
seen = nil
@io.send(@method) { |b| seen = b }
- seen.should be_nil
+ seen.should == nil
end
it "returns self" do
- @io.send(@method) {}.should equal(@io)
+ @io.send(@method) {}.should.equal?(@io)
end
it "returns an Enumerator when passed no block" do
enum = @io.send(@method)
- enum.instance_of?(Enumerator).should be_true
+ enum.instance_of?(Enumerator).should == true
seen = []
enum.each { |b| seen << b }
@@ -39,10 +39,10 @@ end
describe :stringio_each_byte_not_readable, shared: true do
it "raises an IOError" do
io = StringIO.new(+"xyz", "w")
- -> { io.send(@method) { |b| b } }.should raise_error(IOError)
+ -> { io.send(@method) { |b| b } }.should.raise(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.send(@method) { |b| b } }.should raise_error(IOError)
+ -> { io.send(@method) { |b| b } }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/shared/each_char.rb b/spec/ruby/library/stringio/shared/each_char.rb
index 197237c1c8..4215a9952b 100644
--- a/spec/ruby/library/stringio/shared/each_char.rb
+++ b/spec/ruby/library/stringio/shared/each_char.rb
@@ -11,12 +11,12 @@ describe :stringio_each_char, shared: true do
end
it "returns self" do
- @io.send(@method) {}.should equal(@io)
+ @io.send(@method) {}.should.equal?(@io)
end
it "returns an Enumerator when passed no block" do
enum = @io.send(@method)
- enum.instance_of?(Enumerator).should be_true
+ enum.instance_of?(Enumerator).should == true
seen = []
enum.each { |c| seen << c }
@@ -27,10 +27,10 @@ end
describe :stringio_each_char_not_readable, shared: true do
it "raises an IOError" do
io = StringIO.new(+"xyz", "w")
- -> { io.send(@method) { |b| b } }.should raise_error(IOError)
+ -> { io.send(@method) { |b| b } }.should.raise(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.send(@method) { |b| b } }.should raise_error(IOError)
+ -> { io.send(@method) { |b| b } }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/shared/eof.rb b/spec/ruby/library/stringio/shared/eof.rb
index e0368a2892..a9489581fc 100644
--- a/spec/ruby/library/stringio/shared/eof.rb
+++ b/spec/ruby/library/stringio/shared/eof.rb
@@ -5,20 +5,20 @@ describe :stringio_eof, shared: true do
it "returns true when self's position is greater than or equal to self's size" do
@io.pos = 3
- @io.send(@method).should be_true
+ @io.send(@method).should == true
@io.pos = 6
- @io.send(@method).should be_true
+ @io.send(@method).should == true
end
it "returns false when self's position is less than self's size" do
@io.pos = 0
- @io.send(@method).should be_false
+ @io.send(@method).should == false
@io.pos = 1
- @io.send(@method).should be_false
+ @io.send(@method).should == false
@io.pos = 2
- @io.send(@method).should be_false
+ @io.send(@method).should == false
end
end
diff --git a/spec/ruby/library/stringio/shared/getc.rb b/spec/ruby/library/stringio/shared/getc.rb
index ba65040bce..a146b2d4cf 100644
--- a/spec/ruby/library/stringio/shared/getc.rb
+++ b/spec/ruby/library/stringio/shared/getc.rb
@@ -5,39 +5,39 @@ describe :stringio_getc, shared: true do
it "increases self's position by one" do
@io.send(@method)
- @io.pos.should eql(1)
+ @io.pos.should.eql?(1)
@io.send(@method)
- @io.pos.should eql(2)
+ @io.pos.should.eql?(2)
@io.send(@method)
- @io.pos.should eql(3)
+ @io.pos.should.eql?(3)
end
it "returns nil when called at the end of self" do
@io.pos = 7
- @io.send(@method).should be_nil
- @io.send(@method).should be_nil
- @io.send(@method).should be_nil
+ @io.send(@method).should == nil
+ @io.send(@method).should == nil
+ @io.send(@method).should == nil
end
it "does not increase self's position when called at the end of file" do
@io.pos = 7
@io.send(@method)
- @io.pos.should eql(7)
+ @io.pos.should.eql?(7)
@io.send(@method)
- @io.pos.should eql(7)
+ @io.pos.should.eql?(7)
end
end
describe :stringio_getc_not_readable, shared: true do
it "raises an IOError" do
io = StringIO.new(+"xyz", "w")
- -> { io.send(@method) }.should raise_error(IOError)
+ -> { io.send(@method) }.should.raise(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.send(@method) }.should raise_error(IOError)
+ -> { io.send(@method) }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/shared/gets.rb b/spec/ruby/library/stringio/shared/gets.rb
new file mode 100644
index 0000000000..16039b18ef
--- /dev/null
+++ b/spec/ruby/library/stringio/shared/gets.rb
@@ -0,0 +1,249 @@
+describe :stringio_gets_separator, shared: true do
+ describe "when passed [separator]" do
+ before :each do
+ @io = StringIO.new("this>is>an>example")
+ end
+
+ it "returns the data read till the next occurrence of the passed separator" do
+ @io.send(@method, ">").should == "this>"
+ @io.send(@method, ">").should == "is>"
+ @io.send(@method, ">").should == "an>"
+ @io.send(@method, ">").should == "example"
+ end
+
+ it "sets $_ to the read content" do
+ @io.send(@method, ">")
+ $_.should == "this>"
+ @io.send(@method, ">")
+ $_.should == "is>"
+ @io.send(@method, ">")
+ $_.should == "an>"
+ @io.send(@method, ">")
+ $_.should == "example"
+ end
+
+ it "accepts string as separator" do
+ @io.send(@method, "is>")
+ $_.should == "this>"
+ @io.send(@method, "an>")
+ $_.should == "is>an>"
+ @io.send(@method, "example")
+ $_.should == "example"
+ end
+
+ it "updates self's lineno by one" do
+ @io.send(@method, ">")
+ @io.lineno.should.eql?(1)
+
+ @io.send(@method, ">")
+ @io.lineno.should.eql?(2)
+
+ @io.send(@method, ">")
+ @io.lineno.should.eql?(3)
+ end
+
+ it "returns the next paragraph when the passed separator is an empty String" do
+ io = StringIO.new("this is\n\nan example")
+ io.send(@method, "").should == "this is\n\n"
+ io.send(@method, "").should == "an example"
+ end
+
+ it "returns the remaining content starting at the current position when passed nil" do
+ io = StringIO.new("this is\n\nan example")
+ io.pos = 5
+ io.send(@method, nil).should == "is\n\nan example"
+ end
+
+ it "tries to convert the passed separator to a String using #to_str" do
+ obj = mock('to_str')
+ obj.should_receive(:to_str).and_return(">")
+ @io.send(@method, obj).should == "this>"
+ end
+ end
+end
+
+describe :stringio_gets_limit, shared: true do
+ describe "when passed [limit]" do
+ before :each do
+ @io = StringIO.new("this>is>an>example")
+ end
+
+ it "returns the data read until the limit is met" do
+ @io.send(@method, 4).should == "this"
+ @io.send(@method, 3).should == ">is"
+ @io.send(@method, 5).should == ">an>e"
+ @io.send(@method, 6).should == "xample"
+ end
+
+ it "sets $_ to the read content" do
+ @io.send(@method, 4)
+ $_.should == "this"
+ @io.send(@method, 3)
+ $_.should == ">is"
+ @io.send(@method, 5)
+ $_.should == ">an>e"
+ @io.send(@method, 6)
+ $_.should == "xample"
+ end
+
+ it "updates self's lineno by one" do
+ @io.send(@method, 3)
+ @io.lineno.should.eql?(1)
+
+ @io.send(@method, 3)
+ @io.lineno.should.eql?(2)
+
+ @io.send(@method, 3)
+ @io.lineno.should.eql?(3)
+ end
+
+ it "tries to convert the passed limit to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(4)
+ @io.send(@method, obj).should == "this"
+ end
+
+ it "returns a blank string when passed a limit of 0" do
+ @io.send(@method, 0).should == ""
+ end
+
+ it "ignores it when passed a negative limit" do
+ @io.send(@method, -4).should == "this>is>an>example"
+ end
+ end
+end
+
+describe :stringio_gets_separator_and_limit, shared: true do
+ describe "when passed [separator] and [limit]" do
+ before :each do
+ @io = StringIO.new("this>is>an>example")
+ end
+
+ it "returns the data read until the limit is consumed or the separator is met" do
+ @io.send(@method, '>', 8).should == "this>"
+ @io.send(@method, '>', 2).should == "is"
+ @io.send(@method, '>', 10).should == ">"
+ @io.send(@method, '>', 6).should == "an>"
+ @io.send(@method, '>', 5).should == "examp"
+ end
+
+ it "truncates the multi-character separator at the end to meet the limit" do
+ @io.send(@method, "is>an", 7).should == "this>is"
+ end
+
+ it "sets $_ to the read content" do
+ @io.send(@method, '>', 8)
+ $_.should == "this>"
+ @io.send(@method, '>', 2)
+ $_.should == "is"
+ @io.send(@method, '>', 10)
+ $_.should == ">"
+ @io.send(@method, '>', 6)
+ $_.should == "an>"
+ @io.send(@method, '>', 5)
+ $_.should == "examp"
+ end
+
+ it "updates self's lineno by one" do
+ @io.send(@method, '>', 3)
+ @io.lineno.should.eql?(1)
+
+ @io.send(@method, '>', 3)
+ @io.lineno.should.eql?(2)
+
+ @io.send(@method, '>', 3)
+ @io.lineno.should.eql?(3)
+ end
+
+ it "tries to convert the passed separator to a String using #to_str" do
+ obj = mock('to_str')
+ obj.should_receive(:to_str).and_return('>')
+ @io.send(@method, obj, 5).should == "this>"
+ end
+
+ it "does not raise TypeError if passed separator is nil" do
+ @io.send(@method, nil, 5).should == "this>"
+ end
+
+ it "tries to convert the passed limit to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(5)
+ @io.send(@method, '>', obj).should == "this>"
+ end
+ end
+end
+
+describe :stringio_gets_no_argument, shared: true do
+ describe "when passed no argument" do
+ before :each do
+ @io = StringIO.new("this is\nan example\nfor StringIO#gets")
+ end
+
+ it "returns the data read till the next occurrence of $/ or till eof" do
+ @io.send(@method).should == "this is\n"
+
+ begin
+ old_sep = $/
+ suppress_warning {$/ = " "}
+ @io.send(@method).should == "an "
+ @io.send(@method).should == "example\nfor "
+ @io.send(@method).should == "StringIO#gets"
+ ensure
+ suppress_warning {$/ = old_sep}
+ end
+ end
+
+ it "sets $_ to the read content" do
+ @io.send(@method)
+ $_.should == "this is\n"
+ @io.send(@method)
+ $_.should == "an example\n"
+ @io.send(@method)
+ $_.should == "for StringIO#gets"
+ end
+
+ it "updates self's position" do
+ @io.send(@method)
+ @io.pos.should.eql?(8)
+
+ @io.send(@method)
+ @io.pos.should.eql?(19)
+
+ @io.send(@method)
+ @io.pos.should.eql?(36)
+ end
+
+ it "updates self's lineno" do
+ @io.send(@method)
+ @io.lineno.should.eql?(1)
+
+ @io.send(@method)
+ @io.lineno.should.eql?(2)
+
+ @io.send(@method)
+ @io.lineno.should.eql?(3)
+ end
+ end
+end
+
+describe :stringio_gets_chomp, shared: true do
+ describe "when passed [chomp]" do
+ it "returns the data read without a trailing newline character" do
+ io = StringIO.new("this>is>an>example\n")
+ io.send(@method, chomp: true).should == "this>is>an>example"
+ end
+ end
+end
+
+describe :stringio_gets_write_only, shared: true do
+ describe "when in write-only mode" do
+ it "raises an IOError" do
+ io = StringIO.new(+"xyz", "w")
+ -> { io.send(@method) }.should.raise(IOError)
+
+ io = StringIO.new("xyz")
+ io.close_read
+ -> { io.send(@method) }.should.raise(IOError)
+ end
+ end
+end
diff --git a/spec/ruby/library/stringio/shared/isatty.rb b/spec/ruby/library/stringio/shared/isatty.rb
index c9e7ee7321..2b92e8d656 100644
--- a/spec/ruby/library/stringio/shared/isatty.rb
+++ b/spec/ruby/library/stringio/shared/isatty.rb
@@ -1,5 +1,5 @@
describe :stringio_isatty, shared: true do
it "returns false" do
- StringIO.new("tty").send(@method).should be_false
+ StringIO.new("tty").send(@method).should == false
end
end
diff --git a/spec/ruby/library/stringio/shared/read.rb b/spec/ruby/library/stringio/shared/read.rb
index 8ef6ec2734..6e04e75dba 100644
--- a/spec/ruby/library/stringio/shared/read.rb
+++ b/spec/ruby/library/stringio/shared/read.rb
@@ -5,9 +5,9 @@ describe :stringio_read, shared: true do
it "returns the passed buffer String" do
# Note: Rubinius bug:
- # @io.send(@method, 7, buffer = +"").should equal(buffer)
+ # @io.send(@method, 7, buffer = +"").should.equal?(buffer)
ret = @io.send(@method, 7, buffer = +"")
- ret.should equal(buffer)
+ ret.should.equal?(buffer)
end
it "reads length bytes and writes them to the buffer String" do
@@ -15,7 +15,7 @@ describe :stringio_read, shared: true do
buffer.should == "example"
end
- ruby_version_is ""..."3.4" do
+ guard -> { StringIO::VERSION < "3.1.2" } do
it "does not preserve the encoding of the given buffer" do
buffer = ''.encode(Encoding::ISO_8859_1)
@io.send(@method, 7, buffer)
@@ -24,7 +24,7 @@ describe :stringio_read, shared: true do
end
end
- ruby_version_is "3.4" do
+ guard -> { StringIO::VERSION >= "3.1.2" } do
it "preserves the encoding of the given buffer" do
buffer = ''.encode(Encoding::ISO_8859_1)
@io.send(@method, 7, buffer)
@@ -42,11 +42,11 @@ describe :stringio_read, shared: true do
end
it "raises a TypeError when the passed buffer Object can't be converted to a String" do
- -> { @io.send(@method, 7, Object.new) }.should raise_error(TypeError)
+ -> { @io.send(@method, 7, Object.new) }.should.raise(TypeError)
end
it "raises a FrozenError error when passed a frozen String as buffer" do
- -> { @io.send(@method, 7, "".freeze) }.should raise_error(FrozenError)
+ -> { @io.send(@method, 7, "".freeze) }.should.raise(FrozenError)
end
end
@@ -66,10 +66,10 @@ describe :stringio_read_length, shared: true do
it "correctly updates the position" do
@io.send(@method, 3)
- @io.pos.should eql(3)
+ @io.pos.should.eql?(3)
@io.send(@method, 999)
- @io.pos.should eql(7)
+ @io.pos.should.eql?(7)
end
it "tries to convert the passed length to an Integer using #to_int" do
@@ -79,11 +79,11 @@ describe :stringio_read_length, shared: true do
end
it "raises a TypeError when the passed length can't be converted to an Integer" do
- -> { @io.send(@method, Object.new) }.should raise_error(TypeError)
+ -> { @io.send(@method, Object.new) }.should.raise(TypeError)
end
it "raises a TypeError when the passed length is negative" do
- -> { @io.send(@method, -2) }.should raise_error(ArgumentError)
+ -> { @io.send(@method, -2) }.should.raise(ArgumentError)
end
it "returns a binary String" do
@@ -105,13 +105,13 @@ describe :stringio_read_no_arguments, shared: true do
it "correctly updates the current position" do
@io.send(@method)
- @io.pos.should eql(7)
+ @io.pos.should.eql?(7)
end
it "correctly update the current position in bytes when multi-byte characters are used" do
@io.print("example\u03A3") # Overwrite the original string with 8 characters containing 9 bytes.
@io.send(@method)
- @io.pos.should eql(9)
+ @io.pos.should.eql?(9)
end
end
@@ -129,17 +129,17 @@ describe :stringio_read_nil, shared: true do
it "updates the current position" do
@io.send(@method, nil)
- @io.pos.should eql(7)
+ @io.pos.should.eql?(7)
end
end
describe :stringio_read_not_readable, shared: true do
it "raises an IOError" do
io = StringIO.new(+"test", "w")
- -> { io.send(@method) }.should raise_error(IOError)
+ -> { io.send(@method) }.should.raise(IOError)
io = StringIO.new("test")
io.close_read
- -> { io.send(@method) }.should raise_error(IOError)
+ -> { io.send(@method) }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/shared/readchar.rb b/spec/ruby/library/stringio/shared/readchar.rb
index 72d7446c36..5ac28e0743 100644
--- a/spec/ruby/library/stringio/shared/readchar.rb
+++ b/spec/ruby/library/stringio/shared/readchar.rb
@@ -13,17 +13,17 @@ describe :stringio_readchar, shared: true do
it "raises an EOFError when self is at the end" do
@io.pos = 7
- -> { @io.send(@method) }.should raise_error(EOFError)
+ -> { @io.send(@method) }.should.raise(EOFError)
end
end
describe :stringio_readchar_not_readable, shared: true do
it "raises an IOError" do
io = StringIO.new(+"a b c d e", "w")
- -> { io.send(@method) }.should raise_error(IOError)
+ -> { io.send(@method) }.should.raise(IOError)
io = StringIO.new("a b c d e")
io.close_read
- -> { io.send(@method) }.should raise_error(IOError)
+ -> { io.send(@method) }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/shared/sysread.rb b/spec/ruby/library/stringio/shared/sysread.rb
index 3e23fbc233..bc448d3379 100644
--- a/spec/ruby/library/stringio/shared/sysread.rb
+++ b/spec/ruby/library/stringio/shared/sysread.rb
@@ -10,6 +10,6 @@ describe :stringio_sysread_length, shared: true do
it "raises an EOFError when passed length > 0 and no data remains" do
@io.read.should == "example"
- -> { @io.send(@method, 1) }.should raise_error(EOFError)
+ -> { @io.send(@method, 1) }.should.raise(EOFError)
end
end
diff --git a/spec/ruby/library/stringio/shared/write.rb b/spec/ruby/library/stringio/shared/write.rb
index 4661658baf..b6bffe7f12 100644
--- a/spec/ruby/library/stringio/shared/write.rb
+++ b/spec/ruby/library/stringio/shared/write.rb
@@ -42,7 +42,7 @@ describe :stringio_write_string, shared: true do
it "updates self's position" do
@io.send(@method, 'test')
- @io.pos.should eql(4)
+ @io.pos.should.eql?(4)
end
it "handles concurrent writes correctly" do
@@ -107,11 +107,11 @@ end
describe :stringio_write_not_writable, shared: true do
it "raises an IOError" do
io = StringIO.new(+"test", "r")
- -> { io.send(@method, "test") }.should raise_error(IOError)
+ -> { io.send(@method, "test") }.should.raise(IOError)
io = StringIO.new(+"test")
io.close_write
- -> { io.send(@method, "test") }.should raise_error(IOError)
+ -> { io.send(@method, "test") }.should.raise(IOError)
end
end
@@ -130,6 +130,6 @@ describe :stringio_write_append, shared: true do
it "correctly updates self's position" do
@io.send(@method, ", testing")
- @io.pos.should eql(16)
+ @io.pos.should.eql?(16)
end
end
diff --git a/spec/ruby/library/stringio/string_spec.rb b/spec/ruby/library/stringio/string_spec.rb
index 1ed5233ba6..3b27243da9 100644
--- a/spec/ruby/library/stringio/string_spec.rb
+++ b/spec/ruby/library/stringio/string_spec.rb
@@ -4,7 +4,7 @@ require_relative 'fixtures/classes'
describe "StringIO#string" do
it "returns the underlying string" do
io = StringIO.new(str = "hello")
- io.string.should equal(str)
+ io.string.should.equal?(str)
end
end
@@ -15,25 +15,25 @@ describe "StringIO#string=" do
it "returns the passed String" do
str = "test"
- (@io.string = str).should equal(str)
+ (@io.string = str).should.equal?(str)
end
it "changes the underlying string" do
str = "hello"
@io.string = str
- @io.string.should equal(str)
+ @io.string.should.equal?(str)
end
it "resets the position" do
@io.pos = 1
@io.string = "other"
- @io.pos.should eql(0)
+ @io.pos.should.eql?(0)
end
it "resets the line number" do
@io.lineno = 1
@io.string = "other"
- @io.lineno.should eql(0)
+ @io.lineno.should.eql?(0)
end
it "tries to convert the passed Object to a String using #to_str" do
@@ -45,6 +45,6 @@ describe "StringIO#string=" do
end
it "raises a TypeError when the passed Object can't be converted to an Integer" do
- -> { @io.seek(Object.new) }.should raise_error(TypeError)
+ -> { @io.seek(Object.new) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/stringio/stringio_spec.rb b/spec/ruby/library/stringio/stringio_spec.rb
index 5ef42b3390..dee0364ab0 100644
--- a/spec/ruby/library/stringio/stringio_spec.rb
+++ b/spec/ruby/library/stringio/stringio_spec.rb
@@ -3,6 +3,6 @@ require "stringio"
describe "StringIO" do
it "includes the Enumerable module" do
- StringIO.should include(Enumerable)
+ StringIO.should.include?(Enumerable)
end
end
diff --git a/spec/ruby/library/stringio/sync_spec.rb b/spec/ruby/library/stringio/sync_spec.rb
index e717a5697b..d7d1209047 100644
--- a/spec/ruby/library/stringio/sync_spec.rb
+++ b/spec/ruby/library/stringio/sync_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/classes'
describe "StringIO#sync" do
it "returns true" do
- StringIO.new('').sync.should be_true
+ StringIO.new('').sync.should == true
end
end
@@ -14,6 +14,6 @@ describe "StringIO#sync=" do
it "does not change 'sync' status" do
@io.sync = false
- @io.sync.should be_true
+ @io.sync.should == true
end
end
diff --git a/spec/ruby/library/stringio/sysread_spec.rb b/spec/ruby/library/stringio/sysread_spec.rb
index fabb06dd9a..1403dab5cb 100644
--- a/spec/ruby/library/stringio/sysread_spec.rb
+++ b/spec/ruby/library/stringio/sysread_spec.rb
@@ -44,7 +44,7 @@ describe "StringIO#sysread when passed [length]" do
it "raises an EOFError when self's position is at the end" do
@io.pos = 7
- -> { @io.sysread(10) }.should raise_error(EOFError)
+ -> { @io.sysread(10) }.should.raise(EOFError)
end
it "returns an empty String when length is 0" do
diff --git a/spec/ruby/library/stringio/truncate_spec.rb b/spec/ruby/library/stringio/truncate_spec.rb
index 592ca5a6e1..7205261141 100644
--- a/spec/ruby/library/stringio/truncate_spec.rb
+++ b/spec/ruby/library/stringio/truncate_spec.rb
@@ -7,7 +7,7 @@ describe "StringIO#truncate when passed [length]" do
end
it "returns an Integer" do
- @io.truncate(4).should be_kind_of(Integer)
+ @io.truncate(4).should.is_a?(Integer)
end
it "truncated the underlying string down to the passed length" do
@@ -18,13 +18,13 @@ describe "StringIO#truncate when passed [length]" do
it "does not create a copy of the underlying string" do
io = StringIO.new(str = +"123456789")
io.truncate(4)
- io.string.should equal(str)
+ io.string.should.equal?(str)
end
it "does not change the position" do
@io.pos = 7
@io.truncate(4)
- @io.pos.should eql(7)
+ @io.pos.should.eql?(7)
end
it "can grow a string to a larger size, padding it with \\000" do
@@ -33,8 +33,8 @@ describe "StringIO#truncate when passed [length]" do
end
it "raises an Errno::EINVAL when the passed length is negative" do
- -> { @io.truncate(-1) }.should raise_error(Errno::EINVAL)
- -> { @io.truncate(-10) }.should raise_error(Errno::EINVAL)
+ -> { @io.truncate(-1) }.should.raise(Errno::EINVAL)
+ -> { @io.truncate(-10) }.should.raise(Errno::EINVAL)
end
it "tries to convert the passed length to an Integer using #to_int" do
@@ -46,17 +46,17 @@ describe "StringIO#truncate when passed [length]" do
end
it "raises a TypeError when the passed length can't be converted to an Integer" do
- -> { @io.truncate(Object.new) }.should raise_error(TypeError)
+ -> { @io.truncate(Object.new) }.should.raise(TypeError)
end
end
describe "StringIO#truncate when self is not writable" do
it "raises an IOError" do
io = StringIO.new(+"test", "r")
- -> { io.truncate(2) }.should raise_error(IOError)
+ -> { io.truncate(2) }.should.raise(IOError)
io = StringIO.new(+"test")
io.close_write
- -> { io.truncate(2) }.should raise_error(IOError)
+ -> { io.truncate(2) }.should.raise(IOError)
end
end
diff --git a/spec/ruby/library/stringio/ungetc_spec.rb b/spec/ruby/library/stringio/ungetc_spec.rb
index bceafa79ff..8753ac9666 100644
--- a/spec/ruby/library/stringio/ungetc_spec.rb
+++ b/spec/ruby/library/stringio/ungetc_spec.rb
@@ -14,13 +14,13 @@ describe "StringIO#ungetc when passed [char]" do
it "returns nil" do
@io.pos = 1
- @io.ungetc(?A).should be_nil
+ @io.ungetc(?A).should == nil
end
it "decreases the current position by one" do
@io.pos = 2
@io.ungetc(?A)
- @io.pos.should eql(1)
+ @io.pos.should.eql?(1)
end
it "pads with \\000 when the current position is after the end" do
@@ -39,7 +39,7 @@ describe "StringIO#ungetc when passed [char]" do
end
it "raises a TypeError when the passed length can't be converted to an Integer or String" do
- -> { @io.ungetc(Object.new) }.should raise_error(TypeError)
+ -> { @io.ungetc(Object.new) }.should.raise(TypeError)
end
end
@@ -47,12 +47,12 @@ describe "StringIO#ungetc when self is not readable" do
it "raises an IOError" do
io = StringIO.new(+"test", "w")
io.pos = 1
- -> { io.ungetc(?A) }.should raise_error(IOError)
+ -> { io.ungetc(?A) }.should.raise(IOError)
io = StringIO.new(+"test")
io.pos = 1
io.close_read
- -> { io.ungetc(?A) }.should raise_error(IOError)
+ -> { io.ungetc(?A) }.should.raise(IOError)
end
end
@@ -62,11 +62,11 @@ end
# it "raises an IOError" do
# io = StringIO.new(+"test", "r")
# io.pos = 1
-# lambda { io.ungetc(?A) }.should raise_error(IOError)
+# lambda { io.ungetc(?A) }.should.raise(IOError)
#
# io = StringIO.new(+"test")
# io.pos = 1
# io.close_write
-# lambda { io.ungetc(?A) }.should raise_error(IOError)
+# lambda { io.ungetc(?A) }.should.raise(IOError)
# end
# end