|
16 | 16 |
|
17 | 17 | it "can take two argument" do
|
18 | 18 | EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-).should == 4
|
| 19 | + EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, "-").should == 4 |
| 20 | + |
| 21 | + [1, 2, 3].send(@method, 10, :-).should == 4 |
| 22 | + [1, 2, 3].send(@method, 10, "-").should == 4 |
| 23 | + end |
| 24 | + |
| 25 | + it "converts non-Symbol method name argument to String with #to_str if two arguments" do |
| 26 | + name = Object.new |
| 27 | + def name.to_str; "-"; end |
| 28 | + |
| 29 | + EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, name).should == 4 |
| 30 | + [1, 2, 3].send(@method, 10, name).should == 4 |
| 31 | + end |
| 32 | + |
| 33 | + it "raises TypeError when the second argument is not Symbol or String and it cannot be converted to String if two arguments" do |
| 34 | + -> { EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, Object.new) }.should raise_error(TypeError, /is not a symbol nor a string/) |
| 35 | + -> { [1, 2, 3].send(@method, 10, Object.new) }.should raise_error(TypeError, /is not a symbol nor a string/) |
19 | 36 | end
|
20 | 37 |
|
21 | 38 | it "ignores the block if two arguments" do
|
|
39 | 56 |
|
40 | 57 | it "can take a symbol argument" do
|
41 | 58 | EnumerableSpecs::Numerous.new(10, 1, 2, 3).send(@method, :-).should == 4
|
| 59 | + [10, 1, 2, 3].send(@method, :-).should == 4 |
| 60 | + end |
| 61 | + |
| 62 | + it "can take a String argument" do |
| 63 | + EnumerableSpecs::Numerous.new(10, 1, 2, 3).send(@method, "-").should == 4 |
| 64 | + [10, 1, 2, 3].send(@method, "-").should == 4 |
| 65 | + end |
| 66 | + |
| 67 | + it "converts non-Symbol method name argument to String with #to_str" do |
| 68 | + name = Object.new |
| 69 | + def name.to_str; "-"; end |
| 70 | + |
| 71 | + EnumerableSpecs::Numerous.new(10, 1, 2, 3).send(@method, name).should == 4 |
| 72 | + [10, 1, 2, 3].send(@method, name).should == 4 |
| 73 | + end |
| 74 | + |
| 75 | + it "raises TypeError when passed not Symbol or String method name argument and it cannot be converted to String" do |
| 76 | + -> { EnumerableSpecs::Numerous.new(10, 1, 2, 3).send(@method, Object.new) }.should raise_error(TypeError, /is not a symbol nor a string/) |
| 77 | + -> { [10, 1, 2, 3].send(@method, Object.new) }.should raise_error(TypeError, /is not a symbol nor a string/) |
42 | 78 | end
|
43 | 79 |
|
44 | 80 | it "without argument takes a block with an accumulator (with first element as initial value) and the current element. Value of block becomes new accumulator" do
|
|
77 | 113 | EnumerableSpecs::EachDefiner.new('a','b','c').send(@method) {|result, i| i+result}.should == "cba"
|
78 | 114 | EnumerableSpecs::EachDefiner.new(3, 4, 5).send(@method) {|result, i| result*i}.should == 60
|
79 | 115 | EnumerableSpecs::EachDefiner.new([1], 2, 'a','b').send(@method){|r,i| r<<i}.should == [1, 2, 'a', 'b']
|
80 |
| -
|
81 | 116 | end
|
82 | 117 |
|
83 | 118 | it "returns nil when fails(legacy rubycon)" do
|
|
0 commit comments