Skip to content

Commit

Permalink
Add message matchers for exception specs in IO#pwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
herwinw committed Oct 28, 2023
1 parent 82e1948 commit 4b4fe97
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/io/pwrite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
end

it "calls #to_s on the object to be written" do
data = mock("to_s")
data.should_receive(:to_s).and_return("foo")
@file.pwrite(data, 0)
object = mock("to_s")
object.should_receive(:to_s).and_return("foo")
@file.pwrite(object, 0)
@file.pread(3, 0).should == "foo"
end

Expand All @@ -44,17 +44,17 @@

it "raises IOError when file is not open in write mode" do
File.open(@fname, "r") do |file|
-> { file.pwrite("foo", 1) }.should raise_error(IOError)
-> { file.pwrite("foo", 1) }.should raise_error(IOError, "not opened for writing")
end
end

it "raises IOError when file is closed" do
file = File.open(@fname, "w+")
file.close
-> { file.pwrite("foo", 1) }.should raise_error(IOError)
-> { file.pwrite("foo", 1) }.should raise_error(IOError, "closed stream")
end

it "raises a NoMethodError if #to_s cannot be called on the object to be written" do
it "raises a NoMethodError if object does not respond to #to_s" do
-> {
@file.pwrite(BasicObject.new, 0)
}.should raise_error(NoMethodError, /undefined method `to_s'/)
Expand Down

0 comments on commit 4b4fe97

Please sign in to comment.