1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Add in-tree mspec and ruby/spec

* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
  These files can therefore be updated like any other file in MRI.
  Instructions are provided in spec/README.
  [Feature #13156] [ruby-core:79246]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-05-07 12:04:49 +00:00
parent ed7d803500
commit 95e8c48dd3
4645 changed files with 230678 additions and 4 deletions

View file

@ -0,0 +1,124 @@
describe :file_size, shared: true do
before :each do
@exists = tmp('i_exist')
touch(@exists) { |f| f.write 'rubinius' }
end
after :each do
rm_r @exists
end
it "returns the size of the file if it exists and is not empty" do
@object.send(@method, @exists).should == 8
end
it "accepts a String-like (to_str) parameter" do
obj = mock("file")
obj.should_receive(:to_str).and_return(@exists)
@object.send(@method, obj).should == 8
end
it "accepts an object that has a #to_path method" do
@object.send(@method, mock_to_path(@exists)).should == 8
end
end
describe :file_size_to_io, shared: true do
before :each do
@exists = tmp('i_exist')
touch(@exists) { |f| f.write 'rubinius' }
@file = File.open(@exists, 'r')
end
after :each do
@file.close unless @file.closed?
rm_r @exists
end
it "calls #to_io to convert the argument to an IO" do
obj = mock("io like")
obj.should_receive(:to_io).and_return(@file)
@object.send(@method, obj).should == 8
end
end
describe :file_size_raise_when_missing, shared: true do
before :each do
# TODO: missing_file
@missing = tmp("i_dont_exist")
rm_r @missing
end
after :each do
rm_r @missing
end
it "raises an error if file_name doesn't exist" do
lambda {@object.send(@method, @missing)}.should raise_error(Errno::ENOENT)
end
end
describe :file_size_nil_when_missing, shared: true do
before :each do
# TODO: missing_file
@missing = tmp("i_dont_exist")
rm_r @missing
end
after :each do
rm_r @missing
end
it "returns nil if file_name doesn't exist or has 0 size" do
@object.send(@method, @missing).should == nil
end
end
describe :file_size_0_when_empty, shared: true do
before :each do
@empty = tmp("i_am_empty")
touch @empty
end
after :each do
rm_r @empty
end
it "returns 0 if the file is empty" do
@object.send(@method, @empty).should == 0
end
end
describe :file_size_nil_when_empty, shared: true do
before :each do
@empty = tmp("i_am_empt")
touch @empty
end
after :each do
rm_r @empty
end
it "returns nil if file_name is empty" do
@object.send(@method, @empty).should == nil
end
end
describe :file_size_with_file_argument, shared: true do
before :each do
@exists = tmp('i_exist')
touch(@exists) { |f| f.write 'rubinius' }
end
after :each do
rm_r @exists
end
it "accepts a File argument" do
File.open(@exists) do |f|
@object.send(@method, f).should == 8
end
end
end