diff options
Diffstat (limited to 'spec/ruby/core/io/shared/binwrite.rb')
| -rw-r--r-- | spec/ruby/core/io/shared/binwrite.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/spec/ruby/core/io/shared/binwrite.rb b/spec/ruby/core/io/shared/binwrite.rb index 3649bb47ff..64793b1936 100644 --- a/spec/ruby/core/io/shared/binwrite.rb +++ b/spec/ruby/core/io/shared/binwrite.rb @@ -21,6 +21,14 @@ describe :io_binwrite, shared: true do IO.send(@method, @filename, "abcde").should == 5 end + it "accepts options as a keyword argument" do + IO.send(@method, @filename, "hi", 0, flags: File::CREAT).should == 2 + + -> { + IO.send(@method, @filename, "hi", 0, {flags: File::CREAT}) + }.should.raise(ArgumentError, "wrong number of arguments (given 4, expected 2..3)") + end + it "creates a file if missing" do fn = @filename + "xxx" begin @@ -67,8 +75,13 @@ describe :io_binwrite, shared: true do File.read(@filename).should == "\0\0foo" end + it "accepts a :flags option without :mode one" do + IO.send(@method, @filename, "hello, world!", flags: File::CREAT) + File.read(@filename).should == "hello, world!" + end + it "raises an error if readonly mode is specified" do - -> { IO.send(@method, @filename, "abcde", mode: "r") }.should raise_error(IOError) + -> { IO.send(@method, @filename, "abcde", mode: "r") }.should.raise(IOError) end it "truncates if empty :opts provided and offset skipped" do |
