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.rb26
-rw-r--r--spec/ruby/library/stringio/binmode_spec.rb20
-rw-r--r--spec/ruby/library/stringio/bytes_spec.rb11
-rw-r--r--spec/ruby/library/stringio/chars_spec.rb11
-rw-r--r--spec/ruby/library/stringio/close_read_spec.rb19
-rw-r--r--spec/ruby/library/stringio/close_spec.rb23
-rw-r--r--spec/ruby/library/stringio/close_write_spec.rb21
-rw-r--r--spec/ruby/library/stringio/closed_read_spec.rb6
-rw-r--r--spec/ruby/library/stringio/closed_spec.rb8
-rw-r--r--spec/ruby/library/stringio/closed_write_spec.rb6
-rw-r--r--spec/ruby/library/stringio/codepoints_spec.rb9
-rw-r--r--spec/ruby/library/stringio/each_byte_spec.rb4
-rw-r--r--spec/ruby/library/stringio/each_char_spec.rb6
-rw-r--r--spec/ruby/library/stringio/each_codepoint_spec.rb9
-rw-r--r--spec/ruby/library/stringio/each_line_spec.rb16
-rw-r--r--spec/ruby/library/stringio/each_spec.rb20
-rw-r--r--spec/ruby/library/stringio/eof_spec.rb6
-rw-r--r--spec/ruby/library/stringio/external_encoding_spec.rb24
-rw-r--r--spec/ruby/library/stringio/fcntl_spec.rb6
-rw-r--r--spec/ruby/library/stringio/fileno_spec.rb6
-rw-r--r--spec/ruby/library/stringio/fixtures/classes.rb4
-rw-r--r--spec/ruby/library/stringio/flush_spec.rb6
-rw-r--r--spec/ruby/library/stringio/fsync_spec.rb6
-rw-r--r--spec/ruby/library/stringio/getbyte_spec.rb10
-rw-r--r--spec/ruby/library/stringio/getc_spec.rb10
-rw-r--r--spec/ruby/library/stringio/getch_spec.rb32
-rw-r--r--spec/ruby/library/stringio/getpass_spec.rb11
-rw-r--r--spec/ruby/library/stringio/gets_spec.rb27
-rw-r--r--spec/ruby/library/stringio/initialize_spec.rb201
-rw-r--r--spec/ruby/library/stringio/inspect_spec.rb19
-rw-r--r--spec/ruby/library/stringio/internal_encoding_spec.rb2
-rw-r--r--spec/ruby/library/stringio/isatty_spec.rb6
-rw-r--r--spec/ruby/library/stringio/length_spec.rb6
-rw-r--r--spec/ruby/library/stringio/lineno_spec.rb2
-rw-r--r--spec/ruby/library/stringio/lines_spec.rb21
-rw-r--r--spec/ruby/library/stringio/new_spec.rb10
-rw-r--r--spec/ruby/library/stringio/open_spec.rb81
-rw-r--r--spec/ruby/library/stringio/path_spec.rb6
-rw-r--r--spec/ruby/library/stringio/pid_spec.rb4
-rw-r--r--spec/ruby/library/stringio/pos_spec.rb8
-rw-r--r--spec/ruby/library/stringio/print_spec.rb26
-rw-r--r--spec/ruby/library/stringio/printf_spec.rb48
-rw-r--r--spec/ruby/library/stringio/putc_spec.rb35
-rw-r--r--spec/ruby/library/stringio/puts_spec.rb53
-rw-r--r--spec/ruby/library/stringio/read_nonblock_spec.rb39
-rw-r--r--spec/ruby/library/stringio/read_spec.rb6
-rw-r--r--spec/ruby/library/stringio/readbyte_spec.rb8
-rw-r--r--spec/ruby/library/stringio/readchar_spec.rb8
-rw-r--r--spec/ruby/library/stringio/readline_spec.rb47
-rw-r--r--spec/ruby/library/stringio/readlines_spec.rb43
-rw-r--r--spec/ruby/library/stringio/readpartial_spec.rb20
-rw-r--r--spec/ruby/library/stringio/reopen_spec.rb103
-rw-r--r--spec/ruby/library/stringio/rewind_spec.rb4
-rw-r--r--spec/ruby/library/stringio/seek_spec.rb18
-rw-r--r--spec/ruby/library/stringio/set_encoding_by_bom_spec.rb237
-rw-r--r--spec/ruby/library/stringio/set_encoding_spec.rb24
-rw-r--r--spec/ruby/library/stringio/shared/codepoints.rb8
-rw-r--r--spec/ruby/library/stringio/shared/each.rb69
-rw-r--r--spec/ruby/library/stringio/shared/each_byte.rb6
-rw-r--r--spec/ruby/library/stringio/shared/each_char.rb6
-rw-r--r--spec/ruby/library/stringio/shared/getc.rb6
-rw-r--r--spec/ruby/library/stringio/shared/isatty.rb2
-rw-r--r--spec/ruby/library/stringio/shared/read.rb52
-rw-r--r--spec/ruby/library/stringio/shared/readchar.rb8
-rw-r--r--spec/ruby/library/stringio/shared/sysread.rb4
-rw-r--r--spec/ruby/library/stringio/shared/write.rb74
-rw-r--r--spec/ruby/library/stringio/size_spec.rb6
-rw-r--r--spec/ruby/library/stringio/string_spec.rb6
-rw-r--r--spec/ruby/library/stringio/stringio_spec.rb3
-rw-r--r--spec/ruby/library/stringio/sync_spec.rb4
-rw-r--r--spec/ruby/library/stringio/sysread_spec.rb11
-rw-r--r--spec/ruby/library/stringio/syswrite_spec.rb6
-rw-r--r--spec/ruby/library/stringio/tell_spec.rb6
-rw-r--r--spec/ruby/library/stringio/truncate_spec.rb32
-rw-r--r--spec/ruby/library/stringio/tty_spec.rb6
-rw-r--r--spec/ruby/library/stringio/ungetbyte_spec.rb40
-rw-r--r--spec/ruby/library/stringio/ungetc_spec.rb20
-rw-r--r--spec/ruby/library/stringio/write_nonblock_spec.rb12
-rw-r--r--spec/ruby/library/stringio/write_spec.rb6
79 files changed, 599 insertions, 1242 deletions
diff --git a/spec/ruby/library/stringio/append_spec.rb b/spec/ruby/library/stringio/append_spec.rb
index cb50d73d1b..ff0dc233cd 100644
--- a/spec/ruby/library/stringio/append_spec.rb
+++ b/spec/ruby/library/stringio/append_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#<< when passed [Object]" do
before :each do
- @io = StringIO.new(+"example")
+ @io = StringIO.new("example")
end
it "returns self" do
@@ -29,6 +29,16 @@ describe "StringIO#<< when passed [Object]" do
@io.string.should == "example\000\000\000\000\000\000\000\000just testing"
end
+ it "taints self's String when the passed argument is tainted" do
+ (@io << "test".taint)
+ @io.string.tainted?.should be_true
+ end
+
+ it "does not taint self when the passed argument is tainted" do
+ (@io << "test".taint)
+ @io.tainted?.should be_false
+ end
+
it "updates self's position" do
@io << "test"
@io.pos.should eql(4)
@@ -44,18 +54,18 @@ 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 = StringIO.new("test", "r")
+ lambda { io << "test" }.should raise_error(IOError)
- io = StringIO.new(+"test")
+ io = StringIO.new("test")
io.close_write
- -> { io << "test" }.should raise_error(IOError)
+ lambda { io << "test" }.should raise_error(IOError)
end
end
describe "StringIO#<< when in append mode" do
before :each do
- @io = StringIO.new(+"example", "a")
+ @io = StringIO.new("example", "a")
end
it "appends the passed argument to the end of self, ignoring current position" do
diff --git a/spec/ruby/library/stringio/binmode_spec.rb b/spec/ruby/library/stringio/binmode_spec.rb
index 9e92c63814..11fbbaadeb 100644
--- a/spec/ruby/library/stringio/binmode_spec.rb
+++ b/spec/ruby/library/stringio/binmode_spec.rb
@@ -1,23 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#binmode" do
it "returns self" do
- io = StringIO.new(+"example")
+ io = StringIO.new("example")
io.binmode.should equal(io)
end
-
- it "changes external encoding to BINARY" do
- io = StringIO.new
- io.external_encoding.should == Encoding.find('external')
- io.binmode
- io.external_encoding.should == Encoding::BINARY
- end
-
- it "does not set internal encoding" do
- io = StringIO.new
- io.internal_encoding.should == nil
- io.binmode
- io.internal_encoding.should == nil
- end
end
diff --git a/spec/ruby/library/stringio/bytes_spec.rb b/spec/ruby/library/stringio/bytes_spec.rb
new file mode 100644
index 0000000000..22d990dff7
--- /dev/null
+++ b/spec/ruby/library/stringio/bytes_spec.rb
@@ -0,0 +1,11 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'stringio'
+require File.expand_path('../shared/each_byte', __FILE__)
+
+describe "StringIO#bytes" do
+ it_behaves_like :stringio_each_byte, :bytes
+end
+
+describe "StringIO#bytes when self is not readable" do
+ it_behaves_like :stringio_each_byte_not_readable, :bytes
+end
diff --git a/spec/ruby/library/stringio/chars_spec.rb b/spec/ruby/library/stringio/chars_spec.rb
new file mode 100644
index 0000000000..c5ffde23db
--- /dev/null
+++ b/spec/ruby/library/stringio/chars_spec.rb
@@ -0,0 +1,11 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'stringio'
+require File.expand_path('../shared/each_char', __FILE__)
+
+describe "StringIO#chars" do
+ it_behaves_like :stringio_each_char, :chars
+end
+
+describe "StringIO#chars when self is not readable" do
+ it_behaves_like :stringio_each_char_not_readable, :chars
+end
diff --git a/spec/ruby/library/stringio/close_read_spec.rb b/spec/ruby/library/stringio/close_read_spec.rb
index 0f08e1ff2e..59e16385d2 100644
--- a/spec/ruby/library/stringio/close_read_spec.rb
+++ b/spec/ruby/library/stringio/close_read_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#close_read" do
before :each do
- @io = StringIO.new(+"example")
+ @io = StringIO.new("example")
end
it "returns nil" do
@@ -12,7 +12,7 @@ describe "StringIO#close_read" do
it "prevents further reading" do
@io.close_read
- -> { @io.read(1) }.should raise_error(IOError)
+ lambda { @io.read(1) }.should raise_error(IOError)
end
it "allows further writing" do
@@ -21,11 +21,16 @@ describe "StringIO#close_read" do
end
it "raises an IOError when in write-only mode" do
- io = StringIO.new(+"example", "w")
- -> { io.close_read }.should raise_error(IOError)
+ io = StringIO.new("example", "w")
+ lambda { io.close_read }.should raise_error(IOError)
io = StringIO.new("example")
io.close_read
- io.close_read.should == nil
+ ruby_version_is ''...'2.3' do
+ lambda { io.close_read }.should raise_error(IOError)
+ end
+ ruby_version_is '2.3' do
+ io.close_read.should == nil
+ end
end
end
diff --git a/spec/ruby/library/stringio/close_spec.rb b/spec/ruby/library/stringio/close_spec.rb
index 520a8de782..423aad4bd1 100644
--- a/spec/ruby/library/stringio/close_spec.rb
+++ b/spec/ruby/library/stringio/close_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#close" do
before :each do
@@ -12,12 +12,21 @@ describe "StringIO#close" do
it "prevents further reading and/or writing" do
@io.close
- -> { @io.read(1) }.should raise_error(IOError)
- -> { @io.write('x') }.should raise_error(IOError)
+ lambda { @io.read(1) }.should raise_error(IOError)
+ lambda { @io.write('x') }.should raise_error(IOError)
end
- it "does not raise anything when self was already closed" do
- @io.close
- -> { @io.close }.should_not raise_error(IOError)
+ ruby_version_is ''...'2.3' do
+ it "raises an IOError when self was already closed" do
+ @io.close
+ lambda { @io.close }.should raise_error(IOError)
+ end
+ end
+
+ ruby_version_is "2.3" do
+ it "does not raise anything when self was already closed" do
+ @io.close
+ lambda { @io.close }.should_not raise_error(IOError)
+ end
end
end
diff --git a/spec/ruby/library/stringio/close_write_spec.rb b/spec/ruby/library/stringio/close_write_spec.rb
index c86c3f9826..6637fe6043 100644
--- a/spec/ruby/library/stringio/close_write_spec.rb
+++ b/spec/ruby/library/stringio/close_write_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#close_write" do
before :each do
- @io = StringIO.new(+"example")
+ @io = StringIO.new("example")
end
it "returns nil" do
@@ -12,7 +12,7 @@ describe "StringIO#close_write" do
it "prevents further writing" do
@io.close_write
- -> { @io.write('x') }.should raise_error(IOError)
+ lambda { @io.write('x') }.should raise_error(IOError)
end
it "allows further reading" do
@@ -21,11 +21,16 @@ describe "StringIO#close_write" do
end
it "raises an IOError when in read-only mode" do
- io = StringIO.new(+"example", "r")
- -> { io.close_write }.should raise_error(IOError)
+ io = StringIO.new("example", "r")
+ lambda { io.close_write }.should raise_error(IOError)
- io = StringIO.new(+"example")
+ io = StringIO.new("example")
io.close_write
- io.close_write.should == nil
+ ruby_version_is ''...'2.3' do
+ lambda { io.close_write }.should raise_error(IOError)
+ end
+ ruby_version_is '2.3' do
+ io.close_write.should == nil
+ end
end
end
diff --git a/spec/ruby/library/stringio/closed_read_spec.rb b/spec/ruby/library/stringio/closed_read_spec.rb
index b4dcadc3a4..971eb5f71c 100644
--- a/spec/ruby/library/stringio/closed_read_spec.rb
+++ b/spec/ruby/library/stringio/closed_read_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#closed_read?" do
it "returns true if self is not readable" do
- io = StringIO.new(+"example", "r+")
+ io = StringIO.new("example", "r+")
io.close_write
io.closed_read?.should be_false
io.close_read
diff --git a/spec/ruby/library/stringio/closed_spec.rb b/spec/ruby/library/stringio/closed_spec.rb
index bf7ba63184..4026d78775 100644
--- a/spec/ruby/library/stringio/closed_spec.rb
+++ b/spec/ruby/library/stringio/closed_spec.rb
@@ -1,15 +1,15 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#closed?" do
it "returns true if self is completely closed" do
- io = StringIO.new(+"example", "r+")
+ io = StringIO.new("example", "r+")
io.close_read
io.closed?.should be_false
io.close_write
io.closed?.should be_true
- io = StringIO.new(+"example", "r+")
+ io = StringIO.new("example", "r+")
io.close
io.closed?.should be_true
end
diff --git a/spec/ruby/library/stringio/closed_write_spec.rb b/spec/ruby/library/stringio/closed_write_spec.rb
index 2bd3e6fa8b..52707aa240 100644
--- a/spec/ruby/library/stringio/closed_write_spec.rb
+++ b/spec/ruby/library/stringio/closed_write_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#closed_write?" do
it "returns true if self is not writable" do
- io = StringIO.new(+"example", "r+")
+ io = StringIO.new("example", "r+")
io.close_read
io.closed_write?.should be_false
io.close_write
diff --git a/spec/ruby/library/stringio/codepoints_spec.rb b/spec/ruby/library/stringio/codepoints_spec.rb
new file mode 100644
index 0000000000..098bd3c4c3
--- /dev/null
+++ b/spec/ruby/library/stringio/codepoints_spec.rb
@@ -0,0 +1,9 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/codepoints', __FILE__)
+
+# See redmine #1667
+describe "StringIO#codepoints" do
+ it_behaves_like(:stringio_codepoints, :codepoints)
+end
diff --git a/spec/ruby/library/stringio/each_byte_spec.rb b/spec/ruby/library/stringio/each_byte_spec.rb
index 6f82a32441..8e88997bc0 100644
--- a/spec/ruby/library/stringio/each_byte_spec.rb
+++ b/spec/ruby/library/stringio/each_byte_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
-require_relative 'shared/each_byte'
+require File.expand_path('../shared/each_byte', __FILE__)
describe "StringIO#each_byte" do
it_behaves_like :stringio_each_byte, :each_byte
diff --git a/spec/ruby/library/stringio/each_char_spec.rb b/spec/ruby/library/stringio/each_char_spec.rb
index 14b2f09a17..a141ae03fe 100644
--- a/spec/ruby/library/stringio/each_char_spec.rb
+++ b/spec/ruby/library/stringio/each_char_spec.rb
@@ -1,11 +1,11 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
-require_relative 'shared/each_char'
+require File.expand_path('../shared/each_char', __FILE__)
describe "StringIO#each_char" do
it_behaves_like :stringio_each_char, :each_char
end
describe "StringIO#each_char when self is not readable" do
- it_behaves_like :stringio_each_char_not_readable, :each_char
+ it_behaves_like :stringio_each_char_not_readable, :chars
end
diff --git a/spec/ruby/library/stringio/each_codepoint_spec.rb b/spec/ruby/library/stringio/each_codepoint_spec.rb
index f18de22aad..25a0bf4c81 100644
--- a/spec/ruby/library/stringio/each_codepoint_spec.rb
+++ b/spec/ruby/library/stringio/each_codepoint_spec.rb
@@ -1,9 +1,10 @@
# -*- encoding: utf-8 -*-
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/codepoints'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/codepoints', __FILE__)
# See redmine #1667
describe "StringIO#each_codepoint" do
- it_behaves_like :stringio_codepoints, :each_codepoint
+ it_behaves_like(:stringio_codepoints, :codepoints)
end
+
diff --git a/spec/ruby/library/stringio/each_line_spec.rb b/spec/ruby/library/stringio/each_line_spec.rb
index c68f7dae82..d770c18e67 100644
--- a/spec/ruby/library/stringio/each_line_spec.rb
+++ b/spec/ruby/library/stringio/each_line_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/each'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/each', __FILE__)
describe "StringIO#each_line when passed a separator" do
it_behaves_like :stringio_each_separator, :each_line
@@ -14,10 +14,8 @@ describe "StringIO#each_line when self is not readable" do
it_behaves_like :stringio_each_not_readable, :each_line
end
-describe "StringIO#each_line when passed chomp" do
- it_behaves_like :stringio_each_chomp, :each_line
-end
-
-describe "StringIO#each_line when passed limit" do
- it_behaves_like :stringio_each_limit, :each_line
+ruby_version_is "2.4" do
+ describe "StringIO#each_line when passed chomp" do
+ it_behaves_like :stringio_each_chomp, :each_line
+ end
end
diff --git a/spec/ruby/library/stringio/each_spec.rb b/spec/ruby/library/stringio/each_spec.rb
index 2c30ed5cda..cebaa345d8 100644
--- a/spec/ruby/library/stringio/each_spec.rb
+++ b/spec/ruby/library/stringio/each_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/each'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/each', __FILE__)
describe "StringIO#each when passed a separator" do
it_behaves_like :stringio_each_separator, :each
@@ -14,14 +14,8 @@ describe "StringIO#each when self is not readable" do
it_behaves_like :stringio_each_not_readable, :each
end
-describe "StringIO#each when passed chomp" do
- it_behaves_like :stringio_each_chomp, :each
-end
-
-describe "StringIO#each when passed chomp" do
- it_behaves_like :stringio_each_separator_and_chomp, :each
-end
-
-describe "StringIO#each when passed limit" do
- it_behaves_like :stringio_each_limit, :each
+ruby_version_is "2.4" do
+ describe "StringIO#each when passed chomp" do
+ it_behaves_like :stringio_each_chomp, :each
+ end
end
diff --git a/spec/ruby/library/stringio/eof_spec.rb b/spec/ruby/library/stringio/eof_spec.rb
index af0170977c..a5bb3dbe3d 100644
--- a/spec/ruby/library/stringio/eof_spec.rb
+++ b/spec/ruby/library/stringio/eof_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/eof'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/eof', __FILE__)
describe "StringIO#eof?" do
it_behaves_like :stringio_eof, :eof?
diff --git a/spec/ruby/library/stringio/external_encoding_spec.rb b/spec/ruby/library/stringio/external_encoding_spec.rb
index 6c5edb1713..9bf2d8ee8c 100644
--- a/spec/ruby/library/stringio/external_encoding_spec.rb
+++ b/spec/ruby/library/stringio/external_encoding_spec.rb
@@ -1,5 +1,5 @@
require 'stringio'
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
describe "StringIO#external_encoding" do
it "gets the encoding of the underlying String" do
@@ -8,18 +8,14 @@ describe "StringIO#external_encoding" do
io.external_encoding.should == Encoding::EUC_JP
end
- it "changes to match string if string's encoding is changed" do
- io = StringIO.new
- io.string.force_encoding(Encoding::EUC_JP)
- io.external_encoding.should == Encoding::EUC_JP
- end
-
- it "does not set the encoding of its buffer string if the string is frozen" do
- str = "foo".freeze
- enc = str.encoding
- io = StringIO.new(str)
- io.set_encoding Encoding::EUC_JP
- io.external_encoding.should == Encoding::EUC_JP
- str.encoding.should == enc
+ ruby_version_is "2.3" do
+ it "does not set the encoding of its buffer string if the string is frozen" do
+ str = "foo".freeze
+ enc = str.encoding
+ io = StringIO.new(str)
+ io.set_encoding Encoding::EUC_JP
+ io.external_encoding.should == Encoding::EUC_JP
+ str.encoding.should == enc
+ end
end
end
diff --git a/spec/ruby/library/stringio/fcntl_spec.rb b/spec/ruby/library/stringio/fcntl_spec.rb
index a78004d868..5250359a79 100644
--- a/spec/ruby/library/stringio/fcntl_spec.rb
+++ b/spec/ruby/library/stringio/fcntl_spec.rb
@@ -1,8 +1,8 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#fcntl" do
it "raises a NotImplementedError" do
- -> { StringIO.new("boom").fcntl }.should raise_error(NotImplementedError)
+ lambda { StringIO.new("boom").fcntl }.should raise_error(NotImplementedError)
end
end
diff --git a/spec/ruby/library/stringio/fileno_spec.rb b/spec/ruby/library/stringio/fileno_spec.rb
index eea03a5af3..a5ae820830 100644
--- a/spec/ruby/library/stringio/fileno_spec.rb
+++ b/spec/ruby/library/stringio/fileno_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/each'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/each', __FILE__)
describe "StringIO#fileno" do
it "returns nil" do
diff --git a/spec/ruby/library/stringio/fixtures/classes.rb b/spec/ruby/library/stringio/fixtures/classes.rb
index 832c5457d7..bb8dc354cc 100644
--- a/spec/ruby/library/stringio/fixtures/classes.rb
+++ b/spec/ruby/library/stringio/fixtures/classes.rb
@@ -4,12 +4,12 @@ class StringSubclass < String; end
module StringIOSpecs
def self.build
- str = <<-EOS
+ str = <<-EOS
each
peach
pear
plum
- EOS
+ EOS
StringIO.new(str)
end
end
diff --git a/spec/ruby/library/stringio/flush_spec.rb b/spec/ruby/library/stringio/flush_spec.rb
index 4dc58b1d48..75a92db85a 100644
--- a/spec/ruby/library/stringio/flush_spec.rb
+++ b/spec/ruby/library/stringio/flush_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#flush" do
it "returns self" do
- io = StringIO.new(+"flush")
+ io = StringIO.new("flush")
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..509f4a972f 100644
--- a/spec/ruby/library/stringio/fsync_spec.rb
+++ b/spec/ruby/library/stringio/fsync_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#fsync" do
it "returns zero" do
- io = StringIO.new(+"fsync")
+ io = StringIO.new("fsync")
io.fsync.should eql(0)
end
end
diff --git a/spec/ruby/library/stringio/getbyte_spec.rb b/spec/ruby/library/stringio/getbyte_spec.rb
index 3daa3d8e02..163cb9d0c6 100644
--- a/spec/ruby/library/stringio/getbyte_spec.rb
+++ b/spec/ruby/library/stringio/getbyte_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
-require_relative 'shared/getc'
+require File.expand_path('../shared/getc', __FILE__)
describe "StringIO#getbyte" do
it_behaves_like :stringio_getc, :getbyte
@@ -8,9 +8,9 @@ describe "StringIO#getbyte" do
it "returns the 8-bit byte at the current position" do
io = StringIO.new("example")
- io.getbyte.should == 101
- io.getbyte.should == 120
- io.getbyte.should == 97
+ io.send(@method).should == 101
+ io.send(@method).should == 120
+ io.send(@method).should == 97
end
end
diff --git a/spec/ruby/library/stringio/getc_spec.rb b/spec/ruby/library/stringio/getc_spec.rb
index 263d418316..804502d8ba 100644
--- a/spec/ruby/library/stringio/getc_spec.rb
+++ b/spec/ruby/library/stringio/getc_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
-require_relative 'shared/getc'
+require File.expand_path('../shared/getc', __FILE__)
describe "StringIO#getc" do
it_behaves_like :stringio_getc, :getc
@@ -8,9 +8,9 @@ describe "StringIO#getc" do
it "returns the character at the current position" do
io = StringIO.new("example")
- io.getc.should == ?e
- io.getc.should == ?x
- io.getc.should == ?a
+ io.send(@method).should == ?e
+ io.send(@method).should == ?x
+ io.send(@method).should == ?a
end
end
diff --git a/spec/ruby/library/stringio/getch_spec.rb b/spec/ruby/library/stringio/getch_spec.rb
index 113b4971bf..d6f652424e 100644
--- a/spec/ruby/library/stringio/getch_spec.rb
+++ b/spec/ruby/library/stringio/getch_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
-require_relative 'shared/getc'
+require File.expand_path('../shared/getc', __FILE__)
# This method is added by io/console on require.
describe "StringIO#getch" do
@@ -12,30 +12,32 @@ describe "StringIO#getch" do
it "returns the character at the current position" do
io = StringIO.new("example")
- io.getch.should == ?e
- io.getch.should == ?x
- io.getch.should == ?a
+ io.send(@method).should == ?e
+ io.send(@method).should == ?x
+ io.send(@method).should == ?a
end
- it "increments #pos by the byte size of the character in multibyte strings" do
- io = StringIO.new("föóbar")
+ with_feature :encoding do
+ it "increments #pos by the byte size of the character in multibyte strings" do
+ io = StringIO.new("föóbar")
- io.getch; io.pos.should == 1 # "f" has byte size 1
- io.getch; io.pos.should == 3 # "ö" has byte size 2
- io.getch; io.pos.should == 5 # "ó" has byte size 2
- io.getch; io.pos.should == 6 # "b" has byte size 1
+ io.send(@method); io.pos.should == 1 # "f" has byte size 1
+ io.send(@method); io.pos.should == 3 # "ö" has byte size 2
+ io.send(@method); io.pos.should == 5 # "ó" has byte size 2
+ io.send(@method); io.pos.should == 6 # "b" has byte size 1
+ end
end
it "returns nil at the end of the string" do
# empty string case
io = StringIO.new("")
- io.getch.should == nil
- io.getch.should == nil
+ io.send(@method).should == nil
+ io.send(@method).should == nil
# non-empty string case
io = StringIO.new("a")
- io.getch # skip one
- io.getch.should == nil
+ io.send(@method) # skip one
+ io.send(@method).should == nil
end
describe "StringIO#getch when self is not readable" do
diff --git a/spec/ruby/library/stringio/getpass_spec.rb b/spec/ruby/library/stringio/getpass_spec.rb
deleted file mode 100644
index 60fc64f0c5..0000000000
--- a/spec/ruby/library/stringio/getpass_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require_relative '../../spec_helper'
-require 'stringio'
-
-# This method is added by io/console on require.
-describe "StringIO#getpass" do
- require 'io/console'
-
- it "is defined by io/console" do
- StringIO.new("example").should.respond_to?(:getpass)
- end
-end
diff --git a/spec/ruby/library/stringio/gets_spec.rb b/spec/ruby/library/stringio/gets_spec.rb
index 4af7704a41..a718098a4b 100644
--- a/spec/ruby/library/stringio/gets_spec.rb
+++ b/spec/ruby/library/stringio/gets_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require "stringio"
describe "StringIO#gets when passed [separator]" do
@@ -76,13 +76,12 @@ describe "StringIO#gets when passed no argument" do
@io.gets.should == "this is\n"
begin
- old_sep = $/
- suppress_warning {$/ = " "}
+ old_sep, $/ = $/, " "
@io.gets.should == "an "
@io.gets.should == "example\nfor "
@io.gets.should == "StringIO#gets"
ensure
- suppress_warning {$/ = old_sep}
+ $/ = old_sep
end
end
@@ -171,10 +170,6 @@ describe "StringIO#gets when passed [limit]" do
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 "StringIO#gets when passed [separator] and [limit]" do
@@ -233,18 +228,20 @@ 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", "w")
+ lambda { io.gets }.should raise_error(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.gets }.should raise_error(IOError)
+ lambda { io.gets }.should raise_error(IOError)
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"
+ruby_version_is "2.4" do
+ 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"
+ end
end
end
diff --git a/spec/ruby/library/stringio/initialize_spec.rb b/spec/ruby/library/stringio/initialize_spec.rb
index 6f4d2e456c..8b661a3790 100644
--- a/spec/ruby/library/stringio/initialize_spec.rb
+++ b/spec/ruby/library/stringio/initialize_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
describe "StringIO#initialize when passed [Object, mode]" do
@@ -13,112 +13,112 @@ describe "StringIO#initialize when passed [Object, mode]" do
it "sets the mode based on the passed mode" do
io = StringIO.allocate
- io.send(:initialize, +"example", "r")
+ io.send(:initialize, "example", "r")
io.closed_read?.should be_false
io.closed_write?.should be_true
io = StringIO.allocate
- io.send(:initialize, +"example", "rb")
+ io.send(:initialize, "example", "rb")
io.closed_read?.should be_false
io.closed_write?.should be_true
io = StringIO.allocate
- io.send(:initialize, +"example", "r+")
+ io.send(:initialize, "example", "r+")
io.closed_read?.should be_false
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", "rb+")
+ io.send(:initialize, "example", "rb+")
io.closed_read?.should be_false
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", "w")
+ io.send(:initialize, "example", "w")
io.closed_read?.should be_true
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", "wb")
+ io.send(:initialize, "example", "wb")
io.closed_read?.should be_true
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", "w+")
+ io.send(:initialize, "example", "w+")
io.closed_read?.should be_false
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", "wb+")
+ io.send(:initialize, "example", "wb+")
io.closed_read?.should be_false
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", "a")
+ io.send(:initialize, "example", "a")
io.closed_read?.should be_true
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", "ab")
+ io.send(:initialize, "example", "ab")
io.closed_read?.should be_true
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", "a+")
+ io.send(:initialize, "example", "a+")
io.closed_read?.should be_false
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", "ab+")
+ io.send(:initialize, "example", "ab+")
io.closed_read?.should be_false
io.closed_write?.should be_false
end
it "allows passing the mode as an Integer" do
io = StringIO.allocate
- io.send(:initialize, +"example", IO::RDONLY)
+ io.send(:initialize, "example", IO::RDONLY)
io.closed_read?.should be_false
io.closed_write?.should be_true
io = StringIO.allocate
- io.send(:initialize, +"example", IO::RDWR)
+ io.send(:initialize, "example", IO::RDWR)
io.closed_read?.should be_false
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", IO::WRONLY)
+ io.send(:initialize, "example", IO::WRONLY)
io.closed_read?.should be_true
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", IO::WRONLY | IO::TRUNC)
+ io.send(:initialize, "example", IO::WRONLY | IO::TRUNC)
io.closed_read?.should be_true
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", IO::RDWR | IO::TRUNC)
+ io.send(:initialize, "example", IO::RDWR | IO::TRUNC)
io.closed_read?.should be_false
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", IO::WRONLY | IO::APPEND)
+ io.send(:initialize, "example", IO::WRONLY | IO::APPEND)
io.closed_read?.should be_true
io.closed_write?.should be_false
io = StringIO.allocate
- io.send(:initialize, +"example", IO::RDWR | IO::APPEND)
+ io.send(:initialize, "example", IO::RDWR | IO::APPEND)
io.closed_read?.should be_false
io.closed_write?.should be_false
end
- it "raises a FrozenError when passed a frozen String in truncate mode as StringIO backend" do
+ it "raises a RuntimeError 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)
+ lambda { io.send(:initialize, "example".freeze, IO::TRUNC) }.should raise_error(RuntimeError)
end
it "tries to convert the passed mode to a String using #to_str" do
obj = mock('to_str')
obj.should_receive(:to_str).and_return("r")
- @io.send(:initialize, +"example", obj)
+ @io.send(:initialize, "example", obj)
@io.closed_read?.should be_false
@io.closed_write?.should be_true
@@ -126,29 +126,9 @@ describe "StringIO#initialize when passed [Object, mode]" do
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)
- end
-
- it "truncates all the content if passed w mode" do
- io = StringIO.allocate
- source = +"example".encode(Encoding::ISO_8859_1);
-
- io.send(:initialize, source, "w")
-
- io.string.should.empty?
- io.string.encoding.should == Encoding::ISO_8859_1
- end
-
- it "truncates all the content if passed IO::TRUNC mode" do
- io = StringIO.allocate
- source = +"example".encode(Encoding::ISO_8859_1);
-
- io.send(:initialize, source, IO::TRUNC)
-
- io.string.should.empty?
- io.string.encoding.should == Encoding::ISO_8859_1
+ lambda { @io.send(:initialize, str, "r+") }.should raise_error(Errno::EACCES)
+ lambda { @io.send(:initialize, str, "w") }.should raise_error(Errno::EACCES)
+ lambda { @io.send(:initialize, str, "a") }.should raise_error(Errno::EACCES)
end
end
@@ -162,18 +142,12 @@ describe "StringIO#initialize when passed [Object]" do
@io.string.should equal(str)
end
- it "sets the mode to read-write if the string is mutable" do
- @io.send(:initialize, +"example")
+ it "sets the mode to read-write" do
+ @io.send(:initialize, "example")
@io.closed_read?.should be_false
@io.closed_write?.should be_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
- end
-
it "tries to convert the passed Object to a String using #to_str" do
obj = mock('to_str')
obj.should_receive(:to_str).and_return("example")
@@ -189,91 +163,6 @@ describe "StringIO#initialize when passed [Object]" do
end
end
-# NOTE: Synchronise with core/io/new_spec.rb (core/io/shared/new.rb)
-describe "StringIO#initialize when passed keyword arguments" do
- it "sets the mode based on the passed :mode option" do
- io = StringIO.new("example", mode: "r")
- io.closed_read?.should be_false
- io.closed_write?.should be_true
- end
-
- it "accepts a mode argument set to nil with a valid :mode option" do
- @io = StringIO.new(+'', nil, mode: "w")
- @io.write("foo").should == 3
- end
-
- it "accepts a mode argument with a :mode option set to nil" do
- @io = StringIO.new(+'', "w", mode: nil)
- @io.write("foo").should == 3
- end
-
- it "sets binmode from :binmode option" do
- @io = StringIO.new(+'', 'w', binmode: true)
- @io.external_encoding.to_s.should == "ASCII-8BIT" # #binmode? isn't implemented in StringIO
- end
-
- it "does not set binmode from false :binmode" do
- @io = StringIO.new(+'', 'w', binmode: false)
- @io.external_encoding.to_s.should == "UTF-8" # #binmode? isn't implemented in StringIO
- end
-end
-
-# NOTE: Synchronise with core/io/new_spec.rb (core/io/shared/new.rb)
-describe "StringIO#initialize when passed keyword arguments and error happens" do
- it "raises an error if passed encodings two ways" do
- -> {
- @io = StringIO.new(+'', 'w:ISO-8859-1', encoding: 'ISO-8859-1')
- }.should raise_error(ArgumentError)
- -> {
- @io = StringIO.new(+'', 'w:ISO-8859-1', external_encoding: 'ISO-8859-1')
- }.should raise_error(ArgumentError)
- -> {
- @io = StringIO.new(+'', 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1')
- }.should raise_error(ArgumentError)
- end
-
- it "raises an error if passed matching binary/text mode two ways" do
- -> {
- @io = StringIO.new(+'', "wb", binmode: true)
- }.should raise_error(ArgumentError)
- -> {
- @io = StringIO.new(+'', "wt", textmode: true)
- }.should raise_error(ArgumentError)
-
- -> {
- @io = StringIO.new(+'', "wb", textmode: false)
- }.should raise_error(ArgumentError)
- -> {
- @io = StringIO.new(+'', "wt", binmode: false)
- }.should raise_error(ArgumentError)
- end
-
- it "raises an error if passed conflicting binary/text mode two ways" do
- -> {
- @io = StringIO.new(+'', "wb", binmode: false)
- }.should raise_error(ArgumentError)
- -> {
- @io = StringIO.new(+'', "wt", textmode: false)
- }.should raise_error(ArgumentError)
-
- -> {
- @io = StringIO.new(+'', "wb", textmode: true)
- }.should raise_error(ArgumentError)
- -> {
- @io = StringIO.new(+'', "wt", binmode: true)
- }.should raise_error(ArgumentError)
- end
-
- it "raises an error when trying to set both binmode and textmode" do
- -> {
- @io = StringIO.new(+'', "w", textmode: true, binmode: true)
- }.should raise_error(ArgumentError)
- -> {
- @io = StringIO.new(+'', File::Constants::WRONLY, textmode: true, binmode: true)
- }.should raise_error(ArgumentError)
- end
-end
-
describe "StringIO#initialize when passed no arguments" do
before :each do
@io = StringIO.allocate
@@ -284,7 +173,7 @@ describe "StringIO#initialize when passed no arguments" do
end
it "sets the mode to read-write" do
- @io.send(:initialize)
+ @io.send(:initialize, "example")
@io.closed_read?.should be_false
@io.closed_write?.should be_false
end
@@ -294,35 +183,3 @@ describe "StringIO#initialize when passed no arguments" do
@io.string.should == ""
end
end
-
-describe "StringIO#initialize sets" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
- Encoding.default_external = Encoding::ISO_8859_2
- Encoding.default_internal = Encoding::ISO_8859_2
- end
-
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
-
- it "the encoding to Encoding.default_external when passed no arguments" do
- io = StringIO.new
- io.external_encoding.should == Encoding::ISO_8859_2
- io.string.encoding.should == Encoding::ISO_8859_2
- end
-
- it "the encoding to the encoding of the String when passed a String" do
- s = ''.dup.force_encoding(Encoding::EUC_JP)
- io = StringIO.new(s)
- io.string.encoding.should == Encoding::EUC_JP
- end
-
- it "the #external_encoding to the encoding of the String when passed a String" do
- s = ''.dup.force_encoding(Encoding::EUC_JP)
- io = StringIO.new(s)
- io.external_encoding.should == Encoding::EUC_JP
- end
-end
diff --git a/spec/ruby/library/stringio/inspect_spec.rb b/spec/ruby/library/stringio/inspect_spec.rb
deleted file mode 100644
index 7c02f8d360..0000000000
--- a/spec/ruby/library/stringio/inspect_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require_relative '../../spec_helper'
-require "stringio"
-
-describe "StringIO#inspect" do
- it "returns the same as #to_s" do
- io = StringIO.new("example")
- io.inspect.should == io.to_s
- end
-
- it "does not include the contents" do
- io = StringIO.new("contents")
- io.inspect.should_not include("contents")
- end
-
- it "uses the regular Object#inspect without any instance variable" do
- io = StringIO.new("example")
- io.inspect.should =~ /\A#<StringIO:0x\h+>\z/
- end
-end
diff --git a/spec/ruby/library/stringio/internal_encoding_spec.rb b/spec/ruby/library/stringio/internal_encoding_spec.rb
index 2035cf25a9..f8ecb35989 100644
--- a/spec/ruby/library/stringio/internal_encoding_spec.rb
+++ b/spec/ruby/library/stringio/internal_encoding_spec.rb
@@ -1,5 +1,5 @@
require 'stringio'
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
describe "StringIO#internal_encoding" do
it "returns nil" do
diff --git a/spec/ruby/library/stringio/isatty_spec.rb b/spec/ruby/library/stringio/isatty_spec.rb
index 1ef33978b5..c07dc2f6cc 100644
--- a/spec/ruby/library/stringio/isatty_spec.rb
+++ b/spec/ruby/library/stringio/isatty_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/isatty'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/isatty', __FILE__)
describe "StringIO#isatty" do
it_behaves_like :stringio_isatty, :isatty
diff --git a/spec/ruby/library/stringio/length_spec.rb b/spec/ruby/library/stringio/length_spec.rb
index d3070f50a7..ae8eb15502 100644
--- a/spec/ruby/library/stringio/length_spec.rb
+++ b/spec/ruby/library/stringio/length_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/length'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/length', __FILE__)
describe "StringIO#length" do
it_behaves_like :stringio_length, :length
diff --git a/spec/ruby/library/stringio/lineno_spec.rb b/spec/ruby/library/stringio/lineno_spec.rb
index c620a1a686..b7ef83c7e1 100644
--- a/spec/ruby/library/stringio/lineno_spec.rb
+++ b/spec/ruby/library/stringio/lineno_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require "stringio"
describe "StringIO#lineno" do
diff --git a/spec/ruby/library/stringio/lines_spec.rb b/spec/ruby/library/stringio/lines_spec.rb
new file mode 100644
index 0000000000..c3af802073
--- /dev/null
+++ b/spec/ruby/library/stringio/lines_spec.rb
@@ -0,0 +1,21 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'stringio'
+require File.expand_path('../shared/each', __FILE__)
+
+describe "StringIO#lines when passed a separator" do
+ it_behaves_like :stringio_each_separator, :lines
+end
+
+describe "StringIO#lines when passed no arguments" do
+ it_behaves_like :stringio_each_no_arguments, :lines
+end
+
+describe "StringIO#lines when self is not readable" do
+ it_behaves_like :stringio_each_not_readable, :lines
+end
+
+ruby_version_is "2.4" do
+ describe "StringIO#lines when passed chomp" do
+ it_behaves_like :stringio_each_chomp, :lines
+ end
+end
diff --git a/spec/ruby/library/stringio/new_spec.rb b/spec/ruby/library/stringio/new_spec.rb
deleted file mode 100644
index ec4b32aa11..0000000000
--- a/spec/ruby/library/stringio/new_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require_relative '../../spec_helper'
-require 'stringio'
-
-describe "StringIO.new" do
- it "does not use the given block and warns to use StringIO::open" do
- -> {
- StringIO.new { raise }
- }.should complain(/warning: StringIO::new\(\) does not take block; use StringIO::open\(\) instead/)
- end
-end
diff --git a/spec/ruby/library/stringio/open_spec.rb b/spec/ruby/library/stringio/open_spec.rb
index b7c90661f9..136ff5f972 100644
--- a/spec/ruby/library/stringio/open_spec.rb
+++ b/spec/ruby/library/stringio/open_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
describe "StringIO.open when passed [Object, mode]" do
@@ -8,26 +8,26 @@ describe "StringIO.open when passed [Object, mode]" do
end
it "returns the blocks return value when yielding" do
- ret = StringIO.open(+"example", "r") { :test }
+ ret = StringIO.open("example", "r") { :test }
ret.should equal(:test)
end
it "yields self to the passed block" do
io = nil
- StringIO.open(+"example", "r") { |strio| io = strio }
+ StringIO.open("example", "r") { |strio| io = strio }
io.should be_kind_of(StringIO)
end
it "closes self after yielding" do
io = nil
- StringIO.open(+"example", "r") { |strio| io = strio }
+ StringIO.open("example", "r") { |strio| io = strio }
io.closed?.should be_true
end
it "even closes self when an exception is raised while yielding" do
io = nil
begin
- StringIO.open(+"example", "r") do |strio|
+ StringIO.open("example", "r") do |strio|
io = strio
raise "Error"
end
@@ -38,14 +38,14 @@ describe "StringIO.open when passed [Object, mode]" do
it "sets self's string to nil after yielding" do
io = nil
- StringIO.open(+"example", "r") { |strio| io = strio }
+ StringIO.open("example", "r") { |strio| io = strio }
io.string.should be_nil
end
it "even sets self's string to nil when an exception is raised while yielding" do
io = nil
begin
- StringIO.open(+"example", "r") do |strio|
+ StringIO.open("example", "r") do |strio|
io = strio
raise "Error"
end
@@ -55,93 +55,93 @@ describe "StringIO.open when passed [Object, mode]" do
end
it "sets the mode based on the passed mode" do
- io = StringIO.open(+"example", "r")
+ io = StringIO.open("example", "r")
io.closed_read?.should be_false
io.closed_write?.should be_true
- io = StringIO.open(+"example", "rb")
+ io = StringIO.open("example", "rb")
io.closed_read?.should be_false
io.closed_write?.should be_true
- io = StringIO.open(+"example", "r+")
+ io = StringIO.open("example", "r+")
io.closed_read?.should be_false
io.closed_write?.should be_false
- io = StringIO.open(+"example", "rb+")
+ io = StringIO.open("example", "rb+")
io.closed_read?.should be_false
io.closed_write?.should be_false
- io = StringIO.open(+"example", "w")
+ io = StringIO.open("example", "w")
io.closed_read?.should be_true
io.closed_write?.should be_false
- io = StringIO.open(+"example", "wb")
+ io = StringIO.open("example", "wb")
io.closed_read?.should be_true
io.closed_write?.should be_false
- io = StringIO.open(+"example", "w+")
+ io = StringIO.open("example", "w+")
io.closed_read?.should be_false
io.closed_write?.should be_false
- io = StringIO.open(+"example", "wb+")
+ io = StringIO.open("example", "wb+")
io.closed_read?.should be_false
io.closed_write?.should be_false
- io = StringIO.open(+"example", "a")
+ io = StringIO.open("example", "a")
io.closed_read?.should be_true
io.closed_write?.should be_false
- io = StringIO.open(+"example", "ab")
+ io = StringIO.open("example", "ab")
io.closed_read?.should be_true
io.closed_write?.should be_false
- io = StringIO.open(+"example", "a+")
+ io = StringIO.open("example", "a+")
io.closed_read?.should be_false
io.closed_write?.should be_false
- io = StringIO.open(+"example", "ab+")
+ io = StringIO.open("example", "ab+")
io.closed_read?.should be_false
io.closed_write?.should be_false
end
it "allows passing the mode as an Integer" do
- io = StringIO.open(+"example", IO::RDONLY)
+ io = StringIO.open("example", IO::RDONLY)
io.closed_read?.should be_false
io.closed_write?.should be_true
- io = StringIO.open(+"example", IO::RDWR)
+ io = StringIO.open("example", IO::RDWR)
io.closed_read?.should be_false
io.closed_write?.should be_false
- io = StringIO.open(+"example", IO::WRONLY)
+ io = StringIO.open("example", IO::WRONLY)
io.closed_read?.should be_true
io.closed_write?.should be_false
- io = StringIO.open(+"example", IO::WRONLY | IO::TRUNC)
+ io = StringIO.open("example", IO::WRONLY | IO::TRUNC)
io.closed_read?.should be_true
io.closed_write?.should be_false
- io = StringIO.open(+"example", IO::RDWR | IO::TRUNC)
+ io = StringIO.open("example", IO::RDWR | IO::TRUNC)
io.closed_read?.should be_false
io.closed_write?.should be_false
- io = StringIO.open(+"example", IO::WRONLY | IO::APPEND)
+ io = StringIO.open("example", IO::WRONLY | IO::APPEND)
io.closed_read?.should be_true
io.closed_write?.should be_false
- io = StringIO.open(+"example", IO::RDWR | IO::APPEND)
+ io = StringIO.open("example", IO::RDWR | IO::APPEND)
io.closed_read?.should be_false
io.closed_write?.should be_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)
+ it "raises a RuntimeError when passed a frozen String in truncate mode as StringIO backend" do
+ lambda { StringIO.open("example".freeze, IO::TRUNC) }.should raise_error(RuntimeError)
end
it "tries to convert the passed mode to a String using #to_str" do
obj = mock('to_str')
obj.should_receive(:to_str).and_return("r")
- io = StringIO.open(+"example", obj)
+ io = StringIO.open("example", obj)
io.closed_read?.should be_false
io.closed_write?.should be_true
@@ -149,9 +149,9 @@ describe "StringIO.open when passed [Object, mode]" do
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)
+ lambda { StringIO.open(str, "r+") }.should raise_error(Errno::EACCES)
+ lambda { StringIO.open(str, "w") }.should raise_error(Errno::EACCES)
+ lambda { StringIO.open(str, "a") }.should raise_error(Errno::EACCES)
end
end
@@ -163,18 +163,14 @@ describe "StringIO.open when passed [Object]" do
it "yields self to the passed block" do
io = nil
- ret = StringIO.open(+"example") { |strio| io = strio }
+ ret = StringIO.open("example") { |strio| io = strio }
io.should equal(ret)
end
- it "sets the mode to read-write (r+)" do
- io = StringIO.open(+"example")
+ it "sets the mode to read-write" do
+ io = StringIO.open("example")
io.closed_read?.should be_false
io.closed_write?.should be_false
-
- io = StringIO.new(+"example")
- io.printf("%d", 123)
- io.string.should == "123mple"
end
it "tries to convert the passed Object to a String using #to_str" do
@@ -199,17 +195,14 @@ describe "StringIO.open when passed no arguments" do
io.should equal(ret)
end
- it "sets the mode to read-write (r+)" do
+ it "sets the mode to read-write" do
io = StringIO.open
io.closed_read?.should be_false
io.closed_write?.should be_false
-
- io = StringIO.new(+"example")
- io.printf("%d", 123)
- io.string.should == "123mple"
end
it "uses an empty String as the StringIO backend" do
StringIO.open.string.should == ""
end
end
+
diff --git a/spec/ruby/library/stringio/path_spec.rb b/spec/ruby/library/stringio/path_spec.rb
index 1184ca523f..6165cf97c4 100644
--- a/spec/ruby/library/stringio/path_spec.rb
+++ b/spec/ruby/library/stringio/path_spec.rb
@@ -1,8 +1,8 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#path" do
it "is not defined" do
- -> { StringIO.new("path").path }.should raise_error(NoMethodError)
+ lambda { StringIO.new("path").path }.should raise_error(NoMethodError)
end
end
diff --git a/spec/ruby/library/stringio/pid_spec.rb b/spec/ruby/library/stringio/pid_spec.rb
index 08f2d7ab1a..41e60880cc 100644
--- a/spec/ruby/library/stringio/pid_spec.rb
+++ b/spec/ruby/library/stringio/pid_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#pid" do
it "returns nil" do
diff --git a/spec/ruby/library/stringio/pos_spec.rb b/spec/ruby/library/stringio/pos_spec.rb
index 81be5f01a5..d5f3c3ab95 100644
--- a/spec/ruby/library/stringio/pos_spec.rb
+++ b/spec/ruby/library/stringio/pos_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/tell'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/tell', __FILE__)
describe "StringIO#pos" do
it_behaves_like :stringio_tell, :pos
@@ -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)
+ lambda { @io.pos = -10 }.should raise_error(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..0f67aeb921 100644
--- a/spec/ruby/library/stringio/print_spec.rb
+++ b/spec/ruby/library/stringio/print_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#print" do
before :each do
- @io = StringIO.new(+'example')
+ @io = StringIO.new('example')
end
it "prints $_ when passed no arguments" do
@@ -39,14 +39,13 @@ describe "StringIO#print" do
end
it "honors the output record separator global" do
- old_rs = $\
- suppress_warning {$\ = 'x'}
+ old_rs, $\ = $\, 'x'
begin
@io.print(5, 6, 7, 8)
@io.string.should == '5678xle'
ensure
- suppress_warning {$\ = old_rs}
+ $\ = old_rs
end
end
@@ -59,21 +58,20 @@ describe "StringIO#print" do
end
it "correctly updates the current position when honoring the output record separator global" do
- old_rs = $\
- suppress_warning {$\ = 'x'}
+ old_rs, $\ = $\, 'x'
begin
@io.print(5, 6, 7, 8)
@io.pos.should eql(5)
ensure
- suppress_warning {$\ = old_rs}
+ $\ = old_rs
end
end
end
describe "StringIO#print when in append mode" do
before :each do
- @io = StringIO.new(+"example", "a")
+ @io = StringIO.new("example", "a")
end
it "appends the passed argument to the end of self" do
@@ -92,11 +90,11 @@ 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 = StringIO.new("test", "r")
+ lambda { io.print("test") }.should raise_error(IOError)
- io = StringIO.new(+"test")
+ io = StringIO.new("test")
io.close_write
- -> { io.print("test") }.should raise_error(IOError)
+ lambda { io.print("test") }.should raise_error(IOError)
end
end
diff --git a/spec/ruby/library/stringio/printf_spec.rb b/spec/ruby/library/stringio/printf_spec.rb
index ca82e84757..a2094bf52d 100644
--- a/spec/ruby/library/stringio/printf_spec.rb
+++ b/spec/ruby/library/stringio/printf_spec.rb
@@ -1,10 +1,10 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative '../../core/kernel/shared/sprintf'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../../../core/kernel/shared/sprintf', __FILE__)
describe "StringIO#printf" do
before :each do
- @io = StringIO.new()
+ @io = StringIO.new('example')
end
it "returns nil" do
@@ -12,9 +12,9 @@ describe "StringIO#printf" do
end
it "pads self with \\000 when the current position is after the end" do
- @io.pos = 3
+ @io.pos = 10
@io.printf("%d", 123)
- @io.string.should == "\000\000\000123"
+ @io.string.should == "example\000\000\000123"
end
it "performs format conversion" do
@@ -31,38 +31,17 @@ describe "StringIO#printf" do
end
describe "formatting" do
- it_behaves_like :kernel_sprintf, -> format, *args {
- io = StringIO.new(+"")
+ it_behaves_like :kernel_sprintf, -> (format, *args) {
+ io = StringIO.new
io.printf(format, *args)
io.string
}
end
end
-describe "StringIO#printf when in read-write mode" do
- before :each do
- @io = StringIO.new(+"example", "r+")
- end
-
- it "starts from the beginning" do
- @io.printf("%s", "abcdefghijk")
- @io.string.should == "abcdefghijk"
- end
-
- it "does not truncate existing string" do
- @io.printf("%s", "abc")
- @io.string.should == "abcmple"
- end
-
- it "correctly updates self's position" do
- @io.printf("%s", "abc")
- @io.pos.should eql(3)
- end
-end
-
describe "StringIO#printf when in append mode" do
before :each do
- @io = StringIO.new(+"example", "a")
+ @io = StringIO.new("example", "a")
end
it "appends the passed argument to the end of self" do
@@ -81,11 +60,12 @@ 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 = StringIO.new("test", "r")
+ lambda { io.printf("test") }.should raise_error(IOError)
- io = StringIO.new(+"test")
+ io = StringIO.new("test")
io.close_write
- -> { io.printf("test") }.should raise_error(IOError)
+ lambda { io.printf("test") }.should raise_error(IOError)
end
end
+
diff --git a/spec/ruby/library/stringio/putc_spec.rb b/spec/ruby/library/stringio/putc_spec.rb
index 9f1ac8ffb2..783e5a405b 100644
--- a/spec/ruby/library/stringio/putc_spec.rb
+++ b/spec/ruby/library/stringio/putc_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#putc when passed [String]" do
before :each do
- @io = StringIO.new(+'example')
+ @io = StringIO.new('example')
end
it "overwrites the character at the current position" do
@@ -35,26 +35,11 @@ describe "StringIO#putc when passed [String]" do
@io.putc("t")
@io.pos.should == 3
end
-
- it "handles concurrent writes correctly" do
- @io = StringIO.new
- n = 8
- go = false
- threads = n.times.map { |i|
- Thread.new {
- Thread.pass until go
- @io.putc i.to_s
- }
- }
- go = true
- threads.each(&:join)
- @io.string.size.should == n
- end
end
describe "StringIO#putc when passed [Object]" do
before :each do
- @io = StringIO.new(+'example')
+ @io = StringIO.new('example')
end
it "it writes the passed Integer % 256 to self" do
@@ -79,13 +64,13 @@ 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)
+ lambda { @io.putc(Object.new) }.should raise_error(TypeError)
end
end
describe "StringIO#putc when in append mode" do
it "appends to the end of self" do
- io = StringIO.new(+"test", "a")
+ io = StringIO.new("test", "a")
io.putc(?t)
io.string.should == "testt"
end
@@ -93,11 +78,11 @@ 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 = StringIO.new("test", "r")
+ lambda { io.putc(?a) }.should raise_error(IOError)
- io = StringIO.new(+"test")
+ io = StringIO.new("test")
io.close_write
- -> { io.putc("t") }.should raise_error(IOError)
+ lambda { io.putc("t") }.should raise_error(IOError)
end
end
diff --git a/spec/ruby/library/stringio/puts_spec.rb b/spec/ruby/library/stringio/puts_spec.rb
index 054ec8227f..93a676aa15 100644
--- a/spec/ruby/library/stringio/puts_spec.rb
+++ b/spec/ruby/library/stringio/puts_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#puts when passed an Array" do
before :each do
@@ -30,12 +30,11 @@ describe "StringIO#puts when passed an Array" do
it "does not honor the global output record separator $\\" do
begin
- old_rs = $\
- suppress_warning {$\ = "test"}
+ old_rs, $\ = $\, "test"
@io.puts([1, 2, 3, 4])
@io.string.should == "1\n2\n3\n4\n"
ensure
- suppress_warning {$\ = old_rs}
+ $\ = old_rs
end
end
@@ -52,14 +51,6 @@ describe "StringIO#puts when passed an Array" do
@io.puts([obj])
@io.string.should == "to_s\n"
end
-
- it "returns general object info if :to_s does not return a string" do
- object = mock('hola')
- object.should_receive(:to_s).and_return(false)
-
- @io.puts(object).should == nil
- @io.string.should == object.inspect.split(" ")[0] + ">\n"
- end
end
describe "StringIO#puts when passed 1 or more objects" do
@@ -69,12 +60,11 @@ describe "StringIO#puts when passed 1 or more objects" do
it "does not honor the global output record separator $\\" do
begin
- old_rs = $\
- suppress_warning {$\ = "test"}
+ old_rs, $\ = $\, "test"
@io.puts(1, 2, 3, 4)
@io.string.should == "1\n2\n3\n4\n"
ensure
- suppress_warning {$\ = old_rs}
+ $\ = old_rs
end
end
@@ -101,20 +91,6 @@ describe "StringIO#puts when passed 1 or more objects" do
@io.puts ''
@io.string.should == "\n"
end
-
- it "handles concurrent writes correctly" do
- n = 8
- go = false
- threads = n.times.map { |i|
- Thread.new {
- Thread.pass until go
- @io.puts i
- }
- }
- go = true
- threads.each(&:join)
- @io.string.size.should == n.times.map { |i| "#{i}\n" }.join.size
- end
end
describe "StringIO#puts when passed no arguments" do
@@ -133,19 +109,18 @@ describe "StringIO#puts when passed no arguments" do
it "does not honor the global output record separator $\\" do
begin
- old_rs = $\
- suppress_warning {$\ = "test"}
+ old_rs, $\ = $\, "test"
@io.puts
@io.string.should == "\n"
ensure
- suppress_warning {$\ = old_rs}
+ $\ = old_rs
end
end
end
describe "StringIO#puts when in append mode" do
before :each do
- @io = StringIO.new(+"example", "a")
+ @io = StringIO.new("example", "a")
end
it "appends the passed argument to the end of self" do
@@ -164,18 +139,18 @@ 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 = StringIO.new("test", "r")
+ lambda { io.puts }.should raise_error(IOError)
- io = StringIO.new(+"test")
+ io = StringIO.new("test")
io.close_write
- -> { io.puts }.should raise_error(IOError)
+ lambda { io.puts }.should raise_error(IOError)
end
end
describe "StringIO#puts when passed an encoded string" do
it "stores the bytes unmodified" do
- io = StringIO.new(+"")
+ io = StringIO.new("")
io.puts "\x00\x01\x02"
io.puts "æåø"
diff --git a/spec/ruby/library/stringio/read_nonblock_spec.rb b/spec/ruby/library/stringio/read_nonblock_spec.rb
index 74736f7792..84aefe8de7 100644
--- a/spec/ruby/library/stringio/read_nonblock_spec.rb
+++ b/spec/ruby/library/stringio/read_nonblock_spec.rb
@@ -1,25 +1,14 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require "stringio"
-require_relative 'shared/read'
-require_relative 'shared/sysread'
+require File.expand_path('../shared/read', __FILE__)
+require File.expand_path('../shared/sysread', __FILE__)
describe "StringIO#read_nonblock when passed length, buffer" do
it_behaves_like :stringio_read, :read_nonblock
-
- it "accepts :exception option" do
- io = StringIO.new("example")
- io.read_nonblock(3, buffer = +"", exception: true)
- buffer.should == "exa"
- end
end
describe "StringIO#read_nonblock when passed length" do
it_behaves_like :stringio_read_length, :read_nonblock
-
- it "accepts :exception option" do
- io = StringIO.new("example")
- io.read_nonblock(3, exception: true).should == "exa"
- end
end
describe "StringIO#read_nonblock when passed nil" do
@@ -29,25 +18,3 @@ end
describe "StringIO#read_nonblock when passed length" do
it_behaves_like :stringio_sysread_length, :read_nonblock
end
-
-describe "StringIO#read_nonblock" do
-
- it "accepts an exception option" do
- stringio = StringIO.new('foo')
- stringio.read_nonblock(3, exception: false).should == 'foo'
- end
-
- context "when exception option is set to false" do
- context "when the end is reached" do
- it "returns nil" do
- stringio = StringIO.new(+'')
- stringio << "hello"
- stringio.rewind
-
- stringio.read_nonblock(5).should == "hello"
- stringio.read_nonblock(5, exception: false).should be_nil
- end
- end
- end
-
-end
diff --git a/spec/ruby/library/stringio/read_spec.rb b/spec/ruby/library/stringio/read_spec.rb
index e49f262127..2b9c6e10b2 100644
--- a/spec/ruby/library/stringio/read_spec.rb
+++ b/spec/ruby/library/stringio/read_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require "stringio"
-require_relative 'shared/read'
+require File.expand_path('../shared/read', __FILE__)
describe "StringIO#read when passed length, buffer" do
it_behaves_like :stringio_read, :read
@@ -53,7 +53,7 @@ describe "StringIO#read when passed length and a buffer" do
end
it "reads [length] characters into the buffer" do
- buf = +"foo"
+ buf = "foo"
result = @io.read(10, buf)
buf.should == "abcdefghij"
diff --git a/spec/ruby/library/stringio/readbyte_spec.rb b/spec/ruby/library/stringio/readbyte_spec.rb
index 41a0911293..0fbc49a4dd 100644
--- a/spec/ruby/library/stringio/readbyte_spec.rb
+++ b/spec/ruby/library/stringio/readbyte_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
-require_relative 'shared/readchar'
+require File.expand_path('../shared/readchar', __FILE__)
describe "StringIO#readbyte" do
it_behaves_like :stringio_readchar, :readbyte
@@ -8,10 +8,10 @@ describe "StringIO#readbyte" do
it "reads the next 8-bit byte from self's current position" do
io = StringIO.new("example")
- io.readbyte.should == 101
+ io.send(@method).should == 101
io.pos = 4
- io.readbyte.should == 112
+ io.send(@method).should == 112
end
end
diff --git a/spec/ruby/library/stringio/readchar_spec.rb b/spec/ruby/library/stringio/readchar_spec.rb
index 38944819a2..af673c871a 100644
--- a/spec/ruby/library/stringio/readchar_spec.rb
+++ b/spec/ruby/library/stringio/readchar_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
-require_relative 'shared/readchar'
+require File.expand_path('../shared/readchar', __FILE__)
describe "StringIO#readchar" do
it_behaves_like :stringio_readchar, :readchar
@@ -8,10 +8,10 @@ describe "StringIO#readchar" do
it "reads the next 8-bit byte from self's current position" do
io = StringIO.new("example")
- io.readchar.should == ?e
+ io.send(@method).should == ?e
io.pos = 4
- io.readchar.should == ?p
+ io.send(@method).should == ?p
end
end
diff --git a/spec/ruby/library/stringio/readline_spec.rb b/spec/ruby/library/stringio/readline_spec.rb
index b16a16e23f..1deb52c492 100644
--- a/spec/ruby/library/stringio/readline_spec.rb
+++ b/spec/ruby/library/stringio/readline_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#readline when passed [separator]" do
@@ -64,13 +64,12 @@ describe "StringIO#readline when passed no argument" do
@io.readline.should == "this is\n"
begin
- old_sep = $/
- suppress_warning {$/ = " "}
+ old_sep, $/ = $/, " "
@io.readline.should == "an "
@io.readline.should == "example\nfor "
@io.readline.should == "StringIO#readline"
ensure
- suppress_warning {$/ = old_sep}
+ $/ = old_sep
end
end
@@ -107,44 +106,26 @@ describe "StringIO#readline when passed no argument" do
it "raises an IOError if self is at the end" do
@io.pos = 40
- -> { @io.readline }.should raise_error(IOError)
+ lambda { @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", "w")
+ lambda { io.readline }.should raise_error(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.readline }.should raise_error(IOError)
+ lambda { io.readline }.should raise_error(IOError)
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 "StringIO#readline 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 = StringIO.new("this>is>an>example\n")
- io.readline(3).should == "thi"
- end
-
- it "returns a blank string when passed a limit of 0" do
- @io.readline(0).should == ""
- end
-
- it "ignores it when the limit is negative" do
- seen = []
- @io.readline(-4).should == "this>is>an>example"
+ruby_version_is "2.4" do
+ 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
end
diff --git a/spec/ruby/library/stringio/readlines_spec.rb b/spec/ruby/library/stringio/readlines_spec.rb
index ed7cc22b3d..11217d1e59 100644
--- a/spec/ruby/library/stringio/readlines_spec.rb
+++ b/spec/ruby/library/stringio/readlines_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#readlines when passed [separator]" do
before :each do
@@ -51,11 +51,10 @@ describe "StringIO#readlines when passed no argument" do
it "returns an Array containing lines based on $/" do
begin
- old_sep = $/;
- suppress_warning {$/ = " "}
+ old_sep, $/ = $/, " "
@io.readlines.should == ["this ", "is\nan ", "example\nfor ", "StringIO#readlines"]
ensure
- suppress_warning {$/ = old_sep}
+ $/ = old_sep
end
end
@@ -83,36 +82,20 @@ 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 = StringIO.new("xyz", "w")
+ lambda { io.readlines }.should raise_error(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.readlines }.should raise_error(IOError)
+ lambda { io.readlines }.should raise_error(IOError)
end
end
-describe "StringIO#readlines when passed [chomp]" do
- it "returns the data read without a trailing newline character" do
- io = StringIO.new("this>is\nan>example\r\n")
- io.readlines(chomp: true).should == ["this>is", "an>example"]
- end
-end
-
-describe "StringIO#readlines when passed [limit]" do
- before :each do
- @io = StringIO.new("a b c d e\n1 2 3 4 5")
- end
-
- it "returns the data read until the limit is met" do
- @io.readlines(4).should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"]
- end
-
- it "raises ArgumentError when limit is 0" do
- -> { @io.readlines(0) }.should raise_error(ArgumentError)
- end
-
- it "ignores it when the limit is negative" do
- @io.readlines(-4).should == ["a b c d e\n", "1 2 3 4 5"]
+ruby_version_is "2.4" do
+ describe "StringIO#readlines when passed [chomp]" do
+ it "returns the data read without a trailing newline character" do
+ io = StringIO.new("this>is\nan>example\r\n")
+ io.readlines(chomp: true).should == ["this>is", "an>example"]
+ end
end
end
diff --git a/spec/ruby/library/stringio/readpartial_spec.rb b/spec/ruby/library/stringio/readpartial_spec.rb
index f25cef4014..e65e50fa41 100644
--- a/spec/ruby/library/stringio/readpartial_spec.rb
+++ b/spec/ruby/library/stringio/readpartial_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#readpartial" do
before :each do
- @string = StringIO.new(+'Stop, look, listen')
+ @string = StringIO.new('Stop, look, listen')
end
after :each do
@@ -12,7 +12,7 @@ describe "StringIO#readpartial" do
it "raises IOError on closed stream" do
@string.close
- -> { @string.readpartial(10) }.should raise_error(IOError)
+ lambda { @string.readpartial(10) }.should raise_error(IOError)
end
it "reads at most the specified number of bytes" do
@@ -48,30 +48,30 @@ describe "StringIO#readpartial" do
end
it "discards the existing buffer content upon successful read" do
- buffer = +"existing"
+ buffer = "existing"
@string.readpartial(11, buffer)
buffer.should == "Stop, look,"
end
it "raises EOFError on EOF" do
@string.readpartial(18).should == 'Stop, look, listen'
- -> { @string.readpartial(10) }.should raise_error(EOFError)
+ lambda { @string.readpartial(10) }.should raise_error(EOFError)
end
it "discards the existing buffer content upon error" do
- buffer = +'hello'
+ buffer = 'hello'
@string.readpartial(100)
- -> { @string.readpartial(1, buffer) }.should raise_error(EOFError)
+ lambda { @string.readpartial(1, buffer) }.should raise_error(EOFError)
buffer.should be_empty
end
it "raises IOError if the stream is closed" do
@string.close
- -> { @string.readpartial(1) }.should raise_error(IOError)
+ lambda { @string.readpartial(1) }.should raise_error(IOError)
end
it "raises ArgumentError if the negative argument is provided" do
- -> { @string.readpartial(-1) }.should raise_error(ArgumentError)
+ lambda { @string.readpartial(-1) }.should raise_error(ArgumentError)
end
it "immediately returns an empty string if the length argument is 0" do
diff --git a/spec/ruby/library/stringio/reopen_spec.rb b/spec/ruby/library/stringio/reopen_spec.rb
index 7021ff17e5..abdecdf9de 100644
--- a/spec/ruby/library/stringio/reopen_spec.rb
+++ b/spec/ruby/library/stringio/reopen_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#reopen when passed [Object, Integer]" do
before :each do
@@ -12,35 +12,44 @@ describe "StringIO#reopen when passed [Object, Integer]" do
@io.closed_write?.should be_true
@io.string.should == "reopened"
- @io.reopen(+"reopened, twice", IO::WRONLY)
+ @io.reopen("reopened, twice", IO::WRONLY)
@io.closed_read?.should be_true
@io.closed_write?.should be_false
@io.string.should == "reopened, twice"
- @io.reopen(+"reopened, another time", IO::RDWR)
+ @io.reopen("reopened, another time", IO::RDWR)
@io.closed_read?.should be_false
@io.closed_write?.should be_false
@io.string.should == "reopened, another time"
end
+ # NOTE: WEIRD!
+ it "does not taint self when the passed Object was tainted" do
+ @io.reopen("reopened".taint, IO::RDONLY)
+ @io.tainted?.should be_false
+
+ @io.reopen("reopened".taint, IO::WRONLY)
+ @io.tainted?.should be_false
+ end
+
it "tries to convert the passed Object to a String using #to_str" do
obj = mock("to_str")
- obj.should_receive(:to_str).and_return(+"to_str")
+ obj.should_receive(:to_str).and_return("to_str")
@io.reopen(obj, IO::RDWR)
@io.string.should == "to_str"
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)
+ lambda { @io.reopen(Object.new, IO::RDWR) }.should raise_error(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)
+ lambda { @io.reopen("burn".freeze, IO::WRONLY) }.should raise_error(Errno::EACCES)
+ lambda { @io.reopen("burn".freeze, IO::WRONLY | IO::APPEND) }.should raise_error(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)
+ it "raises a RuntimeError when trying to reopen self with a frozen String in truncate-mode" do
+ lambda { @io.reopen("burn".freeze, IO::RDONLY | IO::TRUNC) }.should raise_error(RuntimeError)
end
it "does not raise IOError when passed a frozen String in read-mode" do
@@ -60,27 +69,36 @@ describe "StringIO#reopen when passed [Object, Object]" do
@io.closed_write?.should be_true
@io.string.should == "reopened"
- @io.reopen(+"reopened, twice", "r+")
+ @io.reopen("reopened, twice", "r+")
@io.closed_read?.should be_false
@io.closed_write?.should be_false
@io.string.should == "reopened, twice"
- @io.reopen(+"reopened, another", "w+")
+ @io.reopen("reopened, another", "w+")
@io.closed_read?.should be_false
@io.closed_write?.should be_false
@io.string.should == ""
- @io.reopen(+"reopened, another time", "r+")
+ @io.reopen("reopened, another time", "r+")
@io.closed_read?.should be_false
@io.closed_write?.should be_false
@io.string.should == "reopened, another time"
end
it "truncates the passed String when opened in truncate mode" do
- @io.reopen(str = +"reopened", "w")
+ @io.reopen(str = "reopened", "w")
str.should == ""
end
+ # NOTE: WEIRD!
+ it "does not taint self when the passed Object was tainted" do
+ @io.reopen("reopened".taint, "r")
+ @io.tainted?.should be_false
+
+ @io.reopen("reopened".taint, "w")
+ @io.tainted?.should be_false
+ end
+
it "tries to convert the passed Object to a String using #to_str" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return("to_str")
@@ -89,18 +107,18 @@ 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)
+ lambda { @io.reopen(Object.new, "r") }.should raise_error(TypeError)
end
it "resets self's position to 0" do
@io.read(5)
- @io.reopen(+"reopened")
+ @io.reopen("reopened")
@io.pos.should eql(0)
end
it "resets self's line number to 0" do
@io.gets
- @io.reopen(+"reopened")
+ @io.reopen("reopened")
@io.lineno.should eql(0)
end
@@ -114,10 +132,10 @@ describe "StringIO#reopen when passed [Object, Object]" do
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)
+ lambda { @io.reopen("burn".freeze, 'w') }.should raise_error(Errno::EACCES)
+ lambda { @io.reopen("burn".freeze, 'w+') }.should raise_error(Errno::EACCES)
+ lambda { @io.reopen("burn".freeze, 'a') }.should raise_error(Errno::EACCES)
+ lambda { @io.reopen("burn".freeze, "r+") }.should raise_error(Errno::EACCES)
end
it "does not raise IOError if a frozen string is passed in read mode" do
@@ -134,7 +152,7 @@ describe "StringIO#reopen when passed [String]" do
it "reopens self with the passed String in read-write mode" do
@io.close
- @io.reopen(+"reopened")
+ @io.reopen("reopened")
@io.closed_write?.should be_false
@io.closed_read?.should be_false
@@ -142,15 +160,21 @@ describe "StringIO#reopen when passed [String]" do
@io.string.should == "reopened"
end
+ # NOTE: WEIRD!
+ it "does not taint self when the passed Object was tainted" do
+ @io.reopen("reopened".taint)
+ @io.tainted?.should be_false
+ end
+
it "resets self's position to 0" do
@io.read(5)
- @io.reopen(+"reopened")
+ @io.reopen("reopened")
@io.pos.should eql(0)
end
it "resets self's line number to 0" do
@io.gets
- @io.reopen(+"reopened")
+ @io.reopen("reopened")
@io.lineno.should eql(0)
end
end
@@ -161,21 +185,27 @@ 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)
+ lambda { @io.reopen(Object.new) }.should raise_error(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)
+ lambda { @io.reopen(obj) }.should raise_error(TypeError)
end
it "tries to convert the passed Object to a StringIO using #to_strio" do
obj = mock("to_strio")
- obj.should_receive(:to_strio).and_return(StringIO.new(+"to_strio"))
+ obj.should_receive(:to_strio).and_return(StringIO.new("to_strio"))
@io.reopen(obj)
@io.string.should == "to_strio"
end
+
+ # NOTE: WEIRD!
+ it "taints self when the passed Object was tainted" do
+ @io.reopen(StringIO.new("reopened").taint)
+ @io.tainted?.should be_true
+ end
end
describe "StringIO#reopen when passed no arguments" do
@@ -208,40 +238,47 @@ end
# for details.
describe "StringIO#reopen" do
before :each do
- @io = StringIO.new(+'hello', 'a')
+ @io = StringIO.new('hello','a')
end
# TODO: find out if this is really a bug
it "reopens a stream when given a String argument" do
- @io.reopen(+'goodbye').should == @io
+ @io.reopen('goodbye').should == @io
@io.string.should == 'goodbye'
@io << 'x'
@io.string.should == 'xoodbye'
end
it "reopens a stream in append mode when flagged as such" do
- @io.reopen(+'goodbye', 'a').should == @io
+ @io.reopen('goodbye', 'a').should == @io
@io.string.should == 'goodbye'
@io << 'x'
@io.string.should == 'goodbyex'
end
it "reopens and truncate when reopened in write mode" do
- @io.reopen(+'goodbye', 'wb').should == @io
+ @io.reopen('goodbye', 'wb').should == @io
@io.string.should == ''
@io << 'x'
@io.string.should == 'x'
end
it "truncates the given string, not a copy" do
- str = +'goodbye'
+ str = 'goodbye'
@io.reopen(str, 'w')
@io.string.should == ''
str.should == ''
end
+ it "taints self if the provided StringIO argument is tainted" do
+ new_io = StringIO.new("tainted")
+ new_io.taint
+ @io.reopen(new_io)
+ @io.tainted?.should == true
+ end
+
it "does not truncate the content even when the StringIO argument is in the truncate mode" do
- orig_io = StringIO.new(+"Original StringIO", IO::RDWR|IO::TRUNC)
+ orig_io = StringIO.new("Original StringIO", IO::RDWR|IO::TRUNC)
orig_io.write("BLAH") # make sure the content is not empty
@io.reopen(orig_io)
diff --git a/spec/ruby/library/stringio/rewind_spec.rb b/spec/ruby/library/stringio/rewind_spec.rb
index 5f885ecf81..ef144a9f5f 100644
--- a/spec/ruby/library/stringio/rewind_spec.rb
+++ b/spec/ruby/library/stringio/rewind_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#rewind" do
before :each do
diff --git a/spec/ruby/library/stringio/seek_spec.rb b/spec/ruby/library/stringio/seek_spec.rb
index 253b5027a9..ec79122039 100644
--- a/spec/ruby/library/stringio/seek_spec.rb
+++ b/spec/ruby/library/stringio/seek_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#seek" do
before :each do
@@ -33,14 +33,14 @@ 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)
+ lambda { @io.seek(-5, IO::SEEK_SET) }.should raise_error(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)
+ lambda { @io.seek(0, 3) }.should raise_error(Errno::EINVAL)
+ lambda { @io.seek(0, -1) }.should raise_error(Errno::EINVAL)
+ lambda { @io.seek(0, 2**16) }.should raise_error(Errno::EINVAL)
+ lambda { @io.seek(0, -2**16) }.should raise_error(Errno::EINVAL)
end
it "tries to convert the passed Object to a String using #to_int" do
@@ -51,7 +51,7 @@ describe "StringIO#seek" 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)
+ lambda { @io.seek(Object.new) }.should raise_error(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)
+ lambda { @io.seek(5) }.should raise_error(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
deleted file mode 100644
index 1030aad042..0000000000
--- a/spec/ruby/library/stringio/set_encoding_by_bom_spec.rb
+++ /dev/null
@@ -1,237 +0,0 @@
-require 'stringio'
-require_relative '../../spec_helper'
-
-# Should be synced with specs for IO#set_encoding_by_bom
-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.external_encoding.should == Encoding::ASCII_8BIT
- end
-
- it "returns the result encoding if found BOM UTF-8 sequence" do
- io = StringIO.new("\u{FEFF}".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_8
- io.external_encoding.should == Encoding::UTF_8
- io.read.b.should == "".b
-
- io = StringIO.new("\u{FEFF}abc".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_8
- io.external_encoding.should == Encoding::UTF_8
- io.read.b.should == "abc".b
- end
-
- it "returns the result encoding if found BOM UTF_16LE sequence" do
- io = StringIO.new("\xFF\xFE".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_16LE
- io.external_encoding.should == Encoding::UTF_16LE
- io.read.b.should == "".b
-
- io = StringIO.new("\xFF\xFEabc".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_16LE
- io.external_encoding.should == Encoding::UTF_16LE
- io.read.b.should == "abc".b
- end
-
- it "returns the result encoding if found BOM UTF_16BE sequence" do
- io = StringIO.new("\xFE\xFF".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_16BE
- io.external_encoding.should == Encoding::UTF_16BE
- io.read.b.should == "".b
-
- io = StringIO.new("\xFE\xFFabc".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_16BE
- io.external_encoding.should == Encoding::UTF_16BE
- io.read.b.should == "abc".b
- end
-
- it "returns the result encoding if found BOM UTF_32LE sequence" do
- io = StringIO.new("\xFF\xFE\x00\x00".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_32LE
- io.external_encoding.should == Encoding::UTF_32LE
- io.read.b.should == "".b
-
- io = StringIO.new("\xFF\xFE\x00\x00abc".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_32LE
- io.external_encoding.should == Encoding::UTF_32LE
- io.read.b.should == "abc".b
- end
-
- it "returns the result encoding if found BOM UTF_32BE sequence" do
- io = StringIO.new("\x00\x00\xFE\xFF".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_32BE
- io.external_encoding.should == Encoding::UTF_32BE
- io.read.b.should == "".b
-
- io = StringIO.new("\x00\x00\xFE\xFFabc".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_32BE
- io.external_encoding.should == Encoding::UTF_32BE
- io.read.b.should == "abc".b
- end
-
- it "returns nil if io is empty" do
- io = StringIO.new("".b, "rb")
- io.set_encoding_by_bom.should be_nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- end
-
- it "returns nil if UTF-8 BOM sequence is incomplete" do
- io = StringIO.new("\xEF".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\xEF".b
-
- io = StringIO.new("\xEFa".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\xEFa".b
-
- io = StringIO.new("\xEF\xBB".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\xEF\xBB".b
-
- io = StringIO.new("\xEF\xBBa".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\xEF\xBBa".b
- end
-
- it "returns nil if UTF-16BE BOM sequence is incomplete" do
- io = StringIO.new("\xFE".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\xFE".b
-
- io = StringIO.new("\xFEa".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\xFEa".b
- end
-
- it "returns nil if UTF-16LE/UTF-32LE BOM sequence is incomplete" do
- io = StringIO.new("\xFF".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\xFF".b
-
- io = StringIO.new("\xFFa".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\xFFa".b
- end
-
- it "returns UTF-16LE if UTF-32LE BOM sequence is incomplete" do
- io = StringIO.new("\xFF\xFE".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_16LE
- io.external_encoding.should == Encoding::UTF_16LE
- io.read.b.should == "".b
-
- io = StringIO.new("\xFF\xFE\x00".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_16LE
- io.external_encoding.should == Encoding::UTF_16LE
- io.read.b.should == "\x00".b
-
- io = StringIO.new("\xFF\xFE\x00a".b, "rb")
-
- io.set_encoding_by_bom.should == Encoding::UTF_16LE
- io.external_encoding.should == Encoding::UTF_16LE
- io.read.b.should == "\x00a".b
- end
-
- it "returns nil if UTF-32BE BOM sequence is incomplete" do
- io = StringIO.new("\x00".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\x00".b
-
- io = StringIO.new("\x00a".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\x00a".b
-
- io = StringIO.new("\x00\x00".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\x00\x00".b
-
- io = StringIO.new("\x00\x00a".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\x00\x00a".b
-
- io = StringIO.new("\x00\x00\xFE".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\x00\x00\xFE".b
-
- io = StringIO.new("\x00\x00\xFEa".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read.b.should == "\x00\x00\xFEa".b
- end
-
- it "returns nil if found BOM sequence not provided" do
- io = StringIO.new("abc".b, "rb")
-
- io.set_encoding_by_bom.should == nil
- io.external_encoding.should == Encoding::ASCII_8BIT
- io.read(3).should == "abc".b
- end
-
- it "does not raise exception if io not in binary mode" do
- io = StringIO.new("", 'r')
- io.set_encoding_by_bom.should == nil
- end
-
- it "does not raise exception if encoding already set" do
- io = StringIO.new("".b, "rb")
- io.set_encoding("utf-8")
- io.set_encoding_by_bom.should == nil
- end
-
- it "does not raise exception if encoding conversion is already set" do
- io = StringIO.new("".b, "rb")
- io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE)
-
- io.set_encoding_by_bom.should == nil
- end
-
- it "raises FrozenError when io is frozen" do
- io = StringIO.new()
- io.freeze
- -> { io.set_encoding_by_bom }.should raise_error(FrozenError)
- end
-
- it "does not raise FrozenError when initial string is frozen" do
- io = StringIO.new("".freeze)
- io.set_encoding_by_bom.should == nil
- end
-end
diff --git a/spec/ruby/library/stringio/set_encoding_spec.rb b/spec/ruby/library/stringio/set_encoding_spec.rb
index 19ca0875bf..c66c70ab04 100644
--- a/spec/ruby/library/stringio/set_encoding_spec.rb
+++ b/spec/ruby/library/stringio/set_encoding_spec.rb
@@ -1,28 +1,10 @@
require 'stringio'
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
describe "StringIO#set_encoding" do
- it "sets the encoding of the underlying String if the String is not frozen" do
- str = "".encode(Encoding::US_ASCII)
-
- io = StringIO.new(str)
+ it "sets the encoding of the underlying String" do
+ io = StringIO.new
io.set_encoding Encoding::UTF_8
io.string.encoding.should == Encoding::UTF_8
end
-
- it "does not set the encoding of the underlying String if the String is frozen" do
- str = "".encode(Encoding::US_ASCII).freeze
-
- io = StringIO.new(str)
- io.set_encoding Encoding::UTF_8
- io.string.encoding.should == Encoding::US_ASCII
- end
-
- it "accepts a String" do
- str = "".encode(Encoding::US_ASCII)
- io = StringIO.new(str)
- io.set_encoding("ASCII-8BIT")
- io.external_encoding.should == Encoding::BINARY
- str.encoding.should == Encoding::BINARY
- end
end
diff --git a/spec/ruby/library/stringio/shared/codepoints.rb b/spec/ruby/library/stringio/shared/codepoints.rb
index 25333bb0fd..c8ca03329f 100644
--- a/spec/ruby/library/stringio/shared/codepoints.rb
+++ b/spec/ruby/library/stringio/shared/codepoints.rb
@@ -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)
+ lambda { @enum.first }.should raise_error(ArgumentError)
end
it "raises an IOError if not readable" do
@io.close_read
- -> { @enum.to_a }.should raise_error(IOError)
+ lambda { @enum.to_a }.should raise_error(IOError)
- io = StringIO.new(+"xyz", "w")
- -> { io.send(@method).to_a }.should raise_error(IOError)
+ io = StringIO.new("xyz", "w")
+ lambda { io.send(@method).to_a }.should raise_error(IOError)
end
diff --git a/spec/ruby/library/stringio/shared/each.rb b/spec/ruby/library/stringio/shared/each.rb
index e0dd3f9b8f..55ed27c1c7 100644
--- a/spec/ruby/library/stringio/shared/each.rb
+++ b/spec/ruby/library/stringio/shared/each.rb
@@ -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 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
@@ -82,12 +71,11 @@ describe :stringio_each_no_arguments, shared: true do
it "uses $/ as the default line separator" do
seen = []
begin
- old_rs = $/
- suppress_warning {$/ = " "}
+ old_rs, $/ = $/, " "
@io.send(@method) {|s| seen << s }
seen.should eql(["a ", "b ", "c ", "d ", "e\n1 ", "2 ", "3 ", "4 ", "5"])
ensure
- suppress_warning {$/ = old_rs}
+ $/ = old_rs
end
end
@@ -107,12 +95,12 @@ 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 = StringIO.new("a b c d e", "w")
+ lambda { io.send(@method) { |b| b } }.should raise_error(IOError)
io = StringIO.new("a b c d e")
io.close_read
- -> { io.send(@method) { |b| b } }.should raise_error(IOError)
+ lambda { io.send(@method) { |b| b } }.should raise_error(IOError)
end
end
@@ -123,41 +111,4 @@ describe :stringio_each_chomp, shared: true do
io.send(@method, chomp: true) {|s| seen << s }
seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"]
end
-
- it "returns each line with removed newline characters when called without block" do
- seen = []
- io = StringIO.new("a b \rc d e\n1 2 3 4 5\r\nthe end")
- enum = io.send(@method, chomp: true)
- enum.each {|s| seen << s }
- seen.should == ["a b \rc d e", "1 2 3 4 5", "the end"]
- end
-end
-
-describe :stringio_each_separator_and_chomp, shared: true do
- it "yields each line with removed separator to the passed block" do
- seen = []
- io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end")
- io.send(@method, "|", chomp: true) {|s| seen << s }
- seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"]
- end
-
- it "returns each line with removed separator when called without block" do
- seen = []
- io = StringIO.new("a b \nc d e|1 2 3 4 5\n|the end")
- enum = io.send(@method, "|", chomp: true)
- enum.each {|s| seen << s }
- seen.should == ["a b \nc d e", "1 2 3 4 5\n", "the end"]
- end
-end
-
-describe :stringio_each_limit, shared: true do
- before :each do
- @io = StringIO.new("a b c d e\n1 2 3 4 5")
- end
-
- it "returns the data read until the limit is met" do
- seen = []
- @io.send(@method, 4) { |s| seen << s }
- seen.should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"]
- end
end
diff --git a/spec/ruby/library/stringio/shared/each_byte.rb b/spec/ruby/library/stringio/shared/each_byte.rb
index b51fa38f2f..1dc48ee437 100644
--- a/spec/ruby/library/stringio/shared/each_byte.rb
+++ b/spec/ruby/library/stringio/shared/each_byte.rb
@@ -38,11 +38,11 @@ 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 = StringIO.new("xyz", "w")
+ lambda { io.send(@method) { |b| b } }.should raise_error(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.send(@method) { |b| b } }.should raise_error(IOError)
+ lambda { io.send(@method) { |b| b } }.should raise_error(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..35efdcb749 100644
--- a/spec/ruby/library/stringio/shared/each_char.rb
+++ b/spec/ruby/library/stringio/shared/each_char.rb
@@ -26,11 +26,11 @@ 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 = StringIO.new("xyz", "w")
+ lambda { io.send(@method) { |b| b } }.should raise_error(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.send(@method) { |b| b } }.should raise_error(IOError)
+ lambda { io.send(@method) { |b| b } }.should raise_error(IOError)
end
end
diff --git a/spec/ruby/library/stringio/shared/getc.rb b/spec/ruby/library/stringio/shared/getc.rb
index ba65040bce..3e064f9c1e 100644
--- a/spec/ruby/library/stringio/shared/getc.rb
+++ b/spec/ruby/library/stringio/shared/getc.rb
@@ -33,11 +33,11 @@ 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 = StringIO.new("xyz", "w")
+ lambda { io.send(@method) }.should raise_error(IOError)
io = StringIO.new("xyz")
io.close_read
- -> { io.send(@method) }.should raise_error(IOError)
+ lambda { io.send(@method) }.should raise_error(IOError)
end
end
diff --git a/spec/ruby/library/stringio/shared/isatty.rb b/spec/ruby/library/stringio/shared/isatty.rb
index c9e7ee7321..3da5999953 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 be_false
end
end
diff --git a/spec/ruby/library/stringio/shared/read.rb b/spec/ruby/library/stringio/shared/read.rb
index 8ef6ec2734..025829a2b1 100644
--- a/spec/ruby/library/stringio/shared/read.rb
+++ b/spec/ruby/library/stringio/shared/read.rb
@@ -5,48 +5,30 @@ describe :stringio_read, shared: true do
it "returns the passed buffer String" do
# Note: Rubinius bug:
- # @io.send(@method, 7, buffer = +"").should equal(buffer)
- ret = @io.send(@method, 7, buffer = +"")
+ # @io.send(@method, 7, buffer = "").should equal(buffer)
+ ret = @io.send(@method, 7, buffer = "")
ret.should equal(buffer)
end
it "reads length bytes and writes them to the buffer String" do
- @io.send(@method, 7, buffer = +"").should.equal?(buffer)
+ @io.send(@method, 7, buffer = "")
buffer.should == "example"
end
- ruby_version_is ""..."3.4" do
- it "does not preserve the encoding of the given buffer" do
- buffer = ''.encode(Encoding::ISO_8859_1)
- @io.send(@method, 7, buffer)
-
- buffer.encoding.should_not == Encoding::ISO_8859_1
- end
- end
-
- ruby_version_is "3.4" do
- it "preserves the encoding of the given buffer" do
- buffer = ''.encode(Encoding::ISO_8859_1)
- @io.send(@method, 7, buffer)
-
- buffer.encoding.should == Encoding::ISO_8859_1
- end
- end
-
it "tries to convert the passed buffer Object to a String using #to_str" do
obj = mock("to_str")
- obj.should_receive(:to_str).and_return(buffer = +"")
+ obj.should_receive(:to_str).and_return(buffer = "")
@io.send(@method, 7, obj)
buffer.should == "example"
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)
+ lambda { @io.send(@method, 7, Object.new) }.should raise_error(TypeError)
end
- it "raises a FrozenError error when passed a frozen String as buffer" do
- -> { @io.send(@method, 7, "".freeze) }.should raise_error(FrozenError)
+ it "raises an error when passed a frozen String as buffer" do
+ lambda { @io.send(@method, 7, "".freeze) }.should raise_error(RuntimeError)
end
end
@@ -79,21 +61,21 @@ 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)
+ lambda { @io.send(@method, Object.new) }.should raise_error(TypeError)
end
it "raises a TypeError when the passed length is negative" do
- -> { @io.send(@method, -2) }.should raise_error(ArgumentError)
+ lambda { @io.send(@method, -2) }.should raise_error(ArgumentError)
end
it "returns a binary String" do
- @io.send(@method, 4).encoding.should == Encoding::BINARY
+ @io.send(@method, 4).encoding.should == Encoding::ASCII_8BIT
end
end
describe :stringio_read_no_arguments, shared: true do
before :each do
- @io = StringIO.new(+"example")
+ @io = StringIO.new("example")
end
it "reads the whole content starting from the current position" do
@@ -107,12 +89,6 @@ describe :stringio_read_no_arguments, shared: true do
@io.send(@method)
@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)
- end
end
describe :stringio_read_nil, shared: true do
@@ -135,11 +111,11 @@ 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 = StringIO.new("test", "w")
+ lambda { io.send(@method) }.should raise_error(IOError)
io = StringIO.new("test")
io.close_read
- -> { io.send(@method) }.should raise_error(IOError)
+ lambda { io.send(@method) }.should raise_error(IOError)
end
end
diff --git a/spec/ruby/library/stringio/shared/readchar.rb b/spec/ruby/library/stringio/shared/readchar.rb
index 72d7446c36..19194f0680 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)
+ lambda { @io.send(@method) }.should raise_error(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 = StringIO.new("a b c d e", "w")
+ lambda { io.send(@method) }.should raise_error(IOError)
io = StringIO.new("a b c d e")
io.close_read
- -> { io.send(@method) }.should raise_error(IOError)
+ lambda { io.send(@method) }.should raise_error(IOError)
end
end
diff --git a/spec/ruby/library/stringio/shared/sysread.rb b/spec/ruby/library/stringio/shared/sysread.rb
index 3e23fbc233..9800b2339b 100644
--- a/spec/ruby/library/stringio/shared/sysread.rb
+++ b/spec/ruby/library/stringio/shared/sysread.rb
@@ -1,4 +1,4 @@
-describe :stringio_sysread_length, shared: true do
+describe :stringio_sysread_length, :shared => true do
before :each do
@io = StringIO.new("example")
end
@@ -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)
+ lambda { @io.sysread(1) }.should raise_error(EOFError)
end
end
diff --git a/spec/ruby/library/stringio/shared/write.rb b/spec/ruby/library/stringio/shared/write.rb
index 4661658baf..bcb548bbd0 100644
--- a/spec/ruby/library/stringio/shared/write.rb
+++ b/spec/ruby/library/stringio/shared/write.rb
@@ -1,6 +1,6 @@
describe :stringio_write, shared: true do
before :each do
- @io = StringIO.new(+'12345')
+ @io = StringIO.new('12345')
end
it "tries to convert the passed Object to a String using #to_s" do
@@ -13,7 +13,7 @@ end
describe :stringio_write_string, shared: true do
before :each do
- @io = StringIO.new(+'12345')
+ @io = StringIO.new('12345')
end
# TODO: RDoc says that #write appends at the current position.
@@ -45,79 +45,31 @@ describe :stringio_write_string, shared: true do
@io.pos.should eql(4)
end
- it "handles concurrent writes correctly" do
- @io = StringIO.new
- n = 8
- go = false
- threads = n.times.map { |i|
- Thread.new {
- Thread.pass until go
- @io.write i.to_s
- }
- }
- go = true
- threads.each(&:join)
- @io.string.size.should == n.times.map(&:to_s).join.size
+ it "taints self's String when the passed argument is tainted" do
+ @io.send(@method, "test".taint)
+ @io.string.tainted?.should be_true
end
- it "handles writing non-ASCII UTF-8 after seek" do
- @io.binmode
- @io << "\x80"
- @io.pos = 0
- @io << "\x81"
- @io.string.should == "\x812345".b
- end
-
- it "handles writing with position < buffer size" do
- @io.pos = 2
- @io.write "abc"
- @io.string.should == "12abc"
-
- @io.pos = 2
- @io.write "de"
- @io.string.should == "12dec"
-
- @io.pos = 2
- @io.write "fghi"
- @io.string.should == "12fghi"
- end
-
- it "transcodes the given string when the external encoding is set and neither is BINARY" do
- utf8_str = "hello"
- io = StringIO.new.set_encoding(Encoding::UTF_16BE)
- io.external_encoding.should == Encoding::UTF_16BE
-
- io.send(@method, utf8_str)
-
- expected = [0, 104, 0, 101, 0, 108, 0, 108, 0, 111] # UTF-16BE bytes for "hello"
- io.string.bytes.should == expected
- end
-
- it "does not transcode the given string when the external encoding is set and the string encoding is BINARY" do
- str = "été_".b
- io = StringIO.new.set_encoding(Encoding::UTF_16BE)
- io.external_encoding.should == Encoding::UTF_16BE
-
- io.send(@method, str)
-
- io.string.bytes.should == str.bytes
+ it "does not taint self when the passed argument is tainted" do
+ @io.send(@method, "test".taint)
+ @io.tainted?.should be_false
end
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 = StringIO.new("test", "r")
+ lambda { io.send(@method, "test") }.should raise_error(IOError)
- io = StringIO.new(+"test")
+ io = StringIO.new("test")
io.close_write
- -> { io.send(@method, "test") }.should raise_error(IOError)
+ lambda { io.send(@method, "test") }.should raise_error(IOError)
end
end
describe :stringio_write_append, shared: true do
before :each do
- @io = StringIO.new(+"example", "a")
+ @io = StringIO.new("example", "a")
end
it "appends the passed argument to the end of self" do
diff --git a/spec/ruby/library/stringio/size_spec.rb b/spec/ruby/library/stringio/size_spec.rb
index f674d22db9..1d6a7fc15e 100644
--- a/spec/ruby/library/stringio/size_spec.rb
+++ b/spec/ruby/library/stringio/size_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/length'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/length', __FILE__)
describe "StringIO#size" do
it_behaves_like :stringio_length, :size
diff --git a/spec/ruby/library/stringio/string_spec.rb b/spec/ruby/library/stringio/string_spec.rb
index 1ed5233ba6..7c4181b6de 100644
--- a/spec/ruby/library/stringio/string_spec.rb
+++ b/spec/ruby/library/stringio/string_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#string" do
it "returns the underlying string" 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)
+ lambda { @io.seek(Object.new) }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/library/stringio/stringio_spec.rb b/spec/ruby/library/stringio/stringio_spec.rb
index 5ef42b3390..9e2cb9cf90 100644
--- a/spec/ruby/library/stringio/stringio_spec.rb
+++ b/spec/ruby/library/stringio/stringio_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require "stringio"
describe "StringIO" do
@@ -6,3 +6,4 @@ describe "StringIO" do
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..b662d7b7cc 100644
--- a/spec/ruby/library/stringio/sync_spec.rb
+++ b/spec/ruby/library/stringio/sync_spec.rb
@@ -1,5 +1,5 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#sync" do
it "returns true" do
diff --git a/spec/ruby/library/stringio/sysread_spec.rb b/spec/ruby/library/stringio/sysread_spec.rb
index fabb06dd9a..cce8d8c88a 100644
--- a/spec/ruby/library/stringio/sysread_spec.rb
+++ b/spec/ruby/library/stringio/sysread_spec.rb
@@ -1,7 +1,6 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require "stringio"
-require_relative 'shared/read'
-require_relative 'shared/sysread'
+require File.expand_path('../shared/read', __FILE__)
describe "StringIO#sysread when passed length, buffer" do
it_behaves_like :stringio_read, :sysread
@@ -33,10 +32,6 @@ describe "StringIO#sysread when passed nil" do
end
end
-describe "StringIO#sysread when passed length" do
- it_behaves_like :stringio_sysread_length, :sysread
-end
-
describe "StringIO#sysread when passed [length]" do
before :each do
@io = StringIO.new("example")
@@ -44,7 +39,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)
+ lambda { @io.sysread(10) }.should raise_error(EOFError)
end
it "returns an empty String when length is 0" do
diff --git a/spec/ruby/library/stringio/syswrite_spec.rb b/spec/ruby/library/stringio/syswrite_spec.rb
index c4891e669b..8b65e81a05 100644
--- a/spec/ruby/library/stringio/syswrite_spec.rb
+++ b/spec/ruby/library/stringio/syswrite_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/write'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/write', __FILE__)
describe "StringIO#syswrite when passed [Object]" do
it_behaves_like :stringio_write, :syswrite
diff --git a/spec/ruby/library/stringio/tell_spec.rb b/spec/ruby/library/stringio/tell_spec.rb
index 8350ee6f4d..af6a01497e 100644
--- a/spec/ruby/library/stringio/tell_spec.rb
+++ b/spec/ruby/library/stringio/tell_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/tell'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/tell', __FILE__)
describe "StringIO#tell" do
it_behaves_like :stringio_tell, :tell
diff --git a/spec/ruby/library/stringio/truncate_spec.rb b/spec/ruby/library/stringio/truncate_spec.rb
index 592ca5a6e1..1023b3d13c 100644
--- a/spec/ruby/library/stringio/truncate_spec.rb
+++ b/spec/ruby/library/stringio/truncate_spec.rb
@@ -1,13 +1,15 @@
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require "stringio"
describe "StringIO#truncate when passed [length]" do
before :each do
- @io = StringIO.new(+'123456789')
+ @io = StringIO.new('123456789')
end
- it "returns an Integer" do
- @io.truncate(4).should be_kind_of(Integer)
+ # TODO: Report to Ruby-Core: The RDoc says it always returns 0
+ it "returns the passed length" do
+ @io.truncate(4).should eql(4)
+ @io.truncate(10).should eql(10)
end
it "truncated the underlying string down to the passed length" do
@@ -16,7 +18,7 @@ describe "StringIO#truncate when passed [length]" do
end
it "does not create a copy of the underlying string" do
- io = StringIO.new(str = +"123456789")
+ io = StringIO.new(str = "123456789")
io.truncate(4)
io.string.should equal(str)
end
@@ -33,8 +35,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)
+ lambda { @io.truncate(-1) }.should raise_error(Errno::EINVAL)
+ lambda { @io.truncate(-10) }.should raise_error(Errno::EINVAL)
end
it "tries to convert the passed length to an Integer using #to_int" do
@@ -45,18 +47,24 @@ describe "StringIO#truncate when passed [length]" do
@io.string.should == "1234"
end
+ it "returns the passed length Object, NOT the result of #to_int" do
+ obj = mock("to_int")
+ obj.should_receive(:to_int).and_return(4)
+ @io.truncate(obj).should equal(obj)
+ 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)
+ lambda { @io.truncate(Object.new) }.should raise_error(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 = StringIO.new("test", "r")
+ lambda { io.truncate(2) }.should raise_error(IOError)
- io = StringIO.new(+"test")
+ io = StringIO.new("test")
io.close_write
- -> { io.truncate(2) }.should raise_error(IOError)
+ lambda { io.truncate(2) }.should raise_error(IOError)
end
end
diff --git a/spec/ruby/library/stringio/tty_spec.rb b/spec/ruby/library/stringio/tty_spec.rb
index c6293dcbd7..7540e68a2b 100644
--- a/spec/ruby/library/stringio/tty_spec.rb
+++ b/spec/ruby/library/stringio/tty_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/isatty'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/isatty', __FILE__)
describe "StringIO#tty?" do
it_behaves_like :stringio_isatty, :tty?
diff --git a/spec/ruby/library/stringio/ungetbyte_spec.rb b/spec/ruby/library/stringio/ungetbyte_spec.rb
index 87b27b837e..a7d9b28024 100644
--- a/spec/ruby/library/stringio/ungetbyte_spec.rb
+++ b/spec/ruby/library/stringio/ungetbyte_spec.rb
@@ -1,42 +1,6 @@
-# frozen_string_literal: false
-require_relative '../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require 'stringio'
describe "StringIO#ungetbyte" do
- it "ungets a single byte from a string starting with a single byte character" do
- str = 'This is a simple string.'
- io = StringIO.new("#{str}")
- c = io.getc
- c.should == 'T'
- io.ungetbyte(83)
- io.string.should == 'Shis is a simple string.'
- end
-
- it "ungets a single byte from a string in the middle of a multibyte character" do
- str = "\u01a9"
- io = StringIO.new(str)
- b = io.getbyte
- b.should == 0xc6 # First byte of UTF-8 encoding of \u01a9
- io.ungetbyte(0xce) # First byte of UTF-8 encoding of \u03a9
- io.string.should == "\u03a9"
- end
-
- it "constrains the value of a numeric argument to a single byte" do
- str = 'This is a simple string.'
- io = StringIO.new("#{str}")
- c = io.getc
- c.should == 'T'
- io.ungetbyte(83 | 0xff00)
- io.string.should == 'Shis is a simple string.'
- end
-
- it "ungets the bytes of a string if given a string as an argument" do
- str = "\u01a9"
- io = StringIO.new(str)
- b = io.getbyte
- b.should == 0xc6 # First byte of UTF-8 encoding of \u01a9
- io.ungetbyte("\u01a9")
- io.string.bytes.should == [198, 169, 169]
- end
-
+ it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/library/stringio/ungetc_spec.rb b/spec/ruby/library/stringio/ungetc_spec.rb
index bceafa79ff..613d49cfbd 100644
--- a/spec/ruby/library/stringio/ungetc_spec.rb
+++ b/spec/ruby/library/stringio/ungetc_spec.rb
@@ -1,9 +1,9 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
describe "StringIO#ungetc when passed [char]" do
before :each do
- @io = StringIO.new(+'1234')
+ @io = StringIO.new('1234')
end
it "writes the passed char before the current position" do
@@ -39,20 +39,20 @@ 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)
+ lambda { @io.ungetc(Object.new) }.should raise_error(TypeError)
end
end
describe "StringIO#ungetc when self is not readable" do
it "raises an IOError" do
- io = StringIO.new(+"test", "w")
+ io = StringIO.new("test", "w")
io.pos = 1
- -> { io.ungetc(?A) }.should raise_error(IOError)
+ lambda { io.ungetc(?A) }.should raise_error(IOError)
- io = StringIO.new(+"test")
+ io = StringIO.new("test")
io.pos = 1
io.close_read
- -> { io.ungetc(?A) }.should raise_error(IOError)
+ lambda { io.ungetc(?A) }.should raise_error(IOError)
end
end
@@ -60,11 +60,11 @@ end
#
# describe "StringIO#ungetc when self is not writable" do
# it "raises an IOError" do
-# io = StringIO.new(+"test", "r")
+# io = StringIO.new("test", "r")
# io.pos = 1
# lambda { io.ungetc(?A) }.should raise_error(IOError)
#
-# io = StringIO.new(+"test")
+# io = StringIO.new("test")
# io.pos = 1
# io.close_write
# lambda { io.ungetc(?A) }.should raise_error(IOError)
diff --git a/spec/ruby/library/stringio/write_nonblock_spec.rb b/spec/ruby/library/stringio/write_nonblock_spec.rb
index b48ef6698a..d4d5ab5a85 100644
--- a/spec/ruby/library/stringio/write_nonblock_spec.rb
+++ b/spec/ruby/library/stringio/write_nonblock_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/write'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/write', __FILE__)
describe "StringIO#write_nonblock when passed [Object]" do
it_behaves_like :stringio_write, :write_nonblock
@@ -8,12 +8,6 @@ end
describe "StringIO#write_nonblock when passed [String]" do
it_behaves_like :stringio_write_string, :write_nonblock
-
- it "accepts :exception option" do
- io = StringIO.new(+"12345", "a")
- io.write_nonblock("67890", exception: true)
- io.string.should == "1234567890"
- end
end
describe "StringIO#write_nonblock when self is not writable" do
diff --git a/spec/ruby/library/stringio/write_spec.rb b/spec/ruby/library/stringio/write_spec.rb
index 3f755c32b4..706234da7e 100644
--- a/spec/ruby/library/stringio/write_spec.rb
+++ b/spec/ruby/library/stringio/write_spec.rb
@@ -1,6 +1,6 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/write'
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/write', __FILE__)
describe "StringIO#write when passed [Object]" do
it_behaves_like :stringio_write, :write