Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 2 additions & 49 deletions core/basicobject/equal_spec.rb
Original file line number Diff line number Diff line change
@@ -1,54 +1,7 @@
require_relative '../../spec_helper'
require_relative '../../shared/kernel/equal'

describe "BasicObject#equal?" do
it "is a public instance method" do
BasicObject.public_instance_methods(false).should.include?(:equal?)
end

it_behaves_like :object_equal, :equal?

it "is unaffected by overriding __id__" do
o1 = mock("object")
o2 = mock("object")
suppress_warning {
def o1.__id__; 10; end
def o2.__id__; 10; end
}
o1.equal?(o2).should == false
end

it "is unaffected by overriding object_id" do
o1 = mock("object")
o1.stub!(:object_id).and_return(10)
o2 = mock("object")
o2.stub!(:object_id).and_return(10)
o1.equal?(o2).should == false
end

it "is unaffected by overriding ==" do
# different objects, overriding == to return true
o1 = mock("object")
o1.stub!(:==).and_return(true)
o2 = mock("object")
o1.equal?(o2).should == false

# same objects, overriding == to return false
o3 = mock("object")
o3.stub!(:==).and_return(false)
o3.equal?(o3).should == true
end

it "is unaffected by overriding eql?" do
# different objects, overriding eql? to return true
o1 = mock("object")
o1.stub!(:eql?).and_return(true)
o2 = mock("object")
o1.equal?(o2).should == false

# same objects, overriding eql? to return false
o3 = mock("object")
o3.stub!(:eql?).and_return(false)
o3.equal?(o3).should == true
it "is an alias of BasicObject#==" do
BasicObject.instance_method(:equal?).should == BasicObject.instance_method(:==)
end
end
44 changes: 44 additions & 0 deletions core/basicobject/equal_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,48 @@
end

it_behaves_like :object_equal, :==

it "is unaffected by overriding __id__" do
o1 = mock("object")
o2 = mock("object")
suppress_warning {
def o1.__id__; 10; end
def o2.__id__; 10; end
}
(o1 == o2).should == false
end

it "is unaffected by overriding object_id" do
o1 = mock("object")
o1.stub!(:object_id).and_return(10)
o2 = mock("object")
o2.stub!(:object_id).and_return(10)
(o1 == o2).should == false
end

it "is unaffected by overriding equal?" do
# different objects, overriding equal? to return true
o1 = mock("object")
o1.stub!(:equal?).and_return(true)
o2 = mock("object")
(o1 == o2).should == false

# same objects, overriding equal? to return false
o3 = mock("object")
o3.stub!(:equal?).and_return(false)
(o3 == o3).should == true
end

it "is unaffected by overriding eql?" do
# different objects, overriding eql? to return true
o1 = mock("object")
o1.stub!(:eql?).and_return(true)
o2 = mock("object")
(o1 == o2).should == false

# same objects, overriding eql? to return false
o3 = mock("object")
o3.stub!(:eql?).and_return(false)
(o3 == o3).should == true
end
end
53 changes: 51 additions & 2 deletions core/dir/delete_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
require_relative 'shared/delete'

describe "Dir.delete" do
before :all do
Expand All @@ -11,5 +10,55 @@
DirSpecs.delete_mock_dirs
end

it_behaves_like :dir_delete, :delete
before :each do
DirSpecs.rmdir_dirs true
end

after :each do
DirSpecs.rmdir_dirs false
end

it "removes empty directories" do
Dir.delete(DirSpecs.mock_rmdir("empty")).should == 0
end

it "calls #to_path on non-String arguments" do
p = mock('path')
p.should_receive(:to_path).and_return(DirSpecs.mock_rmdir("empty"))
Dir.delete(p)
end

it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do
-> do
Dir.delete DirSpecs.mock_rmdir("nonempty")
end.should.raise(Errno::ENOTEMPTY)
end

it "raises an Errno::ENOENT when trying to remove a non-existing directory" do
-> do
Dir.delete DirSpecs.nonexistent
end.should.raise(Errno::ENOENT)
end

it "raises an Errno::ENOTDIR when trying to remove a non-directory" do
file = DirSpecs.mock_rmdir("nonempty/regular")
touch(file)
-> do
Dir.delete file
end.should.raise(Errno::ENOTDIR)
end

# this won't work on Windows, since chmod(0000) does not remove all permissions
platform_is_not :windows do
as_user do
it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do
parent = DirSpecs.mock_rmdir("noperm")
child = DirSpecs.mock_rmdir("noperm", "child")
File.chmod(0000, parent)
-> do
Dir.delete child
end.should.raise(Errno::EACCES)
end
end
end
end
12 changes: 2 additions & 10 deletions core/dir/rmdir_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
require_relative 'shared/delete'

describe "Dir.rmdir" do
before :all do
DirSpecs.create_mock_dirs
it "is an alias of Dir.delete" do
Dir.method(:rmdir).should == Dir.method(:delete)
end

after :all do
DirSpecs.delete_mock_dirs
end

it_behaves_like :dir_delete, :rmdir
end
53 changes: 0 additions & 53 deletions core/dir/shared/delete.rb

This file was deleted.

12 changes: 2 additions & 10 deletions core/dir/unlink_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
require_relative 'shared/delete'

describe "Dir.unlink" do
before :all do
DirSpecs.create_mock_dirs
it "is an alias of Dir.delete" do
Dir.method(:unlink).should == Dir.method(:delete)
end

after :all do
DirSpecs.delete_mock_dirs
end

it_behaves_like :dir_delete, :unlink
end
4 changes: 2 additions & 2 deletions core/false/inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'

describe "FalseClass#inspect" do
it "returns the string 'false'" do
false.inspect.should == "false"
it "is an alias of FalseClass#to_s" do
false.method(:inspect).should == false.method(:to_s)
end
end
8 changes: 2 additions & 6 deletions core/false/xor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
require_relative '../../spec_helper'

describe "FalseClass#^" do
it "returns false if other is nil or false, otherwise true" do
(false ^ false).should == false
(false ^ true).should == true
(false ^ nil).should == false
(false ^ "").should == true
(false ^ mock('x')).should == true
it "is an alias of FalseClass#|" do
false.method(:^).should == false.method(:|)
end
end
6 changes: 3 additions & 3 deletions core/file/zero_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'
require_relative '../../shared/file/zero'

describe "File.zero?" do
it_behaves_like :file_zero, :zero?, File
it_behaves_like :file_zero_missing, :zero?, File
it "is an alias of File.empty?" do
File.method(:zero?).should == File.method(:empty?)
end
end
7 changes: 7 additions & 0 deletions core/filetest/empty_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require_relative '../../spec_helper'
require_relative '../../shared/file/zero'

describe "FileTest.empty?" do
it_behaves_like :file_zero, :empty?, FileTest
it_behaves_like :file_zero_missing, :empty?, FileTest
end
6 changes: 3 additions & 3 deletions core/filetest/zero_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'
require_relative '../../shared/file/zero'

describe "FileTest.zero?" do
it_behaves_like :file_zero, :zero?, FileTest
it_behaves_like :file_zero_missing, :zero?, FileTest
it "is an alias of FileTest.empty?" do
FileTest.method(:zero?).should == FileTest.method(:empty?)
end
end
7 changes: 7 additions & 0 deletions core/integer/inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require_relative '../../spec_helper'

describe "Integer#inspect" do
it "is an alias of Integer#to_s" do
Integer.instance_method(:inspect).should == Integer.instance_method(:to_s)
end
end
6 changes: 6 additions & 0 deletions core/io/eof_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,9 @@
@r.should.eof?
end
end

describe "IO#eof" do
it "is an alias of IO#eof?" do
IO.instance_method(:eof).should == IO.instance_method(:eof?)
end
end
9 changes: 2 additions & 7 deletions core/io/to_i_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

describe "IO#to_i" do
it "returns the numeric file descriptor of the given IO object" do
$stdout.to_i.should == 1
end

it "raises IOError on closed stream" do
-> { IOSpecs.closed_io.to_i }.should.raise(IOError)
it "is an alias of IO#fileno" do
IO.instance_method(:to_i).should == IO.instance_method(:fileno)
end
end
7 changes: 7 additions & 0 deletions core/io/to_path_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require_relative '../../spec_helper'

describe "IO#to_path" do
it "is an alias of IO#path" do
IO.instance_method(:to_path).should == IO.instance_method(:path)
end
end
Loading
Loading