Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed version guards for enumerable specs.

  • Loading branch information...
commit 907a70ace38b027624e1dd40d26b6535dde84184 1 parent 95110ee
@brixen brixen authored
View
60 core/enumerable/count_spec.rb
@@ -1,43 +1,45 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#count" do
- before :each do
- @elements = [1, 2, 4, 2]
- @numerous = EnumerableSpecs::Numerous.new(*@elements)
- end
+ruby_version_is "1.8.7" do
+ describe "Enumerable#count" do
+ before :each do
+ @elements = [1, 2, 4, 2]
+ @numerous = EnumerableSpecs::Numerous.new(*@elements)
+ end
- it "returns size when no argument or a block" do
- @numerous.count.should == 4
- end
+ it "returns size when no argument or a block" do
+ @numerous.count.should == 4
+ end
- it "counts nils if given nil as an argument" do
- EnumerableSpecs::Numerous.new(nil, nil, nil, false).count(nil).should == 3
- end
+ it "counts nils if given nil as an argument" do
+ EnumerableSpecs::Numerous.new(nil, nil, nil, false).count(nil).should == 3
+ end
- it "accepts an argument for comparison using ==" do
- @numerous.count(2).should == 2
- end
+ it "accepts an argument for comparison using ==" do
+ @numerous.count(2).should == 2
+ end
- it "uses a block for comparison" do
- @numerous.count{|x| x%2==0 }.should == 3
- end
+ it "uses a block for comparison" do
+ @numerous.count{|x| x%2==0 }.should == 3
+ end
- it "ignores the block when given an argument" do
- @numerous.count(4){|x| x%2==0 }.should == 1
- end
+ it "ignores the block when given an argument" do
+ @numerous.count(4){|x| x%2==0 }.should == 1
+ end
- ruby_version_is "" ... "1.9" do
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.count {|e| e == [1, 2]}.should == 1
+ ruby_version_is ""..."1.9" do
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.count {|e| e == [1, 2]}.should == 1
+ end
end
- end
- ruby_version_is "1.9" do
- it "gathers initial args as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.count {|e| e == 1 }.should == 1
+ ruby_version_is "1.9" do
+ it "gathers initial args as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.count {|e| e == 1 }.should == 1
+ end
end
end
end
View
111 core/enumerable/cycle_spec.rb
@@ -1,73 +1,74 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#cycle" do
-
- it "loops indefinitely if no argument or nil argument" do
- [[],[nil]].each do |args|
- bomb = 10
- EnumerableSpecs::Numerous.new.cycle(*args) do
- bomb -= 1
- break 42 if bomb <= 0
- end.should == 42
- bomb.should == 0
+ruby_version_is "1.8.7" do
+ describe "Enumerable#cycle" do
+ it "loops indefinitely if no argument or nil argument" do
+ [[],[nil]].each do |args|
+ bomb = 10
+ EnumerableSpecs::Numerous.new.cycle(*args) do
+ bomb -= 1
+ break 42 if bomb <= 0
+ end.should == 42
+ bomb.should == 0
+ end
end
- end
-
- it "returns if there are no elements" do
- out = EnumerableSpecs::Empty.new.cycle { break :nope }
- out.should be_nil
- end
- it "yields successive elements of the array repeatedly" do
- b = []
- EnumerableSpecs::Numerous.new(1,2,3).cycle do |elem|
- b << elem
- break if b.size == 7
+ it "returns if there are no elements" do
+ out = EnumerableSpecs::Empty.new.cycle { break :nope }
+ out.should be_nil
end
- b.should == [1,2,3,1,2,3,1]
- end
- describe "passed a number n as an argument" do
- it "returns nil and does nothing for non positive n" do
- EnumerableSpecs::ThrowingEach.new.cycle(0) {}.should be_nil
- EnumerableSpecs::NoEach.new.cycle(-22) {}.should be_nil
+ it "yields successive elements of the array repeatedly" do
+ b = []
+ EnumerableSpecs::Numerous.new(1,2,3).cycle do |elem|
+ b << elem
+ break if b.size == 7
+ end
+ b.should == [1,2,3,1,2,3,1]
end
- it "calls each at most once" do
- enum = EnumerableSpecs::EachCounter.new(1, 2)
- enum.cycle(3).to_a.should == [1,2,1,2,1,2]
- enum.times_called.should == 1
- end
+ describe "passed a number n as an argument" do
+ it "returns nil and does nothing for non positive n" do
+ EnumerableSpecs::ThrowingEach.new.cycle(0) {}.should be_nil
+ EnumerableSpecs::NoEach.new.cycle(-22) {}.should be_nil
+ end
- it "yields only when necessary" do
- enum = EnumerableSpecs::EachCounter.new(10, 20, 30)
- enum.cycle(3) { |x| break if x == 20}
- enum.times_yielded.should == 2
- end
+ it "calls each at most once" do
+ enum = EnumerableSpecs::EachCounter.new(1, 2)
+ enum.cycle(3).to_a.should == [1,2,1,2,1,2]
+ enum.times_called.should == 1
+ end
- it "tries to convert n to an Integer using #to_int" do
- enum = EnumerableSpecs::Numerous.new(3, 2, 1)
- enum.cycle(2.3).to_a.should == [3, 2, 1, 3, 2, 1]
+ it "yields only when necessary" do
+ enum = EnumerableSpecs::EachCounter.new(10, 20, 30)
+ enum.cycle(3) { |x| break if x == 20}
+ enum.times_yielded.should == 2
+ end
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(2)
- enum.cycle(obj).to_a.should == [3, 2, 1, 3, 2, 1]
- end
+ it "tries to convert n to an Integer using #to_int" do
+ enum = EnumerableSpecs::Numerous.new(3, 2, 1)
+ enum.cycle(2.3).to_a.should == [3, 2, 1, 3, 2, 1]
- it "raises a TypeError when the passed n can be coerced to Integer" do
- enum = EnumerableSpecs::Numerous.new
- lambda{ enum.cycle("cat"){} }.should raise_error(TypeError)
- end
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(2)
+ enum.cycle(obj).to_a.should == [3, 2, 1, 3, 2, 1]
+ end
- it "raises an ArgumentError if more arguments are passed" do
- enum = EnumerableSpecs::Numerous.new
- lambda{ enum.cycle(1, 2) {} }.should raise_error(ArgumentError)
- end
+ it "raises a TypeError when the passed n can be coerced to Integer" do
+ enum = EnumerableSpecs::Numerous.new
+ lambda{ enum.cycle("cat"){} }.should raise_error(TypeError)
+ end
+
+ it "raises an ArgumentError if more arguments are passed" do
+ enum = EnumerableSpecs::Numerous.new
+ lambda{ enum.cycle(1, 2) {} }.should raise_error(ArgumentError)
+ end
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.cycle(2).to_a.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9], [1, 2], [3, 4, 5], [6, 7, 8, 9]]
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.cycle(2).to_a.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9], [1, 2], [3, 4, 5], [6, 7, 8, 9]]
+ end
end
end
end
View
87 core/enumerable/drop_while_spec.rb
@@ -1,48 +1,49 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#drop_while" do
- before :each do
- @enum = EnumerableSpecs::Numerous.new(3, 2, 1, :go)
+ruby_version_is "1.8.7" do
+ describe "Enumerable#drop_while" do
+ before :each do
+ @enum = EnumerableSpecs::Numerous.new(3, 2, 1, :go)
+ end
+
+ it 'returns an Enumerator if no block given' do
+ @enum.drop_while.should be_an_instance_of(enumerator_class)
+ end
+
+ it "returns no/all elements for {true/false} block" do
+ @enum.drop_while{true}.should == []
+ @enum.drop_while{false}.should == @enum.to_a
+ end
+
+ it "accepts returns other than true/false" do
+ @enum.drop_while{1}.should == []
+ @enum.drop_while{nil}.should == @enum.to_a
+ end
+
+ it "passes elements to the block until the first false" do
+ a = []
+ @enum.drop_while{|obj| (a << obj).size < 3}.should == [1, :go]
+ a.should == [3, 2, 1]
+ end
+
+ it "will only go through what's needed" do
+ enum = EnumerableSpecs::EachCounter.new(1,2,3,4)
+ enum.drop_while { |x|
+ break 42 if x == 3
+ true
+ }.should == 42
+ enum.times_yielded.should == 3
+ end
+
+ it "doesn't return self when it could" do
+ a = [1,2,3]
+ a.drop_while{false}.should_not equal(a)
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.drop_while {|e| e != [6, 7, 8, 9] }.should == [[6, 7, 8, 9]]
+ end
end
-
- it 'returns an Enumerator if no block given' do
- @enum.drop_while.should be_an_instance_of(enumerator_class)
- end
-
- it "returns no/all elements for {true/false} block" do
- @enum.drop_while{true}.should == []
- @enum.drop_while{false}.should == @enum.to_a
- end
-
- it "accepts returns other than true/false" do
- @enum.drop_while{1}.should == []
- @enum.drop_while{nil}.should == @enum.to_a
- end
-
- it "passes elements to the block until the first false" do
- a = []
- @enum.drop_while{|obj| (a << obj).size < 3}.should == [1, :go]
- a.should == [3, 2, 1]
- end
-
- it "will only go through what's needed" do
- enum = EnumerableSpecs::EachCounter.new(1,2,3,4)
- enum.drop_while { |x|
- break 42 if x == 3
- true
- }.should == 42
- enum.times_yielded.should == 3
- end
-
- it "doesn't return self when it could" do
- a = [1,2,3]
- a.drop_while{false}.should_not equal(a)
- end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.drop_while {|e| e != [6, 7, 8, 9] }.should == [[6, 7, 8, 9]]
- end
-
end
View
21 core/enumerable/each_cons_spec.rb
@@ -47,15 +47,16 @@
cnt.times_yielded.should == 3
end
- it "returns an enumerator if no block" do
- e = @enum.each_cons(3)
- e.should be_an_instance_of(enumerator_class)
- e.to_a.should == @in_threes
+ ruby_version_is "1.8.7" do
+ it "returns an enumerator if no block" do
+ e = @enum.each_cons(3)
+ e.should be_an_instance_of(enumerator_class)
+ e.to_a.should == @in_threes
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.each_cons(2).to_a.should == [[[1, 2], [3, 4, 5]], [[3, 4, 5], [6, 7, 8, 9]]]
+ end
end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.each_cons(2).to_a.should == [[[1, 2], [3, 4, 5]], [[3, 4, 5], [6, 7, 8, 9]]]
- end
-
end
View
20 core/enumerable/each_slice_spec.rb
@@ -47,14 +47,16 @@
cnt.times_yielded.should == 4
end
- it "returns an enumerator if no block" do
- e = @enum.each_slice(3)
- e.should be_an_instance_of(enumerator_class)
- e.to_a.should == @sliced
- end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.each_slice(2).to_a.should == [[[1, 2], [3, 4, 5]], [[6, 7, 8, 9]]]
+ ruby_version_is "1.8.7" do
+ it "returns an enumerator if no block" do
+ e = @enum.each_slice(3)
+ e.should be_an_instance_of(enumerator_class)
+ e.to_a.should == @sliced
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.each_slice(2).to_a.should == [[[1, 2], [3, 4, 5]], [[6, 7, 8, 9]]]
+ end
end
end
View
89 core/enumerable/find_index_spec.rb
@@ -1,63 +1,64 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#find_index" do
- before :each do
- @elements = [2, 4, 6, 8, 10]
- @numerous = EnumerableSpecs::Numerous.new(*@elements)
- end
+ruby_version_is "1.8.7" do
+ describe "Enumerable#find_index" do
+ before :each do
+ @elements = [2, 4, 6, 8, 10]
+ @numerous = EnumerableSpecs::Numerous.new(*@elements)
+ end
- it "passes each entry in enum to block while block when block is false" do
- visited_elements = []
- @numerous.find_index do |element|
- visited_elements << element
- false
+ it "passes each entry in enum to block while block when block is false" do
+ visited_elements = []
+ @numerous.find_index do |element|
+ visited_elements << element
+ false
+ end
+ visited_elements.should == @elements
end
- visited_elements.should == @elements
- end
- it "returns nil when the block is false" do
- @numerous.find_index {|e| false }.should == nil
- end
+ it "returns nil when the block is false" do
+ @numerous.find_index {|e| false }.should == nil
+ end
- it "returns the first index for which the block is not false" do
- @elements.each_with_index do |element, index|
- @numerous.find_index {|e| e > element - 1 }.should == index
+ it "returns the first index for which the block is not false" do
+ @elements.each_with_index do |element, index|
+ @numerous.find_index {|e| e > element - 1 }.should == index
+ end
end
- end
- it "returns the first index found" do
- repeated = [10, 11, 11, 13, 11, 13, 10, 10, 13, 11]
- numerous_repeat = EnumerableSpecs::Numerous.new(*repeated)
- repeated.each do |element|
- numerous_repeat.find_index(element).should == element - 10
+ it "returns the first index found" do
+ repeated = [10, 11, 11, 13, 11, 13, 10, 10, 13, 11]
+ numerous_repeat = EnumerableSpecs::Numerous.new(*repeated)
+ repeated.each do |element|
+ numerous_repeat.find_index(element).should == element - 10
+ end
end
- end
- it "returns nil when the element not found" do
- @numerous.find_index(-1).should == nil
- end
+ it "returns nil when the element not found" do
+ @numerous.find_index(-1).should == nil
+ end
- it "ignores the block if an argument is given" do
- @numerous.find_index(-1) {|e| true }.should == nil
- end
+ it "ignores the block if an argument is given" do
+ @numerous.find_index(-1) {|e| true }.should == nil
+ end
- it 'returns an Enumerator if no block given' do
- @numerous.find_index.should be_an_instance_of(enumerator_class)
- end
+ it 'returns an Enumerator if no block given' do
+ @numerous.find_index.should be_an_instance_of(enumerator_class)
+ end
- ruby_version_is "" ... "1.9" do
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.find_index {|e| e == [1, 2] }.should == 0
+ ruby_version_is ""..."1.9" do
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.find_index {|e| e == [1, 2] }.should == 0
+ end
end
- end
- ruby_version_is "1.9" do
- it "gathers initial args as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.find_index {|e| e == 1 }.should == 0
+ ruby_version_is "1.9" do
+ it "gathers initial args as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.find_index {|e| e == 1 }.should == 0
+ end
end
end
-
end
View
22 core/enumerable/first_spec.rb
@@ -2,17 +2,19 @@
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/take', __FILE__)
-describe "Enumerable#first" do
- it "returns the first element" do
- EnumerableSpecs::Numerous.new.first.should == 2
- EnumerableSpecs::Empty.new.first.should == nil
- end
+ruby_version_is "1.8.7" do
+ describe "Enumerable#first" do
+ it "returns the first element" do
+ EnumerableSpecs::Numerous.new.first.should == 2
+ EnumerableSpecs::Empty.new.first.should == nil
+ end
- it "returns nil if self is empty" do
- EnumerableSpecs::Empty.new.first.should == nil
- end
+ it "returns nil if self is empty" do
+ EnumerableSpecs::Empty.new.first.should == nil
+ end
- describe "when passed an argument" do
- it_behaves_like :enumerable_take, :first
+ describe "when passed an argument" do
+ it_behaves_like :enumerable_take, :first
+ end
end
end
View
31 core/enumerable/group_by_spec.rb
@@ -1,23 +1,24 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#group_by" do
- it "returns a hash with values grouped according to the block" do
- EnumerableSpecs::Numerous.new(*%w(foo bar baz)).group_by{ |word| word[0..0].to_sym }.
- should == { :f => ["foo"], :b => ["bar", "baz"]}
- end
+ruby_version_is "1.8.7" do
+ describe "Enumerable#group_by" do
+ it "returns a hash with values grouped according to the block" do
+ EnumerableSpecs::Numerous.new(*%w(foo bar baz)).group_by{ |word| word[0..0].to_sym }.
+ should == { :f => ["foo"], :b => ["bar", "baz"]}
+ end
- it "returns an empty hash for empty enumerables" do
- EnumerableSpecs::Empty.new.group_by { |x| x}.should == {}
- end
+ it "returns an empty hash for empty enumerables" do
+ EnumerableSpecs::Empty.new.group_by { |x| x}.should == {}
+ end
- it "returns an Enumerator if called without a block" do
- EnumerableSpecs::Numerous.new.group_by.should be_an_instance_of(enumerator_class)
- end
+ it "returns an Enumerator if called without a block" do
+ EnumerableSpecs::Numerous.new.group_by.should be_an_instance_of(enumerator_class)
+ end
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.group_by {|e| e}.should == {[1, 2]=>[[1, 2]], [6, 7, 8, 9]=>[[6, 7, 8, 9]], [3, 4, 5]=>[[3, 4, 5]]}
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.group_by {|e| e}.should == {[1, 2]=>[[1, 2]], [6, 7, 8, 9]=>[[6, 7, 8, 9]], [3, 4, 5]=>[[3, 4, 5]]}
+ end
end
-
end
View
74 core/enumerable/max_by_spec.rb
@@ -1,42 +1,42 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#max_by" do
-
- it "returns an enumerator if no block" do
- EnumerableSpecs::Numerous.new(42).max_by.should be_an_instance_of(enumerator_class)
- end
-
- it "returns nil if #each yields no objects" do
- EnumerableSpecs::Empty.new.max_by {|o| o.nonesuch }.should == nil
- end
-
- it "returns the object for whom the value returned by block is the largest" do
- EnumerableSpecs::Numerous.new(*%w[1 2 3]).max_by {|obj| obj.to_i }.should == '3'
- EnumerableSpecs::Numerous.new(*%w[three five]).max_by {|obj| obj.length }.should == 'three'
- end
-
- it "returns the object that appears first in #each in case of a tie" do
- a, b, c = '1', '2', '2'
- EnumerableSpecs::Numerous.new(a, b, c).max_by {|obj| obj.to_i }.should equal(b)
+ruby_version_is "1.8.7" do
+ describe "Enumerable#max_by" do
+ it "returns an enumerator if no block" do
+ EnumerableSpecs::Numerous.new(42).max_by.should be_an_instance_of(enumerator_class)
+ end
+
+ it "returns nil if #each yields no objects" do
+ EnumerableSpecs::Empty.new.max_by {|o| o.nonesuch }.should == nil
+ end
+
+ it "returns the object for whom the value returned by block is the largest" do
+ EnumerableSpecs::Numerous.new(*%w[1 2 3]).max_by {|obj| obj.to_i }.should == '3'
+ EnumerableSpecs::Numerous.new(*%w[three five]).max_by {|obj| obj.length }.should == 'three'
+ end
+
+ it "returns the object that appears first in #each in case of a tie" do
+ a, b, c = '1', '2', '2'
+ EnumerableSpecs::Numerous.new(a, b, c).max_by {|obj| obj.to_i }.should equal(b)
+ end
+
+ it "uses max.<=>(current) to determine order" do
+ a, b, c = (1..3).map{|n| EnumerableSpecs::ReverseComparable.new(n)}
+
+ # Just using self here to avoid additional complexity
+ EnumerableSpecs::Numerous.new(a, b, c).max_by {|obj| obj }.should == a
+ end
+
+ it "is able to return the maximum for enums that contain nils" do
+ enum = EnumerableSpecs::Numerous.new(nil, nil, true)
+ enum.max_by {|o| o.nil? ? 0 : 1 }.should == true
+ enum.max_by {|o| o.nil? ? 1 : 0 }.should == nil
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.max_by {|e| e.size}.should == [6, 7, 8, 9]
+ end
end
-
- it "uses max.<=>(current) to determine order" do
- a, b, c = (1..3).map{|n| EnumerableSpecs::ReverseComparable.new(n)}
-
- # Just using self here to avoid additional complexity
- EnumerableSpecs::Numerous.new(a, b, c).max_by {|obj| obj }.should == a
- end
-
- it "is able to return the maximum for enums that contain nils" do
- enum = EnumerableSpecs::Numerous.new(nil, nil, true)
- enum.max_by {|o| o.nil? ? 0 : 1 }.should == true
- enum.max_by {|o| o.nil? ? 1 : 0 }.should == nil
- end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.max_by {|e| e.size}.should == [6, 7, 8, 9]
- end
-
end
View
74 core/enumerable/min_by_spec.rb
@@ -1,41 +1,43 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#min_by" do
- it "returns an enumerator if no block" do
- EnumerableSpecs::Numerous.new(42).min_by.should be_an_instance_of(enumerator_class)
- end
-
- it "returns nil if #each yields no objects" do
- EnumerableSpecs::Empty.new.min_by {|o| o.nonesuch }.should == nil
- end
-
-
- it "returns the object for whom the value returned by block is the largest" do
- EnumerableSpecs::Numerous.new(*%w[3 2 1]).min_by {|obj| obj.to_i }.should == '1'
- EnumerableSpecs::Numerous.new(*%w[five three]).min_by {|obj| obj.length }.should == 'five'
- end
-
- it "returns the object that appears first in #each in case of a tie" do
- a, b, c = '2', '1', '1'
- EnumerableSpecs::Numerous.new(a, b, c).min_by {|obj| obj.to_i }.should equal(b)
- end
-
- it "uses min.<=>(current) to determine order" do
- a, b, c = (1..3).map{|n| EnumerableSpecs::ReverseComparable.new(n)}
-
- # Just using self here to avoid additional complexity
- EnumerableSpecs::Numerous.new(a, b, c).min_by {|obj| obj }.should == c
- end
-
- it "is able to return the maximum for enums that contain nils" do
- enum = EnumerableSpecs::Numerous.new(nil, nil, true)
- enum.min_by {|o| o.nil? ? 0 : 1 }.should == nil
- enum.min_by {|o| o.nil? ? 1 : 0 }.should == true
- end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.min_by {|e| e.size}.should == [1, 2]
+ruby_version_is "1.8.7" do
+ describe "Enumerable#min_by" do
+ it "returns an enumerator if no block" do
+ EnumerableSpecs::Numerous.new(42).min_by.should be_an_instance_of(enumerator_class)
+ end
+
+ it "returns nil if #each yields no objects" do
+ EnumerableSpecs::Empty.new.min_by {|o| o.nonesuch }.should == nil
+ end
+
+
+ it "returns the object for whom the value returned by block is the largest" do
+ EnumerableSpecs::Numerous.new(*%w[3 2 1]).min_by {|obj| obj.to_i }.should == '1'
+ EnumerableSpecs::Numerous.new(*%w[five three]).min_by {|obj| obj.length }.should == 'five'
+ end
+
+ it "returns the object that appears first in #each in case of a tie" do
+ a, b, c = '2', '1', '1'
+ EnumerableSpecs::Numerous.new(a, b, c).min_by {|obj| obj.to_i }.should equal(b)
+ end
+
+ it "uses min.<=>(current) to determine order" do
+ a, b, c = (1..3).map{|n| EnumerableSpecs::ReverseComparable.new(n)}
+
+ # Just using self here to avoid additional complexity
+ EnumerableSpecs::Numerous.new(a, b, c).min_by {|obj| obj }.should == c
+ end
+
+ it "is able to return the maximum for enums that contain nils" do
+ enum = EnumerableSpecs::Numerous.new(nil, nil, true)
+ enum.min_by {|o| o.nil? ? 0 : 1 }.should == nil
+ enum.min_by {|o| o.nil? ? 1 : 0 }.should == true
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.min_by {|e| e.size}.should == [1, 2]
+ end
end
end
View
75 core/enumerable/minmax_by_spec.rb
@@ -1,42 +1,43 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#minmax_by" do
- it "returns an enumerator if no block" do
- EnumerableSpecs::Numerous.new(42).minmax_by.should be_an_instance_of(enumerator_class)
+ruby_version_is "1.8.7" do
+ describe "Enumerable#minmax_by" do
+ it "returns an enumerator if no block" do
+ EnumerableSpecs::Numerous.new(42).minmax_by.should be_an_instance_of(enumerator_class)
+ end
+
+ it "returns nil if #each yields no objects" do
+ EnumerableSpecs::Empty.new.minmax_by {|o| o.nonesuch }.should == [nil, nil]
+ end
+
+ it "returns the object for whom the value returned by block is the largest" do
+ EnumerableSpecs::Numerous.new(*%w[1 2 3]).minmax_by {|obj| obj.to_i }.should == ['1', '3']
+ EnumerableSpecs::Numerous.new(*%w[three five]).minmax_by {|obj| obj.length }.should == ['five', 'three']
+ end
+
+ it "returns the object that appears first in #each in case of a tie" do
+ a, b, c, d = '1', '1', '2', '2'
+ mm = EnumerableSpecs::Numerous.new(a, b, c, d).minmax_by {|obj| obj.to_i }
+ mm[0].should equal(a)
+ mm[1].should equal(c)
+ end
+
+ it "uses min/max.<=>(current) to determine order" do
+ a, b, c = (1..3).map{|n| EnumerableSpecs::ReverseComparable.new(n)}
+
+ # Just using self here to avoid additional complexity
+ EnumerableSpecs::Numerous.new(a, b, c).minmax_by {|obj| obj }.should == [c, a]
+ end
+
+ it "is able to return the maximum for enums that contain nils" do
+ enum = EnumerableSpecs::Numerous.new(nil, nil, true)
+ enum.minmax_by {|o| o.nil? ? 0 : 1 }.should == [nil, true]
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.minmax_by {|e| e.size}.should == [[1, 2], [6, 7, 8, 9]]
+ end
end
-
- it "returns nil if #each yields no objects" do
- EnumerableSpecs::Empty.new.minmax_by {|o| o.nonesuch }.should == [nil, nil]
- end
-
- it "returns the object for whom the value returned by block is the largest" do
- EnumerableSpecs::Numerous.new(*%w[1 2 3]).minmax_by {|obj| obj.to_i }.should == ['1', '3']
- EnumerableSpecs::Numerous.new(*%w[three five]).minmax_by {|obj| obj.length }.should == ['five', 'three']
- end
-
- it "returns the object that appears first in #each in case of a tie" do
- a, b, c, d = '1', '1', '2', '2'
- mm = EnumerableSpecs::Numerous.new(a, b, c, d).minmax_by {|obj| obj.to_i }
- mm[0].should equal(a)
- mm[1].should equal(c)
- end
-
- it "uses min/max.<=>(current) to determine order" do
- a, b, c = (1..3).map{|n| EnumerableSpecs::ReverseComparable.new(n)}
-
- # Just using self here to avoid additional complexity
- EnumerableSpecs::Numerous.new(a, b, c).minmax_by {|obj| obj }.should == [c, a]
- end
-
- it "is able to return the maximum for enums that contain nils" do
- enum = EnumerableSpecs::Numerous.new(nil, nil, true)
- enum.minmax_by {|o| o.nil? ? 0 : 1 }.should == [nil, true]
- end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.minmax_by {|e| e.size}.should == [[1, 2], [6, 7, 8, 9]]
- end
-
end
View
81 core/enumerable/minmax_spec.rb
@@ -1,55 +1,56 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#minmax" do
- before :each do
- @enum = EnumerableSpecs::Numerous.new(6, 4, 5, 10, 8)
+ruby_version_is "1.8.7" do
+ describe "Enumerable#minmax" do
+ before :each do
+ @enum = EnumerableSpecs::Numerous.new(6, 4, 5, 10, 8)
- @strs = EnumerableSpecs::Numerous.new("333", "2", "60", "55555", "1010", "111")
- end
-
- it "min should return the minimum element" do
- @enum.minmax.should == [4, 10]
- @strs.minmax.should == ["1010", "60" ]
- end
+ @strs = EnumerableSpecs::Numerous.new("333", "2", "60", "55555", "1010", "111")
+ end
- it "returns [nil, nil] for an empty Enumerable" do
- EnumerableSpecs::Empty.new.minmax.should == [nil, nil]
- end
+ it "min should return the minimum element" do
+ @enum.minmax.should == [4, 10]
+ @strs.minmax.should == ["1010", "60" ]
+ end
- it "raises an ArgumentError when elements are incomparable" do
- lambda do
- EnumerableSpecs::Numerous.new(11,"22").minmax
- end.should raise_error(ArgumentError)
- lambda do
- EnumerableSpecs::Numerous.new(11,12,22,33).minmax{|a, b| nil}
- end.should raise_error(ArgumentError)
- end
+ it "returns [nil, nil] for an empty Enumerable" do
+ EnumerableSpecs::Empty.new.minmax.should == [nil, nil]
+ end
- ruby_version_is ""..."1.9" do
- it "raises a NoMethodError for elements without #<=>" do
+ it "raises an ArgumentError when elements are incomparable" do
+ lambda do
+ EnumerableSpecs::Numerous.new(11,"22").minmax
+ end.should raise_error(ArgumentError)
lambda do
- EnumerableSpecs::Numerous.new(Object.new, Object.new).minmax
- end.should raise_error(NoMethodError)
+ EnumerableSpecs::Numerous.new(11,12,22,33).minmax{|a, b| nil}
+ end.should raise_error(ArgumentError)
end
- end
- ruby_version_is "1.9" do
- it "raises a NoMethodError for elements without #<=>" do
- lambda do
- EnumerableSpecs::Numerous.new(BasicObject.new, BasicObject.new).minmax
- end.should raise_error(NoMethodError)
+ ruby_version_is ""..."1.9" do
+ it "raises a NoMethodError for elements without #<=>" do
+ lambda do
+ EnumerableSpecs::Numerous.new(Object.new, Object.new).minmax
+ end.should raise_error(NoMethodError)
+ end
end
- end
- it "return the minimun when using a block rule" do
- @enum.minmax {|a,b| b <=> a }.should == [10, 4]
- @strs.minmax {|a,b| a.length <=> b.length }.should == ["2", "55555"]
- end
+ ruby_version_is "1.9" do
+ it "raises a NoMethodError for elements without #<=>" do
+ lambda do
+ EnumerableSpecs::Numerous.new(BasicObject.new, BasicObject.new).minmax
+ end.should raise_error(NoMethodError)
+ end
+ end
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.minmax.should == [[1, 2], [6, 7, 8, 9]]
- end
+ it "return the minimun when using a block rule" do
+ @enum.minmax {|a,b| b <=> a }.should == [10, 4]
+ @strs.minmax {|a,b| a.length <=> b.length }.should == ["2", "55555"]
+ end
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.minmax.should == [[1, 2], [6, 7, 8, 9]]
+ end
+ end
end
View
98 core/enumerable/none_spec.rb
@@ -1,66 +1,68 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#none?" do
- it "returns true if none of the elements in self are true" do
- e = EnumerableSpecs::Numerous.new(false, nil, false)
- e.none?.should be_true
- end
+ruby_version_is "1.8.7" do
+ describe "Enumerable#none?" do
+ it "returns true if none of the elements in self are true" do
+ e = EnumerableSpecs::Numerous.new(false, nil, false)
+ e.none?.should be_true
+ end
- it "returns false if at least one of the elements in self are true" do
- e = EnumerableSpecs::Numerous.new(false, nil, true, false)
- e.none?.should be_false
- end
+ it "returns false if at least one of the elements in self are true" do
+ e = EnumerableSpecs::Numerous.new(false, nil, true, false)
+ e.none?.should be_false
+ end
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMultiWithFalse.new
- multi.none?.should be_false
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMultiWithFalse.new
+ multi.none?.should be_false
+ end
end
-end
-describe "Enumerable#none? with a block" do
- before(:each) do
- @e = EnumerableSpecs::Numerous.new(1,1,2,3,4)
- end
+ describe "Enumerable#none? with a block" do
+ before(:each) do
+ @e = EnumerableSpecs::Numerous.new(1,1,2,3,4)
+ end
- it "passes each element to the block in turn until it returns true" do
- acc = []
- @e.none? {|e| acc << e; false }
- acc.should == [1,1,2,3,4]
- end
+ it "passes each element to the block in turn until it returns true" do
+ acc = []
+ @e.none? {|e| acc << e; false }
+ acc.should == [1,1,2,3,4]
+ end
- it "stops passing elements to the block when it returns true" do
- acc = []
- @e.none? {|e| acc << e; e == 3 ? true : false }
- acc.should == [1,1,2,3]
- end
+ it "stops passing elements to the block when it returns true" do
+ acc = []
+ @e.none? {|e| acc << e; e == 3 ? true : false }
+ acc.should == [1,1,2,3]
+ end
- it "returns true if the block never returns true" do
- @e.none? {|e| false }.should be_true
- end
+ it "returns true if the block never returns true" do
+ @e.none? {|e| false }.should be_true
+ end
- it "returns false if the block ever returns true" do
- @e.none? {|e| e == 3 ? true : false }.should be_false
- end
+ it "returns false if the block ever returns true" do
+ @e.none? {|e| e == 3 ? true : false }.should be_false
+ end
- ruby_version_is "" ... "1.9" do
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.none? {|e| e == 1 }.should be_true
+ ruby_version_is ""..."1.9" do
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.none? {|e| e == 1 }.should be_true
+ end
end
- end
- ruby_version_is "1.9" do
- it "gathers initial args as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.none? {|e| e == [1, 2] }.should be_true
+ ruby_version_is "1.9" do
+ it "gathers initial args as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.none? {|e| e == [1, 2] }.should be_true
+ end
end
- end
- it "yields multiple arguments when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- yielded = []
- multi.none? {|e, i| yielded << [e, i] }
- yielded.should == [[1, 2]]
+ it "yields multiple arguments when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ yielded = []
+ multi.none? {|e, i| yielded << [e, i] }
+ yielded.should == [[1, 2]]
+ end
end
end
View
84 core/enumerable/one_spec.rb
@@ -1,60 +1,60 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#one?" do
- describe "when passed a block" do
- it "returns true if block returns true once" do
- [:a, :b, :c].one? { |s| s == :a }.should be_true
- end
+ruby_version_is "1.8.7" do
+ describe "Enumerable#one?" do
+ describe "when passed a block" do
+ it "returns true if block returns true once" do
+ [:a, :b, :c].one? { |s| s == :a }.should be_true
+ end
- it "returns false if the block returns true more than once" do
- [:a, :b, :c].one? { |s| s == :a || s == :b }.should be_false
- end
+ it "returns false if the block returns true more than once" do
+ [:a, :b, :c].one? { |s| s == :a || s == :b }.should be_false
+ end
- it "returns false if the block only returns false" do
- [:a, :b, :c].one? { |s| s == :d }.should be_false
- end
+ it "returns false if the block only returns false" do
+ [:a, :b, :c].one? { |s| s == :d }.should be_false
+ end
- ruby_version_is "" ... "1.9" do
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.one? {|e| e == [1, 2] }.should be_true
+ ruby_version_is ""..."1.9" do
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.one? {|e| e == [1, 2] }.should be_true
+ end
end
- end
- ruby_version_is "1.9" do
- it "gathers initial args as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.one? {|e| e == 1 }.should be_true
+ ruby_version_is "1.9" do
+ it "gathers initial args as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.one? {|e| e == 1 }.should be_true
+ end
end
- end
- it "yields multiple arguments when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- yielded = []
- multi.one? {|e, i| yielded << [e, i] }
- yielded.should == [[1, 2], [3, 4]]
+ it "yields multiple arguments when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ yielded = []
+ multi.one? {|e, i| yielded << [e, i] }
+ yielded.should == [[1, 2], [3, 4]]
+ end
end
- end
-
- describe "when not passed a block" do
- it "returns true if only one element evaluates to true" do
- [false, nil, true].one?.should be_true
- end
+ describe "when not passed a block" do
+ it "returns true if only one element evaluates to true" do
+ [false, nil, true].one?.should be_true
+ end
- it "returns false if two elements evaluate to true" do
- [false, :value, nil, true].one?.should be_false
- end
+ it "returns false if two elements evaluate to true" do
+ [false, :value, nil, true].one?.should be_false
+ end
- it "returns false if all elements evaluate to false" do
- [false, nil, false].one?.should be_false
- end
+ it "returns false if all elements evaluate to false" do
+ [false, nil, false].one?.should be_false
+ end
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMultiWithSingleTrue.new
- multi.one?.should be_false
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMultiWithSingleTrue.new
+ multi.one?.should be_false
+ end
end
-
end
end
View
36 core/enumerable/reverse_each_spec.rb
@@ -1,25 +1,25 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-describe "Enumerable#reverse_each" do
+ruby_version_is "1.8.7" do
+ describe "Enumerable#reverse_each" do
+ it "traverses enum in reverse order and pass each element to block" do
+ a=[]
+ EnumerableSpecs::Numerous.new.reverse_each { |i| a << i }
+ a.should == [4, 1, 6, 3, 5, 2]
+ end
- it "traverses enum in reverse order and pass each element to block" do
- a=[]
- EnumerableSpecs::Numerous.new.reverse_each { |i| a << i }
- a.should == [4, 1, 6, 3, 5, 2]
- end
-
- it 'returns an Enumerator if no block given' do
- enum = EnumerableSpecs::Numerous.new.reverse_each
- enum.should be_an_instance_of(enumerator_class)
- enum.to_a.should == [4, 1, 6, 3, 5, 2]
- end
+ it 'returns an Enumerator if no block given' do
+ enum = EnumerableSpecs::Numerous.new.reverse_each
+ enum.should be_an_instance_of(enumerator_class)
+ enum.to_a.should == [4, 1, 6, 3, 5, 2]
+ end
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- yielded = []
- multi.reverse_each {|e| yielded << e }
- yielded.should == [[6, 7, 8, 9], [3, 4, 5], [1, 2]]
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ yielded = []
+ multi.reverse_each {|e| yielded << e }
+ yielded.should == [[6, 7, 8, 9], [3, 4, 5], [1, 2]]
+ end
end
-
end
View
22 core/enumerable/shared/collect.rb
@@ -10,16 +10,22 @@
numerous.send(@method) { |i| i }.should == entries
end
- it "passes through the values yielded by #each_with_index" do
- [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil }
- ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
+ ruby_version_is "1.8.7" do
+ it "passes through the values yielded by #each_with_index" do
+ [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil }
+ ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
+ end
end
- ruby_version_is "" ... "1.9" do
+ ruby_version_is ""..."1.9" do
it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
multi.send(@method) {|e| e}.should == [[1,2],[3,4,5],[6,7,8,9]]
end
+
+ it "returns to_a when no block given" do
+ EnumerableSpecs::Numerous.new.send(@method).should == [2, 5, 3, 6, 1, 4]
+ end
end
ruby_version_is "1.9" do
@@ -27,15 +33,7 @@
multi = EnumerableSpecs::YieldsMulti.new
multi.send(@method) {|e| e}.should == [1,3,6]
end
- end
-
- ruby_version_is "" ... "1.9" do
- it "returns to_a when no block given" do
- EnumerableSpecs::Numerous.new.send(@method).should == [2, 5, 3, 6, 1, 4]
- end
- end
- ruby_version_is "1.9" do
it "returns an enumerator when no block given" do
enum = EnumerableSpecs::Numerous.new.send(@method)
enum.should be_an_instance_of(enumerator_class)
View
8 core/enumerable/shared/entries.rb
@@ -4,11 +4,11 @@
numerous.send(@method).should == [1, nil, "a", 2, false, true]
end
- it "passes through the values yielded by #each_with_index" do
- [:a, :b].each_with_index.send(@method).should == [[:a, 0], [:b, 1]]
- end
+ ruby_version_is "1.8.7" do
+ it "passes through the values yielded by #each_with_index" do
+ [:a, :b].each_with_index.send(@method).should == [[:a, 0], [:b, 1]]
+ end
- ruby_version_is '1.8.7' do
it "passes arguments to each" do
count = EnumerableSpecs::EachCounter.new(1, 2, 3)
count.to_a(:hello, "world").should == [1, 2, 3]
View
28 core/enumerable/shared/find.rb
@@ -47,25 +47,27 @@
@empty.send(@method, fail_proc) {|e| true}.should == "yay"
end
- it "passes through the values yielded by #each_with_index" do
- [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil }
- ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
- end
-
- ruby_version_is "" ... "1.8.7" do
+ ruby_version_is ""..."1.8.7" do
it "raises a LocalJumpError if no block given" do
lambda { @numerous.send(@method) }.should raise_error(LocalJumpError)
end
end
- it "returns an enumerator when no block given" do
- @numerous.send(@method).should be_an_instance_of(enumerator_class)
- end
+ ruby_version_is "1.8.7" do
+ it "passes through the values yielded by #each_with_index" do
+ [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil }
+ ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
+ end
- it "passes the ifnone proc to the enumerator" do
- times = 0
- fail_proc = lambda { times += 1; raise if times > 1; "cheeseburgers" }
- @numerous.send(@method, fail_proc).each {|e| false }.should == "cheeseburgers"
+ it "returns an enumerator when no block given" do
+ @numerous.send(@method).should be_an_instance_of(enumerator_class)
+ end
+
+ it "passes the ifnone proc to the enumerator" do
+ times = 0
+ fail_proc = lambda { times += 1; raise if times > 1; "cheeseburgers" }
+ @numerous.send(@method, fail_proc).each {|e| false }.should == "cheeseburgers"
+ end
end
it "gathers whole arrays as elements when each yields multiple" do
View
18 core/enumerable/shared/find_all.rb
@@ -11,19 +11,21 @@
@numerous.send(@method) {|i| false }.should == []
end
- it "passes through the values yielded by #each_with_index" do
- [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i] }
- ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
- end
-
- ruby_version_is "" ... "1.8.7" do
+ ruby_version_is ""..."1.8.7" do
it "raises a LocalJumpError if no block given" do
lambda { @numerous.send(@method) }.should raise_error(LocalJumpError)
end
end
- it "returns an enumerator when no block given" do
- @numerous.send(@method).should be_an_instance_of(enumerator_class)
+ ruby_version_is "1.8.7" do
+ it "returns an enumerator when no block given" do
+ @numerous.send(@method).should be_an_instance_of(enumerator_class)
+ end
+
+ it "passes through the values yielded by #each_with_index" do
+ [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i] }
+ ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
+ end
end
it "gathers whole arrays as elements when each yields multiple" do
View
10 core/enumerable/sort_by_spec.rb
@@ -15,10 +15,12 @@
ar.should == [b, a]
end
- it "returns an Enumerator when a block is not supplied" do
- a = EnumerableSpecs::Numerous.new("a","b")
- a.sort_by.should be_an_instance_of(enumerator_class)
- a.to_a.should == ["a", "b"]
+ ruby_version_is "1.8.7" do
+ it "returns an Enumerator when a block is not supplied" do
+ a = EnumerableSpecs::Numerous.new("a","b")
+ a.sort_by.should be_an_instance_of(enumerator_class)
+ a.to_a.should == ["a", "b"]
+ end
end
it "gathers whole arrays as elements when each yields multiple" do
View
4 core/enumerable/take_spec.rb
@@ -2,8 +2,8 @@
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/take', __FILE__)
-describe "Enumerable#take" do
- ruby_version_is '1.8.7' do
+ruby_version_is "1.8.7" do
+ describe "Enumerable#take" do
it "requires an argument" do
lambda{ EnumerableSpecs::Numerous.new.take}.should raise_error(ArgumentError)
end
Please sign in to comment.
Something went wrong with that request. Please try again.