diff options
Diffstat (limited to 'spec/ruby/core/io/shared/new.rb')
-rw-r--r-- | spec/ruby/core/io/shared/new.rb | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb index 2101958170..cc76955784 100644 --- a/spec/ruby/core/io/shared/new.rb +++ b/spec/ruby/core/io/shared/new.rb @@ -89,59 +89,59 @@ describe :io_new, shared: true do end it "uses the external encoding specified via the :external_encoding option" do - @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8'}) + @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8') @io.external_encoding.to_s.should == 'UTF-8' end it "uses the internal encoding specified via the :internal_encoding option" do - @io = IO.send(@method, @fd, 'w', {internal_encoding: 'ibm866'}) + @io = IO.send(@method, @fd, 'w', internal_encoding: 'ibm866') @io.internal_encoding.to_s.should == 'IBM866' end it "uses the colon-separated encodings specified via the :encoding option" do - @io = IO.send(@method, @fd, 'w', {encoding: 'utf-8:ISO-8859-1'}) + @io = IO.send(@method, @fd, 'w', encoding: 'utf-8:ISO-8859-1') @io.external_encoding.to_s.should == 'UTF-8' @io.internal_encoding.to_s.should == 'ISO-8859-1' end it "uses the :encoding option as the external encoding when only one is given" do - @io = IO.send(@method, @fd, 'w', {encoding: 'ISO-8859-1'}) + @io = IO.send(@method, @fd, 'w', encoding: 'ISO-8859-1') @io.external_encoding.to_s.should == 'ISO-8859-1' end it "uses the :encoding options as the external encoding when it's an Encoding object" do - @io = IO.send(@method, @fd, 'w', {encoding: Encoding::ISO_8859_1}) + @io = IO.send(@method, @fd, 'w', encoding: Encoding::ISO_8859_1) @io.external_encoding.should == Encoding::ISO_8859_1 end it "ignores the :encoding option when the :external_encoding option is present" do -> { - @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', encoding: 'iso-8859-1:iso-8859-1'}) + @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8', encoding: 'iso-8859-1:iso-8859-1') }.should complain(/Ignoring encoding parameter/) @io.external_encoding.to_s.should == 'UTF-8' end it "ignores the :encoding option when the :internal_encoding option is present" do -> { - @io = IO.send(@method, @fd, 'w', {internal_encoding: 'ibm866', encoding: 'iso-8859-1:iso-8859-1'}) + @io = IO.send(@method, @fd, 'w', internal_encoding: 'ibm866', encoding: 'iso-8859-1:iso-8859-1') }.should complain(/Ignoring encoding parameter/) @io.internal_encoding.to_s.should == 'IBM866' end it "uses the encoding specified via the :mode option hash" do - @io = IO.send(@method, @fd, {mode: 'w:utf-8:ISO-8859-1'}) + @io = IO.send(@method, @fd, mode: 'w:utf-8:ISO-8859-1') @io.external_encoding.to_s.should == 'UTF-8' @io.internal_encoding.to_s.should == 'ISO-8859-1' end it "ignores the :internal_encoding option when the same as the external encoding" do - @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', internal_encoding: 'utf-8'}) + @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8', internal_encoding: 'utf-8') @io.external_encoding.to_s.should == 'UTF-8' @io.internal_encoding.to_s.should == '' end it "sets internal encoding to nil when passed '-'" do - @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', internal_encoding: '-'}) + @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8', internal_encoding: '-') @io.external_encoding.to_s.should == 'UTF-8' @io.internal_encoding.to_s.should == '' end @@ -157,12 +157,12 @@ describe :io_new, shared: true do end it "sets binmode from :binmode option" do - @io = IO.send(@method, @fd, 'w', {binmode: true}) + @io = IO.send(@method, @fd, 'w', binmode: true) @io.binmode?.should == true end it "does not set binmode from false :binmode" do - @io = IO.send(@method, @fd, 'w', {binmode: false}) + @io = IO.send(@method, @fd, 'w', binmode: false) @io.binmode?.should == false end @@ -173,7 +173,7 @@ describe :io_new, shared: true do # #5917 it "sets external encoding to binary with :binmode option" do - @io = IO.send(@method, @fd, 'w', {binmode: true}) + @io = IO.send(@method, @fd, 'w', binmode: true) @io.external_encoding.should == Encoding::BINARY end @@ -198,7 +198,9 @@ describe :io_new, shared: true do end it "accepts nil options" do - @io = IO.send(@method, @fd, 'w', nil) + @io = suppress_keyword_warning do + IO.send(@method, @fd, 'w', nil) + end @io.write("foo").should == 3 end @@ -247,13 +249,13 @@ describe :io_new, shared: true do it "coerces options as third argument with #to_hash" do options = mock("options") options.should_receive(:to_hash).and_return({}) - @io = IO.send(@method, @fd, 'w', options) + @io = IO.send(@method, @fd, 'w', **options) end it "coerces options as second argument with #to_hash" do options = mock("options") options.should_receive(:to_hash).and_return({}) - @io = IO.send(@method, @fd, options) + @io = IO.send(@method, @fd, **options) end it "accepts an :autoclose option" do @@ -307,13 +309,13 @@ describe :io_new_errors, shared: true do it "raises an error if passed encodings two ways" do -> { - @io = IO.send(@method, @fd, 'w:ISO-8859-1', {encoding: 'ISO-8859-1'}) + @io = IO.send(@method, @fd, 'w:ISO-8859-1', encoding: 'ISO-8859-1') }.should raise_error(ArgumentError) -> { - @io = IO.send(@method, @fd, 'w:ISO-8859-1', {external_encoding: 'ISO-8859-1'}) + @io = IO.send(@method, @fd, 'w:ISO-8859-1', external_encoding: 'ISO-8859-1') }.should raise_error(ArgumentError) -> { - @io = IO.send(@method, @fd, 'w:ISO-8859-1:UTF-8', {internal_encoding: 'ISO-8859-1'}) + @io = IO.send(@method, @fd, 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1') }.should raise_error(ArgumentError) end @@ -372,7 +374,9 @@ describe :io_new_errors, shared: true do it "raises TypeError if passed a hash for mode and nil for options" do -> { - @io = IO.send(@method, @fd, {mode: 'w'}, nil) + suppress_keyword_warning do + @io = IO.send(@method, @fd, {mode: 'w'}, nil) + end }.should raise_error(TypeError) end end |