summaryrefslogtreecommitdiff
path: root/spec/ruby/core/io/shared/binwrite.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/io/shared/binwrite.rb')
-rw-r--r--spec/ruby/core/io/shared/binwrite.rb27
1 files changed, 20 insertions, 7 deletions
diff --git a/spec/ruby/core/io/shared/binwrite.rb b/spec/ruby/core/io/shared/binwrite.rb
index 1a88442a3b..e51093329b 100644
--- a/spec/ruby/core/io/shared/binwrite.rb
+++ b/spec/ruby/core/io/shared/binwrite.rb
@@ -21,12 +21,20 @@ 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_error(ArgumentError, "wrong number of arguments (given 4, expected 2..3)")
+ end
+
it "creates a file if missing" do
fn = @filename + "xxx"
begin
- File.exist?(fn).should be_false
+ File.should_not.exist?(fn)
IO.send(@method, fn, "test")
- File.exist?(fn).should be_true
+ File.should.exist?(fn)
ensure
rm_r fn
end
@@ -35,9 +43,9 @@ describe :io_binwrite, shared: true do
it "creates file if missing even if offset given" do
fn = @filename + "xxx"
begin
- File.exist?(fn).should be_false
+ File.should_not.exist?(fn)
IO.send(@method, fn, "test", 0)
- File.exist?(fn).should be_true
+ File.should.exist?(fn)
ensure
rm_r fn
end
@@ -56,7 +64,7 @@ describe :io_binwrite, shared: true do
end
it "doesn't truncate and writes at the given offset after passing empty opts" do
- IO.send(@method, @filename, "hello world!", 1, {})
+ IO.send(@method, @filename, "hello world!", 1, **{})
File.read(@filename).should == "0hello world!34567890123456789"
end
@@ -67,12 +75,17 @@ 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
- lambda { IO.send(@method, @filename, "abcde", mode: "r") }.should raise_error(IOError)
+ -> { IO.send(@method, @filename, "abcde", mode: "r") }.should raise_error(IOError)
end
it "truncates if empty :opts provided and offset skipped" do
- IO.send(@method, @filename, "hello, world!", {})
+ IO.send(@method, @filename, "hello, world!", **{})
File.read(@filename).should == "hello, world!"
end
end