-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specs for IO#autoclose? and IO#autoclose=
The actual behaviour is still untested.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'fixtures/classes' | ||
|
||
describe "IO#autoclose" do | ||
before :each do | ||
@io = IOSpecs.io_fixture "lines.txt" | ||
end | ||
|
||
after :each do | ||
@io.close unless @io.closed? | ||
end | ||
|
||
it "can be set to true" do | ||
@io.autoclose = true | ||
@io.should.autoclose? | ||
end | ||
|
||
it "can be set to false" do | ||
@io.autoclose = false | ||
@io.should_not.autoclose? | ||
end | ||
|
||
it "can be set to any truthy value" do | ||
@io.autoclose = 42 | ||
@io.should.autoclose? | ||
end | ||
|
||
it "can be set multple times" do | ||
@io.autoclose = true | ||
@io.should.autoclose? | ||
|
||
@io.autoclose = false | ||
@io.should_not.autoclose? | ||
|
||
@io.autoclose = true | ||
@io.should.autoclose? | ||
end | ||
end | ||
|
||
describe "IO#autoclose" do | ||
before :each do | ||
@name = tmp("io_autoclose.txt") | ||
end | ||
|
||
after :each do | ||
rm_r @name | ||
end | ||
|
||
it "cannot be queried on a closed IO object" do | ||
io = new_io(@name, "w:utf-8") | ||
io.close | ||
-> { io.autoclose? }.should raise_error(IOError, /closed stream/) | ||
end | ||
|
||
it "cannot be set on a closed IO object" do | ||
io = new_io(@name, "w:utf-8") | ||
io.close | ||
-> { io.autoclose = false }.should raise_error(IOError, /closed stream/) | ||
end | ||
end |