Skip to content

Commit a498a67

Browse files
committed
Consistent specs for Kernel module functions
Currently, some specs are run for both instance and singleton method This moves specs to run just on instance methods, and simply checks if the singleton method exists
1 parent e695ce6 commit a498a67

64 files changed

Lines changed: 606 additions & 646 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/kernel/Array_spec.rb

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,93 @@
11
require_relative '../../spec_helper'
22
require_relative 'fixtures/classes'
33

4-
describe "Kernel" do
5-
it "has private instance method Array()" do
6-
Kernel.private_instance_methods(false).should.include?(:Array)
7-
end
8-
end
9-
10-
describe :kernel_Array, shared: true do
4+
describe "Kernel#Array" do
115
before :each do
126
@array = [1, 2, 3]
137
end
148

9+
it "is a private method" do
10+
Kernel.private_instance_methods(false).should.include?(:Array)
11+
end
12+
1513
it "does not call #to_ary on an Array" do
1614
@array.should_not_receive(:to_ary)
17-
@object.send(@method, @array).should == @array
15+
Array(@array).should == @array
1816
end
1917

2018
it "calls #to_ary to convert the argument to an Array" do
2119
obj = mock("Array([1,2,3])")
2220
obj.should_receive(:to_ary).and_return(@array)
2321
obj.should_not_receive(:to_a)
2422

25-
@object.send(@method, obj).should == @array
23+
Array(obj).should == @array
2624
end
2725

2826
it "does not call #to_a on an Array" do
2927
@array.should_not_receive(:to_a)
30-
@object.send(@method, @array).should == @array
28+
Array(@array).should == @array
3129
end
3230

3331
it "calls #to_a if the argument does not respond to #to_ary" do
3432
obj = mock("Array([1,2,3])")
3533
obj.should_receive(:to_a).and_return(@array)
3634

37-
@object.send(@method, obj).should == @array
35+
Array(obj).should == @array
3836
end
3937

4038
it "calls #to_a if #to_ary returns nil" do
4139
obj = mock("Array([1,2,3])")
4240
obj.should_receive(:to_ary).and_return(nil)
4341
obj.should_receive(:to_a).and_return(@array)
4442

45-
@object.send(@method, obj).should == @array
43+
Array(obj).should == @array
4644
end
4745

4846
it "returns an Array containing the argument if #to_a returns nil" do
4947
obj = mock("Array([1,2,3])")
5048
obj.should_receive(:to_a).and_return(nil)
5149

52-
@object.send(@method, obj).should == [obj]
50+
Array(obj).should == [obj]
5351
end
5452

5553
it "calls #to_ary first, even if it's private" do
5654
obj = KernelSpecs::PrivateToAry.new
5755

58-
@object.send(@method, obj).should == [1, 2]
56+
Array(obj).should == [1, 2]
5957
end
6058

6159
it "calls #to_a if #to_ary is not defined, even if it's private" do
6260
obj = KernelSpecs::PrivateToA.new
6361

64-
@object.send(@method, obj).should == [3, 4]
62+
Array(obj).should == [3, 4]
6563
end
6664

6765
it "returns an Array containing the argument if it responds to neither #to_ary nor #to_a" do
6866
obj = mock("Array(x)")
69-
@object.send(@method, obj).should == [obj]
67+
Array(obj).should == [obj]
7068
end
7169

7270
it "returns an empty Array when passed nil" do
73-
@object.send(@method, nil).should == []
71+
Array(nil).should == []
7472
end
7573

7674
it "raises a TypeError if #to_ary does not return an Array" do
7775
obj = mock("Array() string")
7876
obj.should_receive(:to_ary).and_return("string")
7977

80-
-> { @object.send(@method, obj) }.should.raise(TypeError)
78+
-> { Array(obj) }.should.raise(TypeError)
8179
end
8280

8381
it "raises a TypeError if #to_a does not return an Array" do
8482
obj = mock("Array() string")
8583
obj.should_receive(:to_a).and_return("string")
8684

87-
-> { @object.send(@method, obj) }.should.raise(TypeError)
85+
-> { Array(obj) }.should.raise(TypeError)
8886
end
8987
end
9088

9189
describe "Kernel.Array" do
92-
it_behaves_like :kernel_Array, :Array_method, KernelSpecs
93-
end
94-
95-
describe "Kernel#Array" do
96-
it_behaves_like :kernel_Array, :Array_function, KernelSpecs
90+
it "is a public method" do
91+
Kernel.public_methods(false).should.include?(:Array)
92+
end
9793
end

core/kernel/Complex_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
require_relative '../../shared/kernel/complex'
33
require_relative 'fixtures/Complex'
44

5-
describe "Kernel.Complex()" do
5+
describe "Kernel#Complex" do
6+
it "is a private method" do
7+
Kernel.private_instance_methods(false).should.include?(:Complex)
8+
end
9+
610
describe "when passed [Complex, Complex]" do
711
it "returns a new Complex number based on the two given numbers" do
812
Complex(Complex(3, 4), Complex(5, 6)).should == Complex(3 - 6, 4 + 5)
@@ -274,3 +278,9 @@
274278
Complex(1).frozen?.should == true
275279
end
276280
end
281+
282+
describe "Kernel.Complex" do
283+
it "is a public method" do
284+
Kernel.public_methods(false).should.include?(:Complex)
285+
end
286+
end

0 commit comments

Comments
 (0)