-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specs to verify ClosedError is raised
- Loading branch information
Showing
2 changed files
with
64 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,63 @@ | ||
require "spec" | ||
require "../src/lavinmq/mfile" | ||
|
||
module MFileSpec | ||
def self.with_file(&) | ||
file = File.tempfile "mfile_spec" | ||
yield file | ||
ensure | ||
file.delete unless file.nil? | ||
end | ||
|
||
describe MFile do | ||
describe "#write" do | ||
it "should raise ClosedError if closed" do | ||
with_file do |file| | ||
mfile = MFile.new file.path | ||
mfile.close | ||
expect_raises(MFile::ClosedError) { mfile.write "foo".to_slice } | ||
end | ||
end | ||
end | ||
describe "#read" do | ||
it "should raise ClosedError if closed" do | ||
with_file do |file| | ||
mfile = MFile.new file.path | ||
mfile.close | ||
data = Bytes.new(1) | ||
expect_raises(MFile::ClosedError) { mfile.read data } | ||
end | ||
end | ||
end | ||
describe "#to_slice" do | ||
describe "without position and size" do | ||
it "should raise ClosedError if closed" do | ||
with_file do |file| | ||
mfile = MFile.new file.path | ||
mfile.close | ||
expect_raises(MFile::ClosedError) { mfile.to_slice } | ||
end | ||
end | ||
end | ||
describe "with position and size" do | ||
it "should raise ClosedError if closed" do | ||
with_file do |file| | ||
mfile = MFile.new file.path | ||
mfile.close | ||
expect_raises(MFile::ClosedError) { mfile.to_slice(1, 1) } | ||
end | ||
end | ||
end | ||
end | ||
describe "#copy_to" do | ||
it "should raise ClosedError if closed" do | ||
with_file do |file| | ||
mfile = MFile.new file.path | ||
mfile.close | ||
data = IO::Memory.new | ||
expect_raises(MFile::ClosedError) { mfile.copy_to data } | ||
end | ||
end | ||
end | ||
end | ||
end |
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