diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-07-27 12:40:09 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-07-27 12:40:09 +0200 |
commit | 5c276e1cc91c5ab2a41fbf7827af2fed914a2bc0 (patch) | |
tree | 05b5c68c8b2a00224d4646ea3b26ce3877efaadd /spec/ruby/core/enumerable | |
parent | a06301b103371b0b7da8eaca26ba744961769f99 (diff) |
Update to ruby/spec@875a09e
Diffstat (limited to 'spec/ruby/core/enumerable')
28 files changed, 157 insertions, 113 deletions
diff --git a/spec/ruby/core/enumerable/all_spec.rb b/spec/ruby/core/enumerable/all_spec.rb index b02ac8b21b..8af80896a9 100644 --- a/spec/ruby/core/enumerable/all_spec.rb +++ b/spec/ruby/core/enumerable/all_spec.rb @@ -21,26 +21,26 @@ describe "Enumerable#all?" do end it "raises an ArgumentError when more than 1 argument is provided" do - lambda { @enum.all?(1, 2, 3) }.should raise_error(ArgumentError) - lambda { [].all?(1, 2, 3) }.should raise_error(ArgumentError) - lambda { {}.all?(1, 2, 3) }.should raise_error(ArgumentError) + -> { @enum.all?(1, 2, 3) }.should raise_error(ArgumentError) + -> { [].all?(1, 2, 3) }.should raise_error(ArgumentError) + -> { {}.all?(1, 2, 3) }.should raise_error(ArgumentError) end ruby_version_is ""..."2.5" do it "raises an ArgumentError when any arguments provided" do - lambda { @enum.all?(Proc.new {}) }.should raise_error(ArgumentError) - lambda { @enum.all?(nil) }.should raise_error(ArgumentError) - lambda { @empty.all?(1) }.should raise_error(ArgumentError) - lambda { @enum1.all?(1) {} }.should raise_error(ArgumentError) + -> { @enum.all?(Proc.new {}) }.should raise_error(ArgumentError) + -> { @enum.all?(nil) }.should raise_error(ArgumentError) + -> { @empty.all?(1) }.should raise_error(ArgumentError) + -> { @enum1.all?(1) {} }.should raise_error(ArgumentError) end end it "does not hide exceptions out of #each" do - lambda { + -> { EnumerableSpecs::ThrowingEach.new.all? }.should raise_error(RuntimeError) - lambda { + -> { EnumerableSpecs::ThrowingEach.new.all? { false } }.should raise_error(RuntimeError) end @@ -113,7 +113,7 @@ describe "Enumerable#all?" do end it "does not hide exceptions out of the block" do - lambda { + -> { @enum.all? { raise "from block" } }.should raise_error(RuntimeError) end @@ -157,7 +157,7 @@ describe "Enumerable#all?" do end it "does not hide exceptions out of #each" do - lambda { + -> { EnumerableSpecs::ThrowingEach.new.all?(Integer) }.should raise_error(RuntimeError) end @@ -185,7 +185,7 @@ describe "Enumerable#all?" do it "does not hide exceptions out of pattern#===" do pattern = EnumerableSpecs::Pattern.new { raise "from pattern" } - lambda { + -> { @enum.all?(pattern) }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerable/any_spec.rb b/spec/ruby/core/enumerable/any_spec.rb index b3f10d6806..c800fe2d4b 100644 --- a/spec/ruby/core/enumerable/any_spec.rb +++ b/spec/ruby/core/enumerable/any_spec.rb @@ -21,26 +21,26 @@ describe "Enumerable#any?" do end it "raises an ArgumentError when more than 1 argument is provided" do - lambda { @enum.any?(1, 2, 3) }.should raise_error(ArgumentError) - lambda { [].any?(1, 2, 3) }.should raise_error(ArgumentError) - lambda { {}.any?(1, 2, 3) }.should raise_error(ArgumentError) + -> { @enum.any?(1, 2, 3) }.should raise_error(ArgumentError) + -> { [].any?(1, 2, 3) }.should raise_error(ArgumentError) + -> { {}.any?(1, 2, 3) }.should raise_error(ArgumentError) end ruby_version_is ""..."2.5" do it "raises an ArgumentError when any arguments provided" do - lambda { @enum.any?(Proc.new {}) }.should raise_error(ArgumentError) - lambda { @enum.any?(nil) }.should raise_error(ArgumentError) - lambda { @empty.any?(1) }.should raise_error(ArgumentError) - lambda { @enum1.any?(1) {} }.should raise_error(ArgumentError) + -> { @enum.any?(Proc.new {}) }.should raise_error(ArgumentError) + -> { @enum.any?(nil) }.should raise_error(ArgumentError) + -> { @empty.any?(1) }.should raise_error(ArgumentError) + -> { @enum1.any?(1) {} }.should raise_error(ArgumentError) end end it "does not hide exceptions out of #each" do - lambda { + -> { EnumerableSpecs::ThrowingEach.new.any? }.should raise_error(RuntimeError) - lambda { + -> { EnumerableSpecs::ThrowingEach.new.any? { false } }.should raise_error(RuntimeError) end @@ -127,7 +127,7 @@ describe "Enumerable#any?" do end it "does not hide exceptions out of the block" do - lambda { + -> { @enum.any? { raise "from block" } }.should raise_error(RuntimeError) end @@ -171,7 +171,7 @@ describe "Enumerable#any?" do end it "does not hide exceptions out of #each" do - lambda { + -> { EnumerableSpecs::ThrowingEach.new.any?(Integer) }.should raise_error(RuntimeError) end @@ -198,7 +198,7 @@ describe "Enumerable#any?" do it "does not hide exceptions out of pattern#===" do pattern = EnumerableSpecs::Pattern.new { raise "from pattern" } - lambda { + -> { @enum.any?(pattern) }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerable/chunk_spec.rb b/spec/ruby/core/enumerable/chunk_spec.rb index 3f8a691da5..548544f4e8 100644 --- a/spec/ruby/core/enumerable/chunk_spec.rb +++ b/spec/ruby/core/enumerable/chunk_spec.rb @@ -49,12 +49,12 @@ describe "Enumerable#chunk" do it "raises a RuntimeError if the block returns a Symbol starting with an underscore other than :_alone or :_separator" do e = EnumerableSpecs::Numerous.new(1, 2, 3, 2, 1) - lambda { e.chunk { |x| :_arbitrary }.to_a }.should raise_error(RuntimeError) + -> { e.chunk { |x| :_arbitrary }.to_a }.should raise_error(RuntimeError) end it "does not accept arguments" do e = EnumerableSpecs::Numerous.new(1, 2, 3) - lambda { + -> { e.chunk(1) {} }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/enumerable/chunk_while_spec.rb b/spec/ruby/core/enumerable/chunk_while_spec.rb index 88d6d2983f..26bcc983db 100644 --- a/spec/ruby/core/enumerable/chunk_while_spec.rb +++ b/spec/ruby/core/enumerable/chunk_while_spec.rb @@ -30,7 +30,7 @@ describe "Enumerable#chunk_while" do context "when not given a block" do it "raises an ArgumentError" do - lambda { @enum.chunk_while }.should raise_error(ArgumentError) + -> { @enum.chunk_while }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/enumerable/cycle_spec.rb b/spec/ruby/core/enumerable/cycle_spec.rb index 2db1ae56fe..487086cba3 100644 --- a/spec/ruby/core/enumerable/cycle_spec.rb +++ b/spec/ruby/core/enumerable/cycle_spec.rb @@ -71,12 +71,12 @@ describe "Enumerable#cycle" do it "raises a TypeError when the passed n cannot be coerced to Integer" do enum = EnumerableSpecs::Numerous.new - lambda{ enum.cycle("cat"){} }.should raise_error(TypeError) + ->{ 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) + ->{ enum.cycle(1, 2) {} }.should raise_error(ArgumentError) end it "gathers whole arrays as elements when each yields multiple" do diff --git a/spec/ruby/core/enumerable/drop_spec.rb b/spec/ruby/core/enumerable/drop_spec.rb index 1f54d4aac7..423cc0088b 100644 --- a/spec/ruby/core/enumerable/drop_spec.rb +++ b/spec/ruby/core/enumerable/drop_spec.rb @@ -7,13 +7,13 @@ describe "Enumerable#drop" do end it "requires exactly one argument" do - lambda{ @enum.drop{} }.should raise_error(ArgumentError) - lambda{ @enum.drop(1, 2){} }.should raise_error(ArgumentError) + ->{ @enum.drop{} }.should raise_error(ArgumentError) + ->{ @enum.drop(1, 2){} }.should raise_error(ArgumentError) end describe "passed a number n as an argument" do it "raises ArgumentError if n < 0" do - lambda{ @enum.drop(-1) }.should raise_error(ArgumentError) + ->{ @enum.drop(-1) }.should raise_error(ArgumentError) end it "tries to convert n to an Integer using #to_int" do @@ -35,8 +35,8 @@ describe "Enumerable#drop" do end it "raises a TypeError when the passed n cannot be coerced to Integer" do - lambda{ @enum.drop("hat") }.should raise_error(TypeError) - lambda{ @enum.drop(nil) }.should raise_error(TypeError) + ->{ @enum.drop("hat") }.should raise_error(TypeError) + ->{ @enum.drop(nil) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/enumerable/each_cons_spec.rb b/spec/ruby/core/enumerable/each_cons_spec.rb index 40d0d53517..7d44f54f74 100644 --- a/spec/ruby/core/enumerable/each_cons_spec.rb +++ b/spec/ruby/core/enumerable/each_cons_spec.rb @@ -15,14 +15,14 @@ describe "Enumerable#each_cons" do end it "raises an ArgumentError if there is not a single parameter > 0" do - lambda{ @enum.each_cons(0){} }.should raise_error(ArgumentError) - lambda{ @enum.each_cons(-2){} }.should raise_error(ArgumentError) - lambda{ @enum.each_cons{} }.should raise_error(ArgumentError) - lambda{ @enum.each_cons(2,2){} }.should raise_error(ArgumentError) - lambda{ @enum.each_cons(0) }.should raise_error(ArgumentError) - lambda{ @enum.each_cons(-2) }.should raise_error(ArgumentError) - lambda{ @enum.each_cons }.should raise_error(ArgumentError) - lambda{ @enum.each_cons(2,2) }.should raise_error(ArgumentError) + ->{ @enum.each_cons(0){} }.should raise_error(ArgumentError) + ->{ @enum.each_cons(-2){} }.should raise_error(ArgumentError) + ->{ @enum.each_cons{} }.should raise_error(ArgumentError) + ->{ @enum.each_cons(2,2){} }.should raise_error(ArgumentError) + ->{ @enum.each_cons(0) }.should raise_error(ArgumentError) + ->{ @enum.each_cons(-2) }.should raise_error(ArgumentError) + ->{ @enum.each_cons }.should raise_error(ArgumentError) + ->{ @enum.each_cons(2,2) }.should raise_error(ArgumentError) end it "tries to convert n to an Integer using #to_int" do diff --git a/spec/ruby/core/enumerable/each_entry_spec.rb b/spec/ruby/core/enumerable/each_entry_spec.rb index 41b61f6208..edf00f3137 100644 --- a/spec/ruby/core/enumerable/each_entry_spec.rb +++ b/spec/ruby/core/enumerable/each_entry_spec.rb @@ -27,8 +27,8 @@ describe "Enumerable#each_entry" do end it "raises an ArgumentError when extra arguments" do - lambda { @enum.each_entry("one").to_a }.should raise_error(ArgumentError) - lambda { @enum.each_entry("one"){}.to_a }.should raise_error(ArgumentError) + -> { @enum.each_entry("one").to_a }.should raise_error(ArgumentError) + -> { @enum.each_entry("one"){}.to_a }.should raise_error(ArgumentError) end it "passes extra arguments to #each" do diff --git a/spec/ruby/core/enumerable/each_slice_spec.rb b/spec/ruby/core/enumerable/each_slice_spec.rb index 9ffb95d29b..ab3b79c344 100644 --- a/spec/ruby/core/enumerable/each_slice_spec.rb +++ b/spec/ruby/core/enumerable/each_slice_spec.rb @@ -15,14 +15,14 @@ describe "Enumerable#each_slice" do end it "raises an ArgumentError if there is not a single parameter > 0" do - lambda{ @enum.each_slice(0){} }.should raise_error(ArgumentError) - lambda{ @enum.each_slice(-2){} }.should raise_error(ArgumentError) - lambda{ @enum.each_slice{} }.should raise_error(ArgumentError) - lambda{ @enum.each_slice(2,2){} }.should raise_error(ArgumentError) - lambda{ @enum.each_slice(0) }.should raise_error(ArgumentError) - lambda{ @enum.each_slice(-2) }.should raise_error(ArgumentError) - lambda{ @enum.each_slice }.should raise_error(ArgumentError) - lambda{ @enum.each_slice(2,2) }.should raise_error(ArgumentError) + ->{ @enum.each_slice(0){} }.should raise_error(ArgumentError) + ->{ @enum.each_slice(-2){} }.should raise_error(ArgumentError) + ->{ @enum.each_slice{} }.should raise_error(ArgumentError) + ->{ @enum.each_slice(2,2){} }.should raise_error(ArgumentError) + ->{ @enum.each_slice(0) }.should raise_error(ArgumentError) + ->{ @enum.each_slice(-2) }.should raise_error(ArgumentError) + ->{ @enum.each_slice }.should raise_error(ArgumentError) + ->{ @enum.each_slice(2,2) }.should raise_error(ArgumentError) end it "tries to convert n to an Integer using #to_int" do diff --git a/spec/ruby/core/enumerable/first_spec.rb b/spec/ruby/core/enumerable/first_spec.rb index 19d02d7522..ed1ba599b4 100644 --- a/spec/ruby/core/enumerable/first_spec.rb +++ b/spec/ruby/core/enumerable/first_spec.rb @@ -19,7 +19,7 @@ describe "Enumerable#first" do it "raises a RangeError when passed a Bignum" do enum = EnumerableSpecs::Empty.new - lambda { enum.first(bignum_value) }.should raise_error(RangeError) + -> { enum.first(bignum_value) }.should raise_error(RangeError) end describe "when passed an argument" do diff --git a/spec/ruby/core/enumerable/grep_spec.rb b/spec/ruby/core/enumerable/grep_spec.rb index a4dd26468d..c9c0f34e27 100644 --- a/spec/ruby/core/enumerable/grep_spec.rb +++ b/spec/ruby/core/enumerable/grep_spec.rb @@ -29,6 +29,28 @@ describe "Enumerable#grep" do ary.grep(/a(b)a/) { $1 }.should == ["b", "b"] end + it "sets $~ in the block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].grep(/b/) { |e| + e.should == "abc" + $&.should == "b" + } + + # Set by the failed match of "def" + $~.should == nil + end + + it "sets $~ to the last match when given no block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].grep(/b/).should == ["abc"] + + # Set by the failed match of "def" + $~.should == nil + + ["abc", "def"].grep(/e/) + $&.should == "e" + end + describe "with a block" do before :each do @numerous = EnumerableSpecs::Numerous.new(*(0..9).to_a) diff --git a/spec/ruby/core/enumerable/grep_v_spec.rb b/spec/ruby/core/enumerable/grep_v_spec.rb index 2268005dee..6dec487065 100644 --- a/spec/ruby/core/enumerable/grep_v_spec.rb +++ b/spec/ruby/core/enumerable/grep_v_spec.rb @@ -9,6 +9,28 @@ describe "Enumerable#grep_v" do end end + it "sets $~ in the block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].grep_v(/e/) { |e| + e.should == "abc" + $~.should == nil + } + + # Set by the match of "def" + $&.should == "e" + end + + it "sets $~ to the last match when given no block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].grep_v(/e/).should == ["abc"] + + # Set by the match of "def" + $&.should == "e" + + ["abc", "def"].grep_v(/b/) + $&.should == nil + end + describe "without block" do it "returns an Array of matched elements" do @numerous.grep_v(@odd_matcher).should == [0, 2, 4, 6, 8] diff --git a/spec/ruby/core/enumerable/max_by_spec.rb b/spec/ruby/core/enumerable/max_by_spec.rb index 76590b602f..ec1738ea3b 100644 --- a/spec/ruby/core/enumerable/max_by_spec.rb +++ b/spec/ruby/core/enumerable/max_by_spec.rb @@ -67,7 +67,7 @@ describe "Enumerable#max_by" do context "when n is negative" do it "raises an ArgumentError" do - lambda { @enum.max_by(-1) { |i| i.to_s } }.should raise_error(ArgumentError) + -> { @enum.max_by(-1) { |i| i.to_s } }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/enumerable/max_spec.rb b/spec/ruby/core/enumerable/max_spec.rb index b1d15126c2..0c11ca0969 100644 --- a/spec/ruby/core/enumerable/max_spec.rb +++ b/spec/ruby/core/enumerable/max_spec.rb @@ -36,16 +36,16 @@ describe "Enumerable#max" do end it "raises a NoMethodError for elements without #<=>" do - lambda do + -> do EnumerableSpecs::EachDefiner.new(BasicObject.new, BasicObject.new).max end.should raise_error(NoMethodError) end it "raises an ArgumentError for incomparable elements" do - lambda do + -> do EnumerableSpecs::EachDefiner.new(11,"22").max end.should raise_error(ArgumentError) - lambda do + -> do EnumerableSpecs::EachDefiner.new(11,12,22,33).max{|a, b| nil} end.should raise_error(ArgumentError) end @@ -106,7 +106,7 @@ describe "Enumerable#max" do context "that is negative" do it "raises an ArgumentError" do - lambda { @e_ints.max(-1) }.should raise_error(ArgumentError) + -> { @e_ints.max(-1) }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/enumerable/min_by_spec.rb b/spec/ruby/core/enumerable/min_by_spec.rb index 5f9b2aea00..3ff87e49d8 100644 --- a/spec/ruby/core/enumerable/min_by_spec.rb +++ b/spec/ruby/core/enumerable/min_by_spec.rb @@ -67,7 +67,7 @@ describe "Enumerable#min_by" do context "when n is negative" do it "raises an ArgumentError" do - lambda { @enum.min_by(-1) { |i| i.to_s } }.should raise_error(ArgumentError) + -> { @enum.min_by(-1) { |i| i.to_s } }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/enumerable/min_spec.rb b/spec/ruby/core/enumerable/min_spec.rb index a31633e8c4..4b6ae248fa 100644 --- a/spec/ruby/core/enumerable/min_spec.rb +++ b/spec/ruby/core/enumerable/min_spec.rb @@ -36,16 +36,16 @@ describe "Enumerable#min" do end it "raises a NoMethodError for elements without #<=>" do - lambda do + -> do EnumerableSpecs::EachDefiner.new(BasicObject.new, BasicObject.new).min end.should raise_error(NoMethodError) end it "raises an ArgumentError for incomparable elements" do - lambda do + -> do EnumerableSpecs::EachDefiner.new(11,"22").min end.should raise_error(ArgumentError) - lambda do + -> do EnumerableSpecs::EachDefiner.new(11,12,22,33).min{|a, b| nil} end.should raise_error(ArgumentError) end @@ -110,7 +110,7 @@ describe "Enumerable#min" do context "that is negative" do it "raises an ArgumentError" do - lambda { @e_ints.min(-1) }.should raise_error(ArgumentError) + -> { @e_ints.min(-1) }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/enumerable/minmax_spec.rb b/spec/ruby/core/enumerable/minmax_spec.rb index f05291aec4..29f1ecf82c 100644 --- a/spec/ruby/core/enumerable/minmax_spec.rb +++ b/spec/ruby/core/enumerable/minmax_spec.rb @@ -18,16 +18,16 @@ describe "Enumerable#minmax" do end it "raises an ArgumentError when elements are incomparable" do - lambda do + -> do EnumerableSpecs::Numerous.new(11,"22").minmax end.should raise_error(ArgumentError) - lambda do + -> do EnumerableSpecs::Numerous.new(11,12,22,33).minmax{|a, b| nil} end.should raise_error(ArgumentError) end it "raises a NoMethodError for elements without #<=>" do - lambda do + -> do EnumerableSpecs::Numerous.new(BasicObject.new, BasicObject.new).minmax end.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/enumerable/none_spec.rb b/spec/ruby/core/enumerable/none_spec.rb index bff252df5e..7c17e58a13 100644 --- a/spec/ruby/core/enumerable/none_spec.rb +++ b/spec/ruby/core/enumerable/none_spec.rb @@ -15,26 +15,26 @@ describe "Enumerable#none?" do end it "raises an ArgumentError when more than 1 argument is provided" do - lambda { @enum.none?(1, 2, 3) }.should raise_error(ArgumentError) - lambda { [].none?(1, 2, 3) }.should raise_error(ArgumentError) - lambda { {}.none?(1, 2, 3) }.should raise_error(ArgumentError) + -> { @enum.none?(1, 2, 3) }.should raise_error(ArgumentError) + -> { [].none?(1, 2, 3) }.should raise_error(ArgumentError) + -> { {}.none?(1, 2, 3) }.should raise_error(ArgumentError) end ruby_version_is ""..."2.5" do it "raises an ArgumentError when any arguments provided" do - lambda { @enum.none?(Proc.new {}) }.should raise_error(ArgumentError) - lambda { @enum.none?(nil) }.should raise_error(ArgumentError) - lambda { @empty.none?(1) }.should raise_error(ArgumentError) - lambda { @enum.none?(1) {} }.should raise_error(ArgumentError) + -> { @enum.none?(Proc.new {}) }.should raise_error(ArgumentError) + -> { @enum.none?(nil) }.should raise_error(ArgumentError) + -> { @empty.none?(1) }.should raise_error(ArgumentError) + -> { @enum.none?(1) {} }.should raise_error(ArgumentError) end end it "does not hide exceptions out of #each" do - lambda { + -> { EnumerableSpecs::ThrowingEach.new.none? }.should raise_error(RuntimeError) - lambda { + -> { EnumerableSpecs::ThrowingEach.new.none? { false } }.should raise_error(RuntimeError) end @@ -82,7 +82,7 @@ describe "Enumerable#none?" do end it "does not hide exceptions out of the block" do - lambda { + -> { @enum.none? { raise "from block" } }.should raise_error(RuntimeError) end @@ -126,7 +126,7 @@ describe "Enumerable#none?" do end it "does not hide exceptions out of #each" do - lambda { + -> { EnumerableSpecs::ThrowingEach.new.none?(Integer) }.should raise_error(RuntimeError) end @@ -151,7 +151,7 @@ describe "Enumerable#none?" do it "does not hide exceptions out of pattern#===" do pattern = EnumerableSpecs::Pattern.new { raise "from pattern" } - lambda { + -> { @enum.none?(pattern) }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerable/one_spec.rb b/spec/ruby/core/enumerable/one_spec.rb index 2bd67adc26..2ae8b3efa4 100644 --- a/spec/ruby/core/enumerable/one_spec.rb +++ b/spec/ruby/core/enumerable/one_spec.rb @@ -15,26 +15,26 @@ describe "Enumerable#one?" do end it "raises an ArgumentError when more than 1 argument is provided" do - lambda { @enum.one?(1, 2, 3) }.should raise_error(ArgumentError) - lambda { [].one?(1, 2, 3) }.should raise_error(ArgumentError) - lambda { {}.one?(1, 2, 3) }.should raise_error(ArgumentError) + -> { @enum.one?(1, 2, 3) }.should raise_error(ArgumentError) + -> { [].one?(1, 2, 3) }.should raise_error(ArgumentError) + -> { {}.one?(1, 2, 3) }.should raise_error(ArgumentError) end ruby_version_is ""..."2.5" do it "raises an ArgumentError when any arguments provided" do - lambda { @enum.one?(Proc.new {}) }.should raise_error(ArgumentError) - lambda { @enum.one?(nil) }.should raise_error(ArgumentError) - lambda { @empty.one?(1) }.should raise_error(ArgumentError) - lambda { @enum.one?(1) {} }.should raise_error(ArgumentError) + -> { @enum.one?(Proc.new {}) }.should raise_error(ArgumentError) + -> { @enum.one?(nil) }.should raise_error(ArgumentError) + -> { @empty.one?(1) }.should raise_error(ArgumentError) + -> { @enum.one?(1) {} }.should raise_error(ArgumentError) end end it "does not hide exceptions out of #each" do - lambda { + -> { EnumerableSpecs::ThrowingEach.new.one? }.should raise_error(RuntimeError) - lambda { + -> { EnumerableSpecs::ThrowingEach.new.one? { false } }.should raise_error(RuntimeError) end @@ -72,7 +72,7 @@ describe "Enumerable#one?" do end it "does not hide exceptions out of the block" do - lambda { + -> { @enum.one? { raise "from block" } }.should raise_error(RuntimeError) end @@ -117,7 +117,7 @@ describe "Enumerable#one?" do end it "does not hide exceptions out of #each" do - lambda { + -> { EnumerableSpecs::ThrowingEach.new.one?(Integer) }.should raise_error(RuntimeError) end @@ -153,7 +153,7 @@ describe "Enumerable#one?" do it "does not hide exceptions out of pattern#===" do pattern = EnumerableSpecs::Pattern.new { raise "from pattern" } - lambda { + -> { @enum.one?(pattern) }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerable/shared/collect_concat.rb b/spec/ruby/core/enumerable/shared/collect_concat.rb index c081c1be71..ddd431baeb 100644 --- a/spec/ruby/core/enumerable/shared/collect_concat.rb +++ b/spec/ruby/core/enumerable/shared/collect_concat.rb @@ -41,7 +41,7 @@ describe :enumerable_collect_concat, shared: true do obj = mock("to_ary defined") obj.should_receive(:to_ary).and_return("array") - lambda { [1, obj, 3].send(@method) { |i| i } }.should raise_error(TypeError) + -> { [1, obj, 3].send(@method) { |i| i } }.should raise_error(TypeError) end it "returns an enumerator when no block given" do diff --git a/spec/ruby/core/enumerable/shared/find.rb b/spec/ruby/core/enumerable/shared/find.rb index 3435ce3658..61d63ba3d5 100644 --- a/spec/ruby/core/enumerable/shared/find.rb +++ b/spec/ruby/core/enumerable/shared/find.rb @@ -29,23 +29,23 @@ 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 @@ -64,7 +64,7 @@ describe :enumerable_find, shared: true do 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 diff --git a/spec/ruby/core/enumerable/shared/take.rb b/spec/ruby/core/enumerable/shared/take.rb index bf2536acda..ce2ace20fa 100644 --- a/spec/ruby/core/enumerable/shared/take.rb +++ b/spec/ruby/core/enumerable/shared/take.rb @@ -25,7 +25,7 @@ describe :enumerable_take, shared: true do end it "raises an ArgumentError when count is negative" do - lambda { @enum.send(@method, -1) }.should raise_error(ArgumentError) + -> { @enum.send(@method, -1) }.should raise_error(ArgumentError) end it "returns the entire array when count > length" do @@ -40,11 +40,11 @@ describe :enumerable_take, shared: true do end it "raises a TypeError if the passed argument is not numeric" do - lambda { @enum.send(@method, nil) }.should raise_error(TypeError) - lambda { @enum.send(@method, "a") }.should raise_error(TypeError) + -> { @enum.send(@method, nil) }.should raise_error(TypeError) + -> { @enum.send(@method, "a") }.should raise_error(TypeError) obj = mock("nonnumeric") - lambda { @enum.send(@method, obj) }.should raise_error(TypeError) + -> { @enum.send(@method, obj) }.should raise_error(TypeError) end it "gathers whole arrays as elements when each yields multiple" do diff --git a/spec/ruby/core/enumerable/slice_after_spec.rb b/spec/ruby/core/enumerable/slice_after_spec.rb index c1bb7f0d83..0e46688db1 100644 --- a/spec/ruby/core/enumerable/slice_after_spec.rb +++ b/spec/ruby/core/enumerable/slice_after_spec.rb @@ -41,14 +41,14 @@ describe "Enumerable#slice_after" do describe "and an argument" do it "raises an ArgumentError" do - lambda { @enum.slice_after(42) { |i| i == 6 } }.should raise_error(ArgumentError) + -> { @enum.slice_after(42) { |i| i == 6 } }.should raise_error(ArgumentError) end end end it "raises an ArgumentError when given an incorrect number of arguments" do - lambda { @enum.slice_after("one", "two") }.should raise_error(ArgumentError) - lambda { @enum.slice_after }.should raise_error(ArgumentError) + -> { @enum.slice_after("one", "two") }.should raise_error(ArgumentError) + -> { @enum.slice_after }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/enumerable/slice_before_spec.rb b/spec/ruby/core/enumerable/slice_before_spec.rb index ad730be245..f9b33f7b28 100644 --- a/spec/ruby/core/enumerable/slice_before_spec.rb +++ b/spec/ruby/core/enumerable/slice_before_spec.rb @@ -41,15 +41,15 @@ describe "Enumerable#slice_before" do end it "does not accept arguments" do - lambda { + -> { @enum.slice_before(1) {} }.should raise_error(ArgumentError) end end it "raises an ArgumentError when given an incorrect number of arguments" do - lambda { @enum.slice_before("one", "two") }.should raise_error(ArgumentError) - lambda { @enum.slice_before }.should raise_error(ArgumentError) + -> { @enum.slice_before("one", "two") }.should raise_error(ArgumentError) + -> { @enum.slice_before }.should raise_error(ArgumentError) end describe "when an iterator method yields more than one value" do diff --git a/spec/ruby/core/enumerable/slice_when_spec.rb b/spec/ruby/core/enumerable/slice_when_spec.rb index 884b1a471c..6b8ea0923e 100644 --- a/spec/ruby/core/enumerable/slice_when_spec.rb +++ b/spec/ruby/core/enumerable/slice_when_spec.rb @@ -39,7 +39,7 @@ describe "Enumerable#slice_when" do context "when not given a block" do it "raises an ArgumentError" do - lambda { @enum.slice_when }.should raise_error(ArgumentError) + -> { @enum.slice_when }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/enumerable/sort_spec.rb b/spec/ruby/core/enumerable/sort_spec.rb index bf20e55f61..cff1a59986 100644 --- a/spec/ruby/core/enumerable/sort_spec.rb +++ b/spec/ruby/core/enumerable/sort_spec.rb @@ -14,7 +14,7 @@ describe "Enumerable#sort" do end it "raises a NoMethodError if elements do not define <=>" do - lambda do + -> do EnumerableSpecs::Numerous.new(BasicObject.new, BasicObject.new, BasicObject.new).sort end.should raise_error(NoMethodError) end @@ -33,14 +33,14 @@ describe "Enumerable#sort" do EnumerableSpecs::Numerous.new.sort { |n, m| EnumerableSpecs::ComparableWithFixnum.new(-(n+m) * (n <=> m)) }.should == [6, 5, 4, 3, 2, 1] - lambda { + -> { EnumerableSpecs::Numerous.new.sort { |n, m| (n <=> m).to_s } }.should raise_error(ArgumentError) end it "raises an error if objects can't be compared" do a=EnumerableSpecs::Numerous.new(EnumerableSpecs::Uncomparable.new, EnumerableSpecs::Uncomparable.new) - lambda {a.sort}.should raise_error(ArgumentError) + -> {a.sort}.should raise_error(ArgumentError) end it "gathers whole arrays as elements when each yields multiple" do diff --git a/spec/ruby/core/enumerable/take_spec.rb b/spec/ruby/core/enumerable/take_spec.rb index c0af372752..41a7438330 100644 --- a/spec/ruby/core/enumerable/take_spec.rb +++ b/spec/ruby/core/enumerable/take_spec.rb @@ -4,7 +4,7 @@ require_relative 'shared/take' describe "Enumerable#take" do it "requires an argument" do - lambda{ EnumerableSpecs::Numerous.new.take}.should raise_error(ArgumentError) + ->{ EnumerableSpecs::Numerous.new.take}.should raise_error(ArgumentError) end describe "when passed an argument" do diff --git a/spec/ruby/core/enumerable/to_h_spec.rb b/spec/ruby/core/enumerable/to_h_spec.rb index f15ced122e..63bfdf19af 100644 --- a/spec/ruby/core/enumerable/to_h_spec.rb +++ b/spec/ruby/core/enumerable/to_h_spec.rb @@ -36,12 +36,12 @@ describe "Enumerable#to_h" do it "raises TypeError if an element is not an array" do enum = EnumerableSpecs::EachDefiner.new(:x) - lambda { enum.to_h }.should raise_error(TypeError) + -> { enum.to_h }.should raise_error(TypeError) end it "raises ArgumentError if an element is not a [key, value] pair" do enum = EnumerableSpecs::EachDefiner.new([:x]) - lambda { enum.to_h }.should raise_error(ArgumentError) + -> { enum.to_h }.should raise_error(ArgumentError) end ruby_version_is "2.6" do |