Skip to content

Instantly share code, notes, and snippets.

@jfirebaugh
Created February 2, 2012 04:03
Show Gist options
  • Select an option

  • Save jfirebaugh/1721366 to your computer and use it in GitHub Desktop.

Select an option

Save jfirebaugh/1721366 to your computer and use it in GitHub Desktop.
describe "File.new" do
it_behaves_like :file_new, :new
end
describe "File.open" do
it_behaves_like :file_new, :open
end
describe :file_new, :shared => true do
# before :each do ...
# after :each do ...
describe :file_new_rdonly, :shared => true do
it "is readable" do
@fh = File.send(@method, @file, @object)
@fh.gets.should == nil
end
it "raises IOError when written" do
@fh = File.send(@method, @file, @object)
lambda { @fh.write "writing" }.should raise_error(IOError)
end
it "raises ENOENT if the file does not exist" do
lambda { File.send(@method, @nonexistent, @object) }.should raise_error(Errno::ENOENT)
end
end
describe "in 'r' mode" do
it_behaves_like :file_new_rdonly, @method, 'r'
end
describe "in RDONLY mode" do
it_behaves_like :file_new_rdonly, @method, File::RDONLY
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment