summaryrefslogtreecommitdiff
path: root/spec/ruby/core/enumerable/shared/find.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/enumerable/shared/find.rb')
-rw-r--r--spec/ruby/core/enumerable/shared/find.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/spec/ruby/core/enumerable/shared/find.rb b/spec/ruby/core/enumerable/shared/find.rb
index 4cbbf07be0..cdff640415 100644
--- a/spec/ruby/core/enumerable/shared/find.rb
+++ b/spec/ruby/core/enumerable/shared/find.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../enumerable_enumeratorized', __FILE__)
+require_relative 'enumerable_enumeratorized'
describe :enumerable_find, shared: true do
# #detect and #find are aliases, so we only need one function
@@ -29,38 +29,42 @@ describe :enumerable_find, shared: true do
end
it "returns the value of the ifnone proc if the block is false" do
- fail_proc = lambda { "cheeseburgers" }
+ fail_proc = -> { "cheeseburgers" }
@numerous.send(@method, fail_proc) {|e| false }.should == "cheeseburgers"
end
it "doesn't call the ifnone proc if an element is found" do
- fail_proc = lambda { raise "This shouldn't have been called" }
+ fail_proc = -> { raise "This shouldn't have been called" }
@numerous.send(@method, fail_proc) {|e| e == @elements.first }.should == 2
end
it "calls the ifnone proc only once when the block is false" do
times = 0
- fail_proc = lambda { times += 1; raise if times > 1; "cheeseburgers" }
+ fail_proc = -> { times += 1; raise if times > 1; "cheeseburgers" }
@numerous.send(@method, fail_proc) {|e| false }.should == "cheeseburgers"
end
it "calls the ifnone proc when there are no elements" do
- fail_proc = lambda { "yay" }
+ fail_proc = -> { "yay" }
@empty.send(@method, fail_proc) {|e| true}.should == "yay"
end
+ it "ignores the ifnone argument when nil" do
+ @numerous.send(@method, nil) {|e| false }.should == nil
+ 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
it "returns an enumerator when no block given" do
- @numerous.send(@method).should be_an_instance_of(Enumerator)
+ @numerous.send(@method).should.instance_of?(Enumerator)
end
it "passes the ifnone proc to the enumerator" do
times = 0
- fail_proc = lambda { times += 1; raise if times > 1; "cheeseburgers" }
+ fail_proc = -> { times += 1; raise if times > 1; "cheeseburgers" }
@numerous.send(@method, fail_proc).each {|e| false }.should == "cheeseburgers"
end