Skip to content

Commit

Permalink
Close open files after the spec is finished, or 120+ specs would fail…
Browse files Browse the repository at this point in the history
… on Windows
  • Loading branch information
vvs committed Jan 9, 2010
1 parent e65fd28 commit df1eedf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions core/file/new_spec.rb
Expand Up @@ -123,15 +123,15 @@
it "coerces filename using to_str" do
name = mock("file")
name.should_receive(:to_str).and_return(@file)
File.new(name, "w") { }
@fh = File.new(name, "w")
File.exists?(@file).should == true
end

ruby_version_is "1.9" do
it "coerces filename using #to_path" do
name = mock("file")
name.should_receive(:to_path).and_return(@file)
File.new(name, "w") { }
@fh = File.new(name, "w")
File.exists?(@file).should == true
end
end
Expand Down
17 changes: 11 additions & 6 deletions core/file/open_spec.rb
Expand Up @@ -15,9 +15,9 @@
end

after :each do
@fh.close if @fh and not @fh.closed?
File.delete(@file) if File.exist?(@file)
File.delete("fake") if File.exist?("fake")
@fh.close if @fh and not @fh.closed?
end

it "with block does not raise error when file is closed inside the block" do
Expand Down Expand Up @@ -59,6 +59,7 @@ def close
class << f
alias_method(:close_orig, :close)
def close
close_orig
raise IOError
end
end
Expand Down Expand Up @@ -432,10 +433,14 @@ def close
end

it "opens a file when use File::WRONLY|File::TRUNC mode" do
File.open(@file, "w")
@fh = File.open(@file, File::WRONLY|File::TRUNC)
@fh.should be_kind_of(File)
File.exist?(@file).should == true
fh1 = File.open(@file, "w")
begin
@fh = File.open(@file, File::WRONLY|File::TRUNC)
@fh.should be_kind_of(File)
File.exist?(@file).should == true
ensure
fh1.close
end
end

platform_is_not :openbsd do
Expand Down Expand Up @@ -477,7 +482,7 @@ def close
it "raises an Errno::EACCES when opening non-permitted file" do
@fh = File.open(@file, "w")
@fh.chmod(000)
lambda { File.open(@file) }.should raise_error(Errno::EACCES)
lambda { fh1 = File.open(@file); fh1.close }.should raise_error(Errno::EACCES)
end

it "raises an Errno::EACCES when opening read-only file" do
Expand Down
20 changes: 11 additions & 9 deletions core/file/shared/stat.rb
Expand Up @@ -22,16 +22,18 @@
end

it "should be able to use the instance methods" do
st = File.new(@file).send(@method)
File.open(@file) do |f|
st = f.send(@method)

st.file?.should == true
st.zero?.should == false
st.size.should == 8
st.size?.should == 8
st.blksize.should > 0
st.atime.should be_kind_of(Time)
st.ctime.should be_kind_of(Time)
st.mtime.should be_kind_of(Time)
st.file?.should == true
st.zero?.should == false
st.size.should == 8
st.size?.should == 8
st.blksize.should > 0
st.atime.should be_kind_of(Time)
st.ctime.should be_kind_of(Time)
st.mtime.should be_kind_of(Time)
end
end

ruby_version_is "1.9" do
Expand Down

0 comments on commit df1eedf

Please sign in to comment.