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 | |
parent | a06301b103371b0b7da8eaca26ba744961769f99 (diff) | |
download | ruby-5c276e1cc91c5ab2a41fbf7827af2fed914a2bc0.tar.gz |
Update to ruby/spec@875a09e
Diffstat (limited to 'spec/ruby/core')
702 files changed, 3330 insertions, 3093 deletions
diff --git a/spec/ruby/core/argf/close_spec.rb b/spec/ruby/core/argf/close_spec.rb index 56faf30664..d4d6a51e72 100644 --- a/spec/ruby/core/argf/close_spec.rb +++ b/spec/ruby/core/argf/close_spec.rb @@ -22,8 +22,8 @@ describe "ARGF.close" do it "doesn't raise an IOError if called on a closed stream" do argf [@file1_name] do - lambda { @argf.close }.should_not raise_error - lambda { @argf.close }.should_not raise_error + -> { @argf.close }.should_not raise_error + -> { @argf.close }.should_not raise_error end end end diff --git a/spec/ruby/core/argf/read_nonblock_spec.rb b/spec/ruby/core/argf/read_nonblock_spec.rb index 466264119f..804a459a62 100644 --- a/spec/ruby/core/argf/read_nonblock_spec.rb +++ b/spec/ruby/core/argf/read_nonblock_spec.rb @@ -64,7 +64,7 @@ platform_is_not :windows do it 'raises IO::EAGAINWaitReadable when empty' do argf ['-'] do - lambda { + -> { @argf.read_nonblock(4) }.should raise_error(IO::EAGAINWaitReadable) end diff --git a/spec/ruby/core/argf/readchar_spec.rb b/spec/ruby/core/argf/readchar_spec.rb index bd3bfd28ae..4eca2efcf7 100644 --- a/spec/ruby/core/argf/readchar_spec.rb +++ b/spec/ruby/core/argf/readchar_spec.rb @@ -13,7 +13,7 @@ describe "ARGF.readchar" do it "raises EOFError when end of stream reached" do argf [@file1, @file2] do - lambda { while @argf.readchar; end }.should raise_error(EOFError) + -> { while @argf.readchar; end }.should raise_error(EOFError) end end end diff --git a/spec/ruby/core/argf/readline_spec.rb b/spec/ruby/core/argf/readline_spec.rb index e196274068..db53c499e9 100644 --- a/spec/ruby/core/argf/readline_spec.rb +++ b/spec/ruby/core/argf/readline_spec.rb @@ -17,7 +17,7 @@ describe "ARGF.readline" do it "raises an EOFError when reaching end of files" do argf [@file1, @file2] do - lambda { while @argf.readline; end }.should raise_error(EOFError) + -> { while @argf.readline; end }.should raise_error(EOFError) end end end diff --git a/spec/ruby/core/argf/readpartial_spec.rb b/spec/ruby/core/argf/readpartial_spec.rb index 4e697683dc..5e284b3423 100644 --- a/spec/ruby/core/argf/readpartial_spec.rb +++ b/spec/ruby/core/argf/readpartial_spec.rb @@ -16,7 +16,7 @@ describe "ARGF.readpartial" do it "raises an ArgumentError if called without a maximum read length" do argf [@file1_name] do - lambda { @argf.readpartial }.should raise_error(ArgumentError) + -> { @argf.readpartial }.should raise_error(ArgumentError) end end @@ -59,8 +59,8 @@ describe "ARGF.readpartial" do @argf.readpartial(@file1.size) @argf.readpartial(1) @argf.readpartial(@file2.size) - lambda { @argf.readpartial(1) }.should raise_error(EOFError) - lambda { @argf.readpartial(1) }.should raise_error(EOFError) + -> { @argf.readpartial(1) }.should raise_error(EOFError) + -> { @argf.readpartial(1) }.should raise_error(EOFError) end end diff --git a/spec/ruby/core/argf/rewind_spec.rb b/spec/ruby/core/argf/rewind_spec.rb index fcb2e81a3e..b29f0b75b7 100644 --- a/spec/ruby/core/argf/rewind_spec.rb +++ b/spec/ruby/core/argf/rewind_spec.rb @@ -33,7 +33,7 @@ describe "ARGF.rewind" do it "raises an ArgumentError when end of stream reached" do argf [@file1_name, @file2_name] do @argf.read - lambda { @argf.rewind }.should raise_error(ArgumentError) + -> { @argf.rewind }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/argf/seek_spec.rb b/spec/ruby/core/argf/seek_spec.rb index c983c0cb5a..2b73bd46fb 100644 --- a/spec/ruby/core/argf/seek_spec.rb +++ b/spec/ruby/core/argf/seek_spec.rb @@ -57,7 +57,7 @@ describe "ARGF.seek" do it "takes at least one argument (offset)" do argf [@file1_name] do - lambda { @argf.seek }.should raise_error(ArgumentError) + -> { @argf.seek }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/argf/shared/eof.rb b/spec/ruby/core/argf/shared/eof.rb index bba18ede50..0e684f943f 100644 --- a/spec/ruby/core/argf/shared/eof.rb +++ b/spec/ruby/core/argf/shared/eof.rb @@ -18,7 +18,7 @@ describe :argf_eof, shared: true do it "raises IOError when called on a closed stream" do argf [@file1] do @argf.read - lambda { @argf.send(@method) }.should raise_error(IOError) + -> { @argf.send(@method) }.should raise_error(IOError) end end end diff --git a/spec/ruby/core/argf/shared/fileno.rb b/spec/ruby/core/argf/shared/fileno.rb index 891e250ad9..5d674048e2 100644 --- a/spec/ruby/core/argf/shared/fileno.rb +++ b/spec/ruby/core/argf/shared/fileno.rb @@ -18,7 +18,7 @@ describe :argf_fileno, shared: true do it "raises an ArgumentError when called on a closed stream" do argf [@file1] do @argf.read - lambda { @argf.send(@method) }.should raise_error(ArgumentError) + -> { @argf.send(@method) }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/argf/shared/pos.rb b/spec/ruby/core/argf/shared/pos.rb index f7184f3d7c..9836d5f1e4 100644 --- a/spec/ruby/core/argf/shared/pos.rb +++ b/spec/ruby/core/argf/shared/pos.rb @@ -25,7 +25,7 @@ describe :argf_pos, shared: true do it "raises an ArgumentError when called on a closed stream" do argf [@file1] do @argf.read - lambda { @argf.send(@method) }.should raise_error(ArgumentError) + -> { @argf.send(@method) }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/argf/skip_spec.rb b/spec/ruby/core/argf/skip_spec.rb index 89b7146e3a..0181801c2d 100644 --- a/spec/ruby/core/argf/skip_spec.rb +++ b/spec/ruby/core/argf/skip_spec.rb @@ -37,6 +37,6 @@ describe "ARGF.skip" do # which as a side-effect calls argf.file which will initialize # internals of ARGF enough for this to work. it "has no effect when nothing has been processed yet" do - lambda { ARGF.class.new(@file1_name).skip }.should_not raise_error + -> { ARGF.class.new(@file1_name).skip }.should_not raise_error end end diff --git a/spec/ruby/core/array/allocate_spec.rb b/spec/ruby/core/array/allocate_spec.rb index a1800e7e16..04f7c0d0ad 100644 --- a/spec/ruby/core/array/allocate_spec.rb +++ b/spec/ruby/core/array/allocate_spec.rb @@ -14,6 +14,6 @@ describe "Array.allocate" do end it "does not accept any arguments" do - lambda { Array.allocate(1) }.should raise_error(ArgumentError) + -> { Array.allocate(1) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/array/append_spec.rb b/spec/ruby/core/array/append_spec.rb index 08ea814d89..302dc4a901 100644 --- a/spec/ruby/core/array/append_spec.rb +++ b/spec/ruby/core/array/append_spec.rb @@ -31,7 +31,7 @@ describe "Array#<<" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array << 5 }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array << 5 }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/at_spec.rb b/spec/ruby/core/array/at_spec.rb index d237c9508a..8bc789fef7 100644 --- a/spec/ruby/core/array/at_spec.rb +++ b/spec/ruby/core/array/at_spec.rb @@ -47,10 +47,10 @@ describe "Array#at" do end it "raises a TypeError when the passed argument can't be coerced to Integer" do - lambda { [].at("cat") }.should raise_error(TypeError) + -> { [].at("cat") }.should raise_error(TypeError) end it "raises an ArgumentError when 2 or more arguments are passed" do - lambda { [:a, :b].at(0,1) }.should raise_error(ArgumentError) + -> { [:a, :b].at(0,1) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/array/bsearch_index_spec.rb b/spec/ruby/core/array/bsearch_index_spec.rb index a075d06ed3..aafded178d 100644 --- a/spec/ruby/core/array/bsearch_index_spec.rb +++ b/spec/ruby/core/array/bsearch_index_spec.rb @@ -21,7 +21,7 @@ describe "Array#bsearch_index" do end it "raises a TypeError when block returns a String" do - lambda { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError) + -> { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError) end it "returns nil when block is empty" do diff --git a/spec/ruby/core/array/bsearch_spec.rb b/spec/ruby/core/array/bsearch_spec.rb index 57b95fb934..8fa6245dbf 100644 --- a/spec/ruby/core/array/bsearch_spec.rb +++ b/spec/ruby/core/array/bsearch_spec.rb @@ -9,11 +9,11 @@ describe "Array#bsearch" do it_behaves_like :enumeratorized_with_unknown_size, :bsearch, [1,2,3] it "raises a TypeError if the block returns an Object" do - lambda { [1].bsearch { Object.new } }.should raise_error(TypeError) + -> { [1].bsearch { Object.new } }.should raise_error(TypeError) end it "raises a TypeError if the block returns a String" do - lambda { [1].bsearch { "1" } }.should raise_error(TypeError) + -> { [1].bsearch { "1" } }.should raise_error(TypeError) end context "with a block returning true or false" do diff --git a/spec/ruby/core/array/clear_spec.rb b/spec/ruby/core/array/clear_spec.rb index 8cba1f9e27..8f83a012b7 100644 --- a/spec/ruby/core/array/clear_spec.rb +++ b/spec/ruby/core/array/clear_spec.rb @@ -29,7 +29,7 @@ describe "Array#clear" do end it "does not accept any arguments" do - lambda { [1].clear(true) }.should raise_error(ArgumentError) + -> { [1].clear(true) }.should raise_error(ArgumentError) end it "keeps untrusted status" do @@ -43,6 +43,6 @@ describe "Array#clear" do it "raises a #{frozen_error_class} on a frozen array" do a = [1] a.freeze - lambda { a.clear }.should raise_error(frozen_error_class) + -> { a.clear }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/compact_spec.rb b/spec/ruby/core/array/compact_spec.rb index 4818217be1..ecccddeb9f 100644 --- a/spec/ruby/core/array/compact_spec.rb +++ b/spec/ruby/core/array/compact_spec.rb @@ -72,6 +72,6 @@ describe "Array#compact!" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.compact! }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.compact! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/concat_spec.rb b/spec/ruby/core/array/concat_spec.rb index 91adb8b745..cc707d9948 100644 --- a/spec/ruby/core/array/concat_spec.rb +++ b/spec/ruby/core/array/concat_spec.rb @@ -33,12 +33,12 @@ describe "Array#concat" do end it "raises a #{frozen_error_class} when Array is frozen and modification occurs" do - lambda { ArraySpecs.frozen_array.concat [1] }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.concat [1] }.should raise_error(frozen_error_class) end # see [ruby-core:23666] it "raises a #{frozen_error_class} when Array is frozen and no modification occurs" do - lambda { ArraySpecs.frozen_array.concat([]) }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.concat([]) }.should raise_error(frozen_error_class) end it "keeps tainted status" do diff --git a/spec/ruby/core/array/cycle_spec.rb b/spec/ruby/core/array/cycle_spec.rb index 018005abb4..7219b49883 100644 --- a/spec/ruby/core/array/cycle_spec.rb +++ b/spec/ruby/core/array/cycle_spec.rb @@ -6,7 +6,7 @@ describe "Array#cycle" do ScratchPad.record [] @array = [1, 2, 3] - @prc = lambda { |x| ScratchPad << x } + @prc = -> x { ScratchPad << x } end it "does not yield and returns nil when the array is empty and passed value is an integer" do @@ -46,13 +46,13 @@ describe "Array#cycle" do end it "does not rescue StopIteration when not passed a count" do - lambda do + -> do @array.cycle { raise StopIteration } end.should raise_error(StopIteration) end it "does not rescue StopIteration when passed a count" do - lambda do + -> do @array.cycle(3) { raise StopIteration } end.should raise_error(StopIteration) end @@ -74,23 +74,23 @@ describe "Array#cycle" do count = mock("cycle count 2") count.should_receive(:to_int).and_return("2") - lambda { @array.cycle(count, &@prc) }.should raise_error(TypeError) + -> { @array.cycle(count, &@prc) }.should raise_error(TypeError) end it "raises a TypeError if passed a String" do - lambda { @array.cycle("4") { } }.should raise_error(TypeError) + -> { @array.cycle("4") { } }.should raise_error(TypeError) end it "raises a TypeError if passed an Object" do - lambda { @array.cycle(mock("cycle count")) { } }.should raise_error(TypeError) + -> { @array.cycle(mock("cycle count")) { } }.should raise_error(TypeError) end it "raises a TypeError if passed true" do - lambda { @array.cycle(true) { } }.should raise_error(TypeError) + -> { @array.cycle(true) { } }.should raise_error(TypeError) end it "raises a TypeError if passed false" do - lambda { @array.cycle(false) { } }.should raise_error(TypeError) + -> { @array.cycle(false) { } }.should raise_error(TypeError) end before :all do diff --git a/spec/ruby/core/array/delete_at_spec.rb b/spec/ruby/core/array/delete_at_spec.rb index 021554c76a..c3111fe3d8 100644 --- a/spec/ruby/core/array/delete_at_spec.rb +++ b/spec/ruby/core/array/delete_at_spec.rb @@ -36,7 +36,7 @@ describe "Array#delete_at" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { [1,2,3].freeze.delete_at(0) }.should raise_error(frozen_error_class) + -> { [1,2,3].freeze.delete_at(0) }.should raise_error(frozen_error_class) end it "keeps tainted status" do diff --git a/spec/ruby/core/array/delete_if_spec.rb b/spec/ruby/core/array/delete_if_spec.rb index 12a7d1662d..9f22f7e086 100644 --- a/spec/ruby/core/array/delete_if_spec.rb +++ b/spec/ruby/core/array/delete_if_spec.rb @@ -40,11 +40,11 @@ describe "Array#delete_if" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.delete_if {} }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.delete_if {} }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(frozen_error_class) end it "keeps tainted status" do diff --git a/spec/ruby/core/array/delete_spec.rb b/spec/ruby/core/array/delete_spec.rb index 62476f489b..c55f4ad672 100644 --- a/spec/ruby/core/array/delete_spec.rb +++ b/spec/ruby/core/array/delete_spec.rb @@ -41,7 +41,7 @@ describe "Array#delete" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { [1, 2, 3].freeze.delete(1) }.should raise_error(frozen_error_class) + -> { [1, 2, 3].freeze.delete(1) }.should raise_error(frozen_error_class) end it "keeps tainted status" do diff --git a/spec/ruby/core/array/dig_spec.rb b/spec/ruby/core/array/dig_spec.rb index 1ace4893ee..f2d8ff47fd 100644 --- a/spec/ruby/core/array/dig_spec.rb +++ b/spec/ruby/core/array/dig_spec.rb @@ -20,20 +20,20 @@ describe "Array#dig" do end it "raises a TypeError for a non-numeric index" do - lambda { + -> { ['a'].dig(:first) }.should raise_error(TypeError) end it "raises a TypeError if any intermediate step does not respond to #dig" do a = [1, 2] - lambda { + -> { a.dig(0, 1) }.should raise_error(TypeError) end it "raises an ArgumentError if no arguments provided" do - lambda { + -> { [10].dig() }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/array/drop_spec.rb b/spec/ruby/core/array/drop_spec.rb index 1bd2e6cc25..89b8534af4 100644 --- a/spec/ruby/core/array/drop_spec.rb +++ b/spec/ruby/core/array/drop_spec.rb @@ -6,7 +6,7 @@ describe "Array#drop" do end it "raises an ArgumentError if the number of elements specified is negative" do - lambda { [1, 2].drop(-3) }.should raise_error(ArgumentError) + -> { [1, 2].drop(-3) }.should raise_error(ArgumentError) end it "returns an empty Array if all elements are dropped" do diff --git a/spec/ruby/core/array/element_set_spec.rb b/spec/ruby/core/array/element_set_spec.rb index 9992e4d32b..9375ff9b80 100644 --- a/spec/ruby/core/array/element_set_spec.rb +++ b/spec/ruby/core/array/element_set_spec.rb @@ -94,8 +94,8 @@ describe "Array#[]=" do it "checks frozen before attempting to coerce arguments" do a = [1,2,3,4].freeze - lambda {a[:foo] = 1}.should raise_error(frozen_error_class) - lambda {a[:foo, :bar] = 1}.should raise_error(frozen_error_class) + -> {a[:foo] = 1}.should raise_error(frozen_error_class) + -> {a[:foo, :bar] = 1}.should raise_error(frozen_error_class) end it "sets elements in the range arguments when passed ranges" do @@ -195,25 +195,25 @@ describe "Array#[]=" do a[to .. from] = ["x"] a.should == [1, "a", "b", "x", "c", 4] - lambda { a["a" .. "b"] = [] }.should raise_error(TypeError) - lambda { a[from .. "b"] = [] }.should raise_error(TypeError) + -> { a["a" .. "b"] = [] }.should raise_error(TypeError) + -> { a[from .. "b"] = [] }.should raise_error(TypeError) end it "raises an IndexError when passed indexes out of bounds" do a = [1, 2, 3, 4] - lambda { a[-5] = "" }.should raise_error(IndexError) - lambda { a[-5, -1] = "" }.should raise_error(IndexError) - lambda { a[-5, 0] = "" }.should raise_error(IndexError) - lambda { a[-5, 1] = "" }.should raise_error(IndexError) - lambda { a[-5, 2] = "" }.should raise_error(IndexError) - lambda { a[-5, 10] = "" }.should raise_error(IndexError) - - lambda { a[-5..-5] = "" }.should raise_error(RangeError) - lambda { a[-5...-5] = "" }.should raise_error(RangeError) - lambda { a[-5..-4] = "" }.should raise_error(RangeError) - lambda { a[-5...-4] = "" }.should raise_error(RangeError) - lambda { a[-5..10] = "" }.should raise_error(RangeError) - lambda { a[-5...10] = "" }.should raise_error(RangeError) + -> { a[-5] = "" }.should raise_error(IndexError) + -> { a[-5, -1] = "" }.should raise_error(IndexError) + -> { a[-5, 0] = "" }.should raise_error(IndexError) + -> { a[-5, 1] = "" }.should raise_error(IndexError) + -> { a[-5, 2] = "" }.should raise_error(IndexError) + -> { a[-5, 10] = "" }.should raise_error(IndexError) + + -> { a[-5..-5] = "" }.should raise_error(RangeError) + -> { a[-5...-5] = "" }.should raise_error(RangeError) + -> { a[-5..-4] = "" }.should raise_error(RangeError) + -> { a[-5...-4] = "" }.should raise_error(RangeError) + -> { a[-5..10] = "" }.should raise_error(RangeError) + -> { a[-5...10] = "" }.should raise_error(RangeError) # ok a[0..-9] = [1] @@ -237,7 +237,7 @@ describe "Array#[]=" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array[0, 0] = [] }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array[0, 0] = [] }.should raise_error(frozen_error_class) end end @@ -337,12 +337,12 @@ describe "Array#[]= with [index, count]" do it "raises an IndexError when passed start and negative length" do a = [1, 2, 3, 4] - lambda { a[-2, -1] = "" }.should raise_error(IndexError) - lambda { a[0, -1] = "" }.should raise_error(IndexError) - lambda { a[2, -1] = "" }.should raise_error(IndexError) - lambda { a[4, -1] = "" }.should raise_error(IndexError) - lambda { a[10, -1] = "" }.should raise_error(IndexError) - lambda { [1, 2, 3, 4, 5][2, -1] = [7, 8] }.should raise_error(IndexError) + -> { a[-2, -1] = "" }.should raise_error(IndexError) + -> { a[0, -1] = "" }.should raise_error(IndexError) + -> { a[2, -1] = "" }.should raise_error(IndexError) + -> { a[4, -1] = "" }.should raise_error(IndexError) + -> { a[10, -1] = "" }.should raise_error(IndexError) + -> { [1, 2, 3, 4, 5][2, -1] = [7, 8] }.should raise_error(IndexError) end end diff --git a/spec/ruby/core/array/fetch_spec.rb b/spec/ruby/core/array/fetch_spec.rb index ccca463935..b81c0b48d7 100644 --- a/spec/ruby/core/array/fetch_spec.rb +++ b/spec/ruby/core/array/fetch_spec.rb @@ -12,9 +12,9 @@ describe "Array#fetch" do end it "raises an IndexError if there is no element at index" do - lambda { [1, 2, 3].fetch(3) }.should raise_error(IndexError) - lambda { [1, 2, 3].fetch(-4) }.should raise_error(IndexError) - lambda { [].fetch(0) }.should raise_error(IndexError) + -> { [1, 2, 3].fetch(3) }.should raise_error(IndexError) + -> { [1, 2, 3].fetch(-4) }.should raise_error(IndexError) + -> { [].fetch(0) }.should raise_error(IndexError) end it "returns default if there is no element at index if passed a default value" do @@ -37,7 +37,7 @@ describe "Array#fetch" do end it "gives precedence to the default block over the default argument" do - lambda { + -> { @result = [1, 2, 3].fetch(9, :foo) { |i| i * i } }.should complain(/block supersedes default value argument/) @result.should == 81 @@ -50,6 +50,6 @@ describe "Array#fetch" do end it "raises a TypeError when the passed argument can't be coerced to Integer" do - lambda { [].fetch("cat") }.should raise_error(TypeError) + -> { [].fetch("cat") }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/array/fill_spec.rb b/spec/ruby/core/array/fill_spec.rb index f953613c26..1c1beef25e 100644 --- a/spec/ruby/core/array/fill_spec.rb +++ b/spec/ruby/core/array/fill_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "Array#fill" do before :all do - @never_passed = lambda do |i| + @never_passed = -> i do raise ExpectationNotMetError, "the control path should not pass here" end end @@ -44,33 +44,33 @@ describe "Array#fill" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.fill('x') }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.fill('x') }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.fill('x') }.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.fill('x') }.should raise_error(frozen_error_class) end it "raises an ArgumentError if 4 or more arguments are passed when no block given" do - lambda { [].fill('a') }.should_not raise_error(ArgumentError) + -> { [].fill('a') }.should_not raise_error(ArgumentError) - lambda { [].fill('a', 1) }.should_not raise_error(ArgumentError) + -> { [].fill('a', 1) }.should_not raise_error(ArgumentError) - lambda { [].fill('a', 1, 2) }.should_not raise_error(ArgumentError) - lambda { [].fill('a', 1, 2, true) }.should raise_error(ArgumentError) + -> { [].fill('a', 1, 2) }.should_not raise_error(ArgumentError) + -> { [].fill('a', 1, 2, true) }.should raise_error(ArgumentError) end it "raises an ArgumentError if no argument passed and no block given" do - lambda { [].fill }.should raise_error(ArgumentError) + -> { [].fill }.should raise_error(ArgumentError) end it "raises an ArgumentError if 3 or more arguments are passed when a block given" do - lambda { [].fill() {|i|} }.should_not raise_error(ArgumentError) + -> { [].fill() {|i|} }.should_not raise_error(ArgumentError) - lambda { [].fill(1) {|i|} }.should_not raise_error(ArgumentError) + -> { [].fill(1) {|i|} }.should_not raise_error(ArgumentError) - lambda { [].fill(1, 2) {|i|} }.should_not raise_error(ArgumentError) - lambda { [].fill(1, 2, true) {|i|} }.should raise_error(ArgumentError) + -> { [].fill(1, 2) {|i|} }.should_not raise_error(ArgumentError) + -> { [].fill(1, 2, true) {|i|} }.should raise_error(ArgumentError) end end @@ -171,23 +171,23 @@ describe "Array#fill with (filler, index, length)" do # See: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17481 it "does not raise an exception if the given length is negative and its absolute value does not exceed the index" do - lambda { [1, 2, 3, 4].fill('a', 3, -1)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill('a', 3, -2)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill('a', 3, -3)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill('a', 3, -1)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill('a', 3, -2)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill('a', 3, -3)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill(3, -1, &@never_passed)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill(3, -2, &@never_passed)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill(3, -3, &@never_passed)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill(3, -1, &@never_passed)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill(3, -2, &@never_passed)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill(3, -3, &@never_passed)}.should_not raise_error(ArgumentError) end it "does not raise an exception even if the given length is negative and its absolute value exceeds the index" do - lambda { [1, 2, 3, 4].fill('a', 3, -4)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill('a', 3, -5)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill('a', 3, -10000)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill('a', 3, -4)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill('a', 3, -5)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill('a', 3, -10000)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill(3, -4, &@never_passed)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill(3, -5, &@never_passed)}.should_not raise_error(ArgumentError) - lambda { [1, 2, 3, 4].fill(3, -10000, &@never_passed)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill(3, -4, &@never_passed)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill(3, -5, &@never_passed)}.should_not raise_error(ArgumentError) + -> { [1, 2, 3, 4].fill(3, -10000, &@never_passed)}.should_not raise_error(ArgumentError) end it "tries to convert the second and third arguments to Integers using #to_int" do @@ -199,17 +199,17 @@ describe "Array#fill with (filler, index, length)" do end it "raises a TypeError if the index is not numeric" do - lambda { [].fill 'a', true }.should raise_error(TypeError) + -> { [].fill 'a', true }.should raise_error(TypeError) obj = mock('nonnumeric') - lambda { [].fill('a', obj) }.should raise_error(TypeError) + -> { [].fill('a', obj) }.should raise_error(TypeError) end not_supported_on :opal do it "raises an ArgumentError or RangeError for too-large sizes" do arr = [1, 2, 3] - lambda { arr.fill(10, 1, fixnum_max) }.should raise_error(ArgumentError) - lambda { arr.fill(10, 1, bignum_value) }.should raise_error(RangeError) + -> { arr.fill(10, 1, fixnum_max) }.should raise_error(ArgumentError) + -> { arr.fill(10, 1, bignum_value) }.should raise_error(RangeError) end end end @@ -239,7 +239,7 @@ describe "Array#fill with (filler, range)" do end it "raises a TypeError with range and length argument" do - lambda { [].fill('x', 0 .. 2, 5) }.should raise_error(TypeError) + -> { [].fill('x', 0 .. 2, 5) }.should raise_error(TypeError) end it "replaces elements between the (-m)th to the last and the (n+1)th from the first if given an range m..n where m < 0 and n >= 0" do @@ -291,13 +291,13 @@ describe "Array#fill with (filler, range)" do end it "raises an exception if some of the given range lies before the first of the array" do - lambda { [1, 2, 3].fill('x', -5..-3) }.should raise_error(RangeError) - lambda { [1, 2, 3].fill('x', -5...-3) }.should raise_error(RangeError) - lambda { [1, 2, 3].fill('x', -5..-4) }.should raise_error(RangeError) + -> { [1, 2, 3].fill('x', -5..-3) }.should raise_error(RangeError) + -> { [1, 2, 3].fill('x', -5...-3) }.should raise_error(RangeError) + -> { [1, 2, 3].fill('x', -5..-4) }.should raise_error(RangeError) - lambda { [1, 2, 3].fill(-5..-3, &@never_passed) }.should raise_error(RangeError) - lambda { [1, 2, 3].fill(-5...-3, &@never_passed) }.should raise_error(RangeError) - lambda { [1, 2, 3].fill(-5..-4, &@never_passed) }.should raise_error(RangeError) + -> { [1, 2, 3].fill(-5..-3, &@never_passed) }.should raise_error(RangeError) + -> { [1, 2, 3].fill(-5...-3, &@never_passed) }.should raise_error(RangeError) + -> { [1, 2, 3].fill(-5..-4, &@never_passed) }.should raise_error(RangeError) end it "tries to convert the start and end of the passed range to Integers using #to_int" do @@ -312,6 +312,6 @@ describe "Array#fill with (filler, range)" do it "raises a TypeError if the start or end of the passed range is not numeric" do obj = mock('nonnumeric') def obj.<=>(rhs); rhs == self ? 0 : nil end - lambda { [].fill('a', obj..obj) }.should raise_error(TypeError) + -> { [].fill('a', obj..obj) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/array/first_spec.rb b/spec/ruby/core/array/first_spec.rb index 5a0a25aeef..66eeba6565 100644 --- a/spec/ruby/core/array/first_spec.rb +++ b/spec/ruby/core/array/first_spec.rb @@ -30,11 +30,11 @@ describe "Array#first" do end it "raises an ArgumentError when count is negative" do - lambda { [1, 2].first(-1) }.should raise_error(ArgumentError) + -> { [1, 2].first(-1) }.should raise_error(ArgumentError) end it "raises a RangeError when count is a Bignum" do - lambda { [].first(bignum_value) }.should raise_error(RangeError) + -> { [].first(bignum_value) }.should raise_error(RangeError) end it "returns the entire array when count > length" do @@ -66,11 +66,11 @@ describe "Array#first" do end it "raises a TypeError if the passed argument is not numeric" do - lambda { [1,2].first(nil) }.should raise_error(TypeError) - lambda { [1,2].first("a") }.should raise_error(TypeError) + -> { [1,2].first(nil) }.should raise_error(TypeError) + -> { [1,2].first("a") }.should raise_error(TypeError) obj = mock("nonnumeric") - lambda { [1,2].first(obj) }.should raise_error(TypeError) + -> { [1,2].first(obj) }.should raise_error(TypeError) end it "does not return subclass instance when passed count on Array subclasses" do diff --git a/spec/ruby/core/array/flatten_spec.rb b/spec/ruby/core/array/flatten_spec.rb index 1b7361552a..b506f899b4 100644 --- a/spec/ruby/core/array/flatten_spec.rb +++ b/spec/ruby/core/array/flatten_spec.rb @@ -30,7 +30,7 @@ describe "Array#flatten" do it "raises a TypeError when the passed Object can't be converted to an Integer" do obj = mock("Not converted") - lambda { [ 1, 2, [3, [4, 5] ] ].flatten(obj) }.should raise_error(TypeError) + -> { [ 1, 2, [3, [4, 5] ] ].flatten(obj) }.should raise_error(TypeError) end it "does not call flatten on elements" do @@ -46,13 +46,13 @@ describe "Array#flatten" do it "raises an ArgumentError on recursive arrays" do x = [] x << x - lambda { x.flatten }.should raise_error(ArgumentError) + -> { x.flatten }.should raise_error(ArgumentError) x = [] y = [] x << y y << x - lambda { x.flatten }.should raise_error(ArgumentError) + -> { x.flatten }.should raise_error(ArgumentError) end it "flattens any element which responds to #to_ary, using the return value of said method" do @@ -106,7 +106,7 @@ describe "Array#flatten" do it "raises a TypeError if #to_ary does not return an Array" do @obj.should_receive(:to_ary).and_return(1) - lambda { [@obj].flatten }.should raise_error(TypeError) + -> { [@obj].flatten }.should raise_error(TypeError) end ruby_version_is ""..."2.5" do @@ -135,7 +135,7 @@ describe "Array#flatten" do it "calls #to_ary if not defined when #respond_to_missing? returns true" do def @obj.respond_to_missing?(name, priv) ScratchPad << name; true end - lambda { [@obj].flatten }.should raise_error(NoMethodError) + -> { [@obj].flatten }.should raise_error(NoMethodError) ScratchPad.recorded.should == [:to_ary] end @@ -226,7 +226,7 @@ describe "Array#flatten!" do it "raises a TypeError when the passed Object can't be converted to an Integer" do obj = mock("Not converted") - lambda { [ 1, 2, [3, [4, 5] ] ].flatten!(obj) }.should raise_error(TypeError) + -> { [ 1, 2, [3, [4, 5] ] ].flatten!(obj) }.should raise_error(TypeError) end it "does not call flatten! on elements" do @@ -242,13 +242,13 @@ describe "Array#flatten!" do it "raises an ArgumentError on recursive arrays" do x = [] x << x - lambda { x.flatten! }.should raise_error(ArgumentError) + -> { x.flatten! }.should raise_error(ArgumentError) x = [] y = [] x << y y << x - lambda { x.flatten! }.should raise_error(ArgumentError) + -> { x.flatten! }.should raise_error(ArgumentError) end it "flattens any elements which responds to #to_ary, using the return value of said method" do @@ -273,12 +273,12 @@ describe "Array#flatten!" do it "raises a #{frozen_error_class} on frozen arrays when the array is modified" do nested_ary = [1, 2, []] nested_ary.freeze - lambda { nested_ary.flatten! }.should raise_error(frozen_error_class) + -> { nested_ary.flatten! }.should raise_error(frozen_error_class) end # see [ruby-core:23663] it "raises a #{frozen_error_class} on frozen arrays when the array would not be modified" do - lambda { ArraySpecs.frozen_array.flatten! }.should raise_error(frozen_error_class) - lambda { ArraySpecs.empty_frozen_array.flatten! }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.flatten! }.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.flatten! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/hash_spec.rb b/spec/ruby/core/array/hash_spec.rb index 638acff12b..8392253ae4 100644 --- a/spec/ruby/core/array/hash_spec.rb +++ b/spec/ruby/core/array/hash_spec.rb @@ -13,10 +13,10 @@ describe "Array#hash" do it "properly handles recursive arrays" do empty = ArraySpecs.empty_recursive_array - lambda { empty.hash }.should_not raise_error + -> { empty.hash }.should_not raise_error array = ArraySpecs.recursive_array - lambda { array.hash }.should_not raise_error + -> { array.hash }.should_not raise_error end it "returns the same hash for equal recursive arrays" do diff --git a/spec/ruby/core/array/initialize_spec.rb b/spec/ruby/core/array/initialize_spec.rb index 350538a222..dfc2ae3518 100644 --- a/spec/ruby/core/array/initialize_spec.rb +++ b/spec/ruby/core/array/initialize_spec.rb @@ -24,19 +24,19 @@ describe "Array#initialize" do end it "raises an ArgumentError if passed 3 or more arguments" do - lambda do + -> do [1, 2].send :initialize, 1, 'x', true end.should raise_error(ArgumentError) - lambda do + -> do [1, 2].send(:initialize, 1, 'x', true) {} end.should raise_error(ArgumentError) end it "raises a #{frozen_error_class} on frozen arrays" do - lambda do + -> do ArraySpecs.frozen_array.send :initialize end.should raise_error(frozen_error_class) - lambda do + -> do ArraySpecs.frozen_array.send :initialize, ArraySpecs.frozen_array end.should raise_error(frozen_error_class) end @@ -53,7 +53,7 @@ describe "Array#initialize with no arguments" do end it "does not use the given block" do - lambda{ [1, 2, 3].send(:initialize) { raise } }.should_not raise_error + ->{ [1, 2, 3].send(:initialize) { raise } }.should_not raise_error end end @@ -64,7 +64,7 @@ describe "Array#initialize with (array)" do end it "does not use the given block" do - lambda{ [1, 2, 3].send(:initialize) { raise } }.should_not raise_error + ->{ [1, 2, 3].send(:initialize) { raise } }.should_not raise_error end it "calls #to_ary to convert the value to an array" do @@ -81,7 +81,7 @@ describe "Array#initialize with (array)" do end it "raises a TypeError if an Array type argument and a default object" do - lambda { [].send(:initialize, [1, 2], 1) }.should raise_error(TypeError) + -> { [].send(:initialize, [1, 2], 1) }.should raise_error(TypeError) end end @@ -103,12 +103,12 @@ describe "Array#initialize with (size, object=nil)" do end it "raises an ArgumentError if size is negative" do - lambda { [].send(:initialize, -1, :a) }.should raise_error(ArgumentError) - lambda { [].send(:initialize, -1) }.should raise_error(ArgumentError) + -> { [].send(:initialize, -1, :a) }.should raise_error(ArgumentError) + -> { [].send(:initialize, -1) }.should raise_error(ArgumentError) end it "raises an ArgumentError if size is too large" do - lambda { [].send(:initialize, fixnum_max+1) }.should raise_error(ArgumentError) + -> { [].send(:initialize, fixnum_max+1) }.should raise_error(ArgumentError) end it "calls #to_int to convert the size argument to an Integer when object is given" do @@ -126,7 +126,7 @@ describe "Array#initialize with (size, object=nil)" do it "raises a TypeError if the size argument is not an Integer type" do obj = mock('nonnumeric') obj.stub!(:to_ary).and_return([1, 2]) - lambda{ [].send(:initialize, obj, :a) }.should raise_error(TypeError) + ->{ [].send(:initialize, obj, :a) }.should raise_error(TypeError) end it "yields the index of the element and sets the element to the value of the block" do @@ -134,7 +134,7 @@ describe "Array#initialize with (size, object=nil)" do end it "uses the block value instead of using the default value" do - lambda { + -> { @result = [].send(:initialize, 3, :obj) { |i| i.to_s } }.should complain(/block supersedes default value argument/) @result.should == ['0', '1', '2'] diff --git a/spec/ruby/core/array/insert_spec.rb b/spec/ruby/core/array/insert_spec.rb index b65a14a6b7..7577a8f743 100644 --- a/spec/ruby/core/array/insert_spec.rb +++ b/spec/ruby/core/array/insert_spec.rb @@ -46,8 +46,8 @@ describe "Array#insert" do end it "raises an IndexError if the negative index is out of bounds" do - lambda { [].insert(-2, 1) }.should raise_error(IndexError) - lambda { [1].insert(-3, 2) }.should raise_error(IndexError) + -> { [].insert(-2, 1) }.should raise_error(IndexError) + -> { [1].insert(-3, 2) }.should raise_error(IndexError) end it "does nothing of no object is passed" do @@ -64,15 +64,15 @@ describe "Array#insert" do end it "raises an ArgumentError if no argument passed" do - lambda { [].insert() }.should raise_error(ArgumentError) + -> { [].insert() }.should raise_error(ArgumentError) end it "raises a #{frozen_error_class} on frozen arrays when the array is modified" do - lambda { ArraySpecs.frozen_array.insert(0, 'x') }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.insert(0, 'x') }.should raise_error(frozen_error_class) end # see [ruby-core:23666] it "raises a #{frozen_error_class} on frozen arrays when the array would not be modified" do - lambda { ArraySpecs.frozen_array.insert(0) }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.insert(0) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/join_spec.rb b/spec/ruby/core/array/join_spec.rb index 403bae7183..e78ea6f9e1 100644 --- a/spec/ruby/core/array/join_spec.rb +++ b/spec/ruby/core/array/join_spec.rb @@ -24,11 +24,11 @@ describe "Array#join" do it "raises a TypeError if the separator cannot be coerced to a String by calling #to_str" do obj = mock("not a string") - lambda { [1, 2].join(obj) }.should raise_error(TypeError) + -> { [1, 2].join(obj) }.should raise_error(TypeError) end it "raises a TypeError if passed false as the separator" do - lambda { [1, 2].join(false) }.should raise_error(TypeError) + -> { [1, 2].join(false) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/array/last_spec.rb b/spec/ruby/core/array/last_spec.rb index 9bf8648776..d6fefada09 100644 --- a/spec/ruby/core/array/last_spec.rb +++ b/spec/ruby/core/array/last_spec.rb @@ -28,7 +28,7 @@ describe "Array#last" do end it "raises an ArgumentError when count is negative" do - lambda { [1, 2].last(-1) }.should raise_error(ArgumentError) + -> { [1, 2].last(-1) }.should raise_error(ArgumentError) end it "returns the entire array when count > length" do @@ -60,11 +60,11 @@ describe "Array#last" do end it "raises a TypeError if the passed argument is not numeric" do - lambda { [1,2].last(nil) }.should raise_error(TypeError) - lambda { [1,2].last("a") }.should raise_error(TypeError) + -> { [1,2].last(nil) }.should raise_error(TypeError) + -> { [1,2].last("a") }.should raise_error(TypeError) obj = mock("nonnumeric") - lambda { [1,2].last(obj) }.should raise_error(TypeError) + -> { [1,2].last(obj) }.should raise_error(TypeError) end it "does not return subclass instance on Array subclasses" do diff --git a/spec/ruby/core/array/max_spec.rb b/spec/ruby/core/array/max_spec.rb index 329b691883..d1c64519d0 100644 --- a/spec/ruby/core/array/max_spec.rb +++ b/spec/ruby/core/array/max_spec.rb @@ -68,16 +68,16 @@ describe "Array#max" do end it "raises a NoMethodError for elements without #<=>" do - lambda do + -> do [BasicObject.new, BasicObject.new].max end.should raise_error(NoMethodError) end it "raises an ArgumentError for incomparable elements" do - lambda do + -> do [11,"22"].max end.should raise_error(ArgumentError) - lambda do + -> do [11,12,22,33].max{|a, b| nil} end.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/array/min_spec.rb b/spec/ruby/core/array/min_spec.rb index 22a179d808..3bdef0dd00 100644 --- a/spec/ruby/core/array/min_spec.rb +++ b/spec/ruby/core/array/min_spec.rb @@ -68,16 +68,16 @@ describe "Array#min" do end it "raises a NoMethodError for elements without #<=>" do - lambda do + -> do [BasicObject.new, BasicObject.new].min end.should raise_error(NoMethodError) end it "raises an ArgumentError for incomparable elements" do - lambda do + -> do [11,"22"].min end.should raise_error(ArgumentError) - lambda do + -> do [11,12,22,33].min{|a, b| nil} end.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/array/multiply_spec.rb b/spec/ruby/core/array/multiply_spec.rb index f9ba20258a..ab654ce489 100644 --- a/spec/ruby/core/array/multiply_spec.rb +++ b/spec/ruby/core/array/multiply_spec.rb @@ -17,7 +17,7 @@ describe "Array#*" do it "raises a TypeError if the argument can neither be converted to a string nor an integer" do obj = mock('not a string or integer') - lambda{ [1,2] * obj }.should raise_error(TypeError) + ->{ [1,2] * obj }.should raise_error(TypeError) end it "converts the passed argument to a String rather than an Integer" do @@ -28,15 +28,15 @@ describe "Array#*" do end it "raises a TypeError is the passed argument is nil" do - lambda{ [1,2] * nil }.should raise_error(TypeError) + ->{ [1,2] * nil }.should raise_error(TypeError) end it "raises an ArgumentError when passed 2 or more arguments" do - lambda{ [1,2].send(:*, 1, 2) }.should raise_error(ArgumentError) + ->{ [1,2].send(:*, 1, 2) }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed no arguments" do - lambda{ [1,2].send(:*) }.should raise_error(ArgumentError) + ->{ [1,2].send(:*) }.should raise_error(ArgumentError) end end @@ -65,8 +65,8 @@ describe "Array#* with an integer" do end it "raises an ArgumentError when passed a negative integer" do - lambda { [ 1, 2, 3 ] * -1 }.should raise_error(ArgumentError) - lambda { [] * -1 }.should raise_error(ArgumentError) + -> { [ 1, 2, 3 ] * -1 }.should raise_error(ArgumentError) + -> { [] * -1 }.should raise_error(ArgumentError) end describe "with a subclass of Array" do diff --git a/spec/ruby/core/array/new_spec.rb b/spec/ruby/core/array/new_spec.rb index d5e4b5722f..96ec6b8198 100644 --- a/spec/ruby/core/array/new_spec.rb +++ b/spec/ruby/core/array/new_spec.rb @@ -11,10 +11,10 @@ describe "Array.new" do end it "raises an ArgumentError if passed 3 or more arguments" do - lambda do + -> do [1, 2].send :initialize, 1, 'x', true end.should raise_error(ArgumentError) - lambda do + -> do [1, 2].send(:initialize, 1, 'x', true) {} end.should raise_error(ArgumentError) end @@ -26,7 +26,7 @@ describe "Array.new with no arguments" do end it "does not use the given block" do - lambda{ Array.new { raise } }.should_not raise_error + ->{ Array.new { raise } }.should_not raise_error end end @@ -37,7 +37,7 @@ describe "Array.new with (array)" do end it "does not use the given block" do - lambda{ Array.new([1, 2]) { raise } }.should_not raise_error + ->{ Array.new([1, 2]) { raise } }.should_not raise_error end it "calls #to_ary to convert the value to an array" do @@ -54,7 +54,7 @@ describe "Array.new with (array)" do end it "raises a TypeError if an Array type argument and a default object" do - lambda { Array.new([1, 2], 1) }.should raise_error(TypeError) + -> { Array.new([1, 2], 1) }.should raise_error(TypeError) end end @@ -74,12 +74,12 @@ describe "Array.new with (size, object=nil)" do end it "raises an ArgumentError if size is negative" do - lambda { Array.new(-1, :a) }.should raise_error(ArgumentError) - lambda { Array.new(-1) }.should raise_error(ArgumentError) + -> { Array.new(-1, :a) }.should raise_error(ArgumentError) + -> { Array.new(-1) }.should raise_error(ArgumentError) end it "raises an ArgumentError if size is too large" do - lambda { Array.new(fixnum_max+1) }.should raise_error(ArgumentError) + -> { Array.new(fixnum_max+1) }.should raise_error(ArgumentError) end it "calls #to_int to convert the size argument to an Integer when object is given" do @@ -97,7 +97,7 @@ describe "Array.new with (size, object=nil)" do it "raises a TypeError if the size argument is not an Integer type" do obj = mock('nonnumeric') obj.stub!(:to_ary).and_return([1, 2]) - lambda{ Array.new(obj, :a) }.should raise_error(TypeError) + ->{ Array.new(obj, :a) }.should raise_error(TypeError) end it "yields the index of the element and sets the element to the value of the block" do @@ -105,7 +105,7 @@ describe "Array.new with (size, object=nil)" do end it "uses the block value instead of using the default value" do - lambda { + -> { @result = Array.new(3, :obj) { |i| i.to_s } }.should complain(/block supersedes default value argument/) @result.should == ['0', '1', '2'] diff --git a/spec/ruby/core/array/pack/buffer_spec.rb b/spec/ruby/core/array/pack/buffer_spec.rb index a3a582996a..ecb40bfd06 100644 --- a/spec/ruby/core/array/pack/buffer_spec.rb +++ b/spec/ruby/core/array/pack/buffer_spec.rb @@ -24,7 +24,7 @@ describe "Array#pack with :buffer option" do end it "raises TypeError exception if buffer is not String" do - lambda { [65].pack("ccc", buffer: []) }.should raise_error( + -> { [65].pack("ccc", buffer: []) }.should raise_error( TypeError, "buffer must be String, not Array") end diff --git a/spec/ruby/core/array/pack/m_spec.rb b/spec/ruby/core/array/pack/m_spec.rb index 40c2e3f1fa..2b1a84abca 100644 --- a/spec/ruby/core/array/pack/m_spec.rb +++ b/spec/ruby/core/array/pack/m_spec.rb @@ -285,16 +285,16 @@ describe "Array#pack with format 'm'" do it "raises a TypeError if #to_str does not return a String" do obj = mock("pack m non-string") - lambda { [obj].pack("m") }.should raise_error(TypeError) + -> { [obj].pack("m") }.should raise_error(TypeError) end it "raises a TypeError if passed nil" do - lambda { [nil].pack("m") }.should raise_error(TypeError) + -> { [nil].pack("m") }.should raise_error(TypeError) end it "raises a TypeError if passed an Integer" do - lambda { [0].pack("m") }.should raise_error(TypeError) - lambda { [bignum_value].pack("m") }.should raise_error(TypeError) + -> { [0].pack("m") }.should raise_error(TypeError) + -> { [bignum_value].pack("m") }.should raise_error(TypeError) end it "does not emit a newline if passed zero as the count modifier" do diff --git a/spec/ruby/core/array/pack/percent_spec.rb b/spec/ruby/core/array/pack/percent_spec.rb index 3c0e7eca0f..5d56dea5fe 100644 --- a/spec/ruby/core/array/pack/percent_spec.rb +++ b/spec/ruby/core/array/pack/percent_spec.rb @@ -2,6 +2,6 @@ require_relative '../../../spec_helper' describe "Array#pack with format '%'" do it "raises an Argument Error" do - lambda { [1].pack("%") }.should raise_error(ArgumentError) + -> { [1].pack("%") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/array/pack/shared/basic.rb b/spec/ruby/core/array/pack/shared/basic.rb index 39ab15308d..bc366987c8 100644 --- a/spec/ruby/core/array/pack/shared/basic.rb +++ b/spec/ruby/core/array/pack/shared/basic.rb @@ -1,6 +1,6 @@ describe :array_pack_arguments, shared: true do it "raises an ArgumentError if there are fewer elements than the format requires" do - lambda { [].pack(pack_format(1)) }.should raise_error(ArgumentError) + -> { [].pack(pack_format(1)) }.should raise_error(ArgumentError) end end @@ -10,11 +10,11 @@ describe :array_pack_basic, shared: true do end it "raises a TypeError when passed nil" do - lambda { [@obj].pack(nil) }.should raise_error(TypeError) + -> { [@obj].pack(nil) }.should raise_error(TypeError) end it "raises a TypeError when passed an Integer" do - lambda { [@obj].pack(1) }.should raise_error(TypeError) + -> { [@obj].pack(1) }.should raise_error(TypeError) end end @@ -56,10 +56,10 @@ end describe :array_pack_no_platform, shared: true do it "raises ArgumentError when the format modifier is '_'" do - lambda{ [1].pack(pack_format("_")) }.should raise_error(ArgumentError) + ->{ [1].pack(pack_format("_")) }.should raise_error(ArgumentError) end it "raises ArgumentError when the format modifier is '!'" do - lambda{ [1].pack(pack_format("!")) }.should raise_error(ArgumentError) + ->{ [1].pack(pack_format("!")) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/array/pack/shared/encodings.rb b/spec/ruby/core/array/pack/shared/encodings.rb index 3724a5d859..6b7ffac764 100644 --- a/spec/ruby/core/array/pack/shared/encodings.rb +++ b/spec/ruby/core/array/pack/shared/encodings.rb @@ -5,12 +5,12 @@ describe :array_pack_hex, shared: true do it "raises a TypeError if the object does not respond to #to_str" do obj = mock("pack hex non-string") - lambda { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should raise_error(TypeError) end it "raises a TypeError if #to_str does not return a String" do obj = mock("pack hex non-string") obj.should_receive(:to_str).and_return(1) - lambda { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/array/pack/shared/float.rb b/spec/ruby/core/array/pack/shared/float.rb index 6cd326ce9c..c6b194007f 100644 --- a/spec/ruby/core/array/pack/shared/float.rb +++ b/spec/ruby/core/array/pack/shared/float.rb @@ -14,7 +14,7 @@ describe :array_pack_float_le, shared: true do end it "raises a TypeError if passed a String representation of a floating point number" do - lambda { ["13"].pack(pack_format) }.should raise_error(TypeError) + -> { ["13"].pack(pack_format) }.should raise_error(TypeError) end it "encodes the number of array elements specified by the count modifier" do @@ -69,7 +69,7 @@ describe :array_pack_float_be, shared: true do end it "raises a TypeError if passed a String representation of a floating point number" do - lambda { ["13"].pack(pack_format) }.should raise_error(TypeError) + -> { ["13"].pack(pack_format) }.should raise_error(TypeError) end it "encodes the number of array elements specified by the count modifier" do @@ -124,7 +124,7 @@ describe :array_pack_double_le, shared: true do end it "raises a TypeError if passed a String representation of a floating point number" do - lambda { ["13"].pack(pack_format) }.should raise_error(TypeError) + -> { ["13"].pack(pack_format) }.should raise_error(TypeError) end it "encodes the number of array elements specified by the count modifier" do @@ -183,7 +183,7 @@ describe :array_pack_double_be, shared: true do end it "raises a TypeError if passed a String representation of a floating point number" do - lambda { ["13"].pack(pack_format) }.should raise_error(TypeError) + -> { ["13"].pack(pack_format) }.should raise_error(TypeError) end it "encodes the number of array elements specified by the count modifier" do diff --git a/spec/ruby/core/array/pack/shared/numeric_basic.rb b/spec/ruby/core/array/pack/shared/numeric_basic.rb index 3ebdbc4c1a..7c36ba4a32 100644 --- a/spec/ruby/core/array/pack/shared/numeric_basic.rb +++ b/spec/ruby/core/array/pack/shared/numeric_basic.rb @@ -4,15 +4,15 @@ describe :array_pack_numeric_basic, shared: true do end it "raises a TypeError when passed nil" do - lambda { [nil].pack(pack_format) }.should raise_error(TypeError) + -> { [nil].pack(pack_format) }.should raise_error(TypeError) end it "raises a TypeError when passed true" do - lambda { [true].pack(pack_format) }.should raise_error(TypeError) + -> { [true].pack(pack_format) }.should raise_error(TypeError) end it "raises a TypeError when passed false" do - lambda { [false].pack(pack_format) }.should raise_error(TypeError) + -> { [false].pack(pack_format) }.should raise_error(TypeError) end it "returns a binary string" do @@ -24,21 +24,21 @@ end describe :array_pack_integer, shared: true do it "raises a TypeError when the object does not respond to #to_int" do obj = mock('not an integer') - lambda { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { ["5"].pack(pack_format) }.should raise_error(TypeError) + -> { ["5"].pack(pack_format) }.should raise_error(TypeError) end end describe :array_pack_float, shared: true do it "raises a TypeError if a String does not represent a floating point number" do - lambda { ["a"].pack(pack_format) }.should raise_error(TypeError) + -> { ["a"].pack(pack_format) }.should raise_error(TypeError) end it "raises a TypeError when the object does not respond to #to_f" do obj = mock('not an float') - lambda { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/array/pack/shared/string.rb b/spec/ruby/core/array/pack/shared/string.rb index 98e8c4d562..8c82e8c617 100644 --- a/spec/ruby/core/array/pack/shared/string.rb +++ b/spec/ruby/core/array/pack/shared/string.rb @@ -17,11 +17,11 @@ describe :array_pack_string, shared: true do end it "raises an ArgumentError when the Array is empty" do - lambda { [].pack(pack_format) }.should raise_error(ArgumentError) + -> { [].pack(pack_format) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the Array has too few elements" do - lambda { ["a"].pack(pack_format(nil, 2)) }.should raise_error(ArgumentError) + -> { ["a"].pack(pack_format(nil, 2)) }.should raise_error(ArgumentError) end it "calls #to_str to convert the element to a String" do @@ -33,7 +33,7 @@ describe :array_pack_string, shared: true do it "raises a TypeError when the object does not respond to #to_str" do obj = mock("not a string") - lambda { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should raise_error(TypeError) end it "returns a string in encoding of common to the concatenated results" do diff --git a/spec/ruby/core/array/pack/shared/unicode.rb b/spec/ruby/core/array/pack/shared/unicode.rb index e16110c491..dd0f8b38aa 100644 --- a/spec/ruby/core/array/pack/shared/unicode.rb +++ b/spec/ruby/core/array/pack/shared/unicode.rb @@ -64,7 +64,7 @@ describe :array_pack_unicode, shared: true do it "raises a TypeError if #to_int does not return an Integer" do obj = mock('to_int') obj.should_receive(:to_int).and_return("5") - lambda { [obj].pack("U") }.should raise_error(TypeError) + -> { [obj].pack("U") }.should raise_error(TypeError) end it "ignores NULL bytes between directives" do @@ -76,11 +76,11 @@ describe :array_pack_unicode, shared: true do end it "raises a RangeError if passed a negative number" do - lambda { [-1].pack("U") }.should raise_error(RangeError) + -> { [-1].pack("U") }.should raise_error(RangeError) end it "raises a RangeError if passed a number larger than an unsigned 32-bit integer" do - lambda { [2**32].pack("U") }.should raise_error(RangeError) + -> { [2**32].pack("U") }.should raise_error(RangeError) end it "sets the output string to UTF-8 encoding" do diff --git a/spec/ruby/core/array/pack/u_spec.rb b/spec/ruby/core/array/pack/u_spec.rb index 8c3eb3a177..fe969cbb2d 100644 --- a/spec/ruby/core/array/pack/u_spec.rb +++ b/spec/ruby/core/array/pack/u_spec.rb @@ -112,16 +112,16 @@ describe "Array#pack with format 'u'" do it "raises a TypeError if #to_str does not return a String" do obj = mock("pack m non-string") - lambda { [obj].pack("u") }.should raise_error(TypeError) + -> { [obj].pack("u") }.should raise_error(TypeError) end it "raises a TypeError if passed nil" do - lambda { [nil].pack("u") }.should raise_error(TypeError) + -> { [nil].pack("u") }.should raise_error(TypeError) end it "raises a TypeError if passed an Integer" do - lambda { [0].pack("u") }.should raise_error(TypeError) - lambda { [bignum_value].pack("u") }.should raise_error(TypeError) + -> { [0].pack("u") }.should raise_error(TypeError) + -> { [bignum_value].pack("u") }.should raise_error(TypeError) end it "sets the output string to US-ASCII encoding" do diff --git a/spec/ruby/core/array/pack/w_spec.rb b/spec/ruby/core/array/pack/w_spec.rb index 889f42bdf7..439fa02198 100644 --- a/spec/ruby/core/array/pack/w_spec.rb +++ b/spec/ruby/core/array/pack/w_spec.rb @@ -33,7 +33,7 @@ describe "Array#pack with format 'w'" do end it "raises an ArgumentError when passed a negative value" do - lambda { [-1].pack("w") }.should raise_error(ArgumentError) + -> { [-1].pack("w") }.should raise_error(ArgumentError) end it "returns a binary string" do diff --git a/spec/ruby/core/array/pack/x_spec.rb b/spec/ruby/core/array/pack/x_spec.rb index 2662873d03..a28dd0bf21 100644 --- a/spec/ruby/core/array/pack/x_spec.rb +++ b/spec/ruby/core/array/pack/x_spec.rb @@ -55,10 +55,10 @@ describe "Array#pack with format 'X'" do end it "raises an ArgumentError if the output string is empty" do - lambda { [1, 2, 3].pack("XC") }.should raise_error(ArgumentError) + -> { [1, 2, 3].pack("XC") }.should raise_error(ArgumentError) end it "raises an ArgumentError if the count modifier is greater than the bytes in the string" do - lambda { [1, 2, 3].pack("C2X3") }.should raise_error(ArgumentError) + -> { [1, 2, 3].pack("C2X3") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/array/pop_spec.rb b/spec/ruby/core/array/pop_spec.rb index 335a0f2b60..7dbd6cb3cc 100644 --- a/spec/ruby/core/array/pop_spec.rb +++ b/spec/ruby/core/array/pop_spec.rb @@ -39,11 +39,11 @@ describe "Array#pop" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.pop }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.pop }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.pop }.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.pop }.should raise_error(frozen_error_class) end it "keeps untrusted status" do @@ -105,7 +105,7 @@ describe "Array#pop" do end it "raises an ArgumentError if n is negative" do - lambda{ [1, 2, 3].pop(-1) }.should raise_error(ArgumentError) + ->{ [1, 2, 3].pop(-1) }.should raise_error(ArgumentError) end it "tries to convert n to an Integer using #to_int" do @@ -120,12 +120,12 @@ describe "Array#pop" do end it "raises a TypeError when the passed n cannot be coerced to Integer" do - lambda{ [1, 2].pop("cat") }.should raise_error(TypeError) - lambda{ [1, 2].pop(nil) }.should raise_error(TypeError) + ->{ [1, 2].pop("cat") }.should raise_error(TypeError) + ->{ [1, 2].pop(nil) }.should raise_error(TypeError) end it "raises an ArgumentError if more arguments are passed" do - lambda{ [1, 2].pop(1, 2) }.should raise_error(ArgumentError) + ->{ [1, 2].pop(1, 2) }.should raise_error(ArgumentError) end it "does not return subclass instances with Array subclass" do @@ -153,8 +153,8 @@ describe "Array#pop" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.pop(2) }.should raise_error(frozen_error_class) - lambda { ArraySpecs.frozen_array.pop(0) }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.pop(2) }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.pop(0) }.should raise_error(frozen_error_class) end it "keeps untrusted status" do diff --git a/spec/ruby/core/array/product_spec.rb b/spec/ruby/core/array/product_spec.rb index 7d810b6196..07d2880a96 100644 --- a/spec/ruby/core/array/product_spec.rb +++ b/spec/ruby/core/array/product_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe "Array#product" do it "returns converted arguments using :to_ary" do - lambda{ [1].product(2..3) }.should raise_error(TypeError) + ->{ [1].product(2..3) }.should raise_error(TypeError) ar = ArraySpecs::ArrayConvertible.new(2,3) [1].product(ar).should == [[1,2],[1,3]] ar.called.should == :to_ary @@ -24,7 +24,7 @@ describe "Array#product" do it "does not attempt to produce an unreasonable number of products" do a = (0..100).to_a - lambda do + -> do a.product(a, a, a, a, a, a, a, a, a, a) end.should raise_error(RangeError) end @@ -49,7 +49,7 @@ describe "Array#product" do it "will ignore unreasonable numbers of products and yield anyway" do a = (0..100).to_a - lambda do + -> do a.product(a, a, a, a, a, a, a, a, a, a) end.should raise_error(RangeError) end diff --git a/spec/ruby/core/array/reject_spec.rb b/spec/ruby/core/array/reject_spec.rb index 6ae2581ff5..1e9c296c8d 100644 --- a/spec/ruby/core/array/reject_spec.rb +++ b/spec/ruby/core/array/reject_spec.rb @@ -104,11 +104,11 @@ describe "Array#reject!" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.reject! {} }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.reject! {} }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(frozen_error_class) end it "does not truncate the array is the block raises an exception" do diff --git a/spec/ruby/core/array/reverse_spec.rb b/spec/ruby/core/array/reverse_spec.rb index d8ff26639d..e738be6fe7 100644 --- a/spec/ruby/core/array/reverse_spec.rb +++ b/spec/ruby/core/array/reverse_spec.rb @@ -37,6 +37,6 @@ describe "Array#reverse!" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.reverse! }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.reverse! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/rotate_spec.rb b/spec/ruby/core/array/rotate_spec.rb index 6450d3892b..cc1aabf986 100644 --- a/spec/ruby/core/array/rotate_spec.rb +++ b/spec/ruby/core/array/rotate_spec.rb @@ -27,10 +27,10 @@ describe "Array#rotate" do end it "raises a TypeError if not passed an integer-like argument" do - lambda { + -> { [1, 2].rotate(nil) }.should raise_error(TypeError) - lambda { + -> { [1, 2].rotate("4") }.should raise_error(TypeError) end @@ -46,7 +46,7 @@ describe "Array#rotate" do end it "does not mutate the receiver" do - lambda { + -> { [].freeze.rotate [2].freeze.rotate(2) [1,2,3].freeze.rotate(-3) @@ -94,10 +94,10 @@ describe "Array#rotate!" do end it "raises a TypeError if not passed an integer-like argument" do - lambda { + -> { [1, 2].rotate!(nil) }.should raise_error(TypeError) - lambda { + -> { [1, 2].rotate!("4") }.should raise_error(TypeError) end @@ -122,8 +122,8 @@ describe "Array#rotate!" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { [1, 2, 3].freeze.rotate!(0) }.should raise_error(frozen_error_class) - lambda { [1].freeze.rotate!(42) }.should raise_error(frozen_error_class) - lambda { [].freeze.rotate! }.should raise_error(frozen_error_class) + -> { [1, 2, 3].freeze.rotate!(0) }.should raise_error(frozen_error_class) + -> { [1].freeze.rotate!(42) }.should raise_error(frozen_error_class) + -> { [].freeze.rotate! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/sample_spec.rb b/spec/ruby/core/array/sample_spec.rb index 3bd5d046cc..44be91ba18 100644 --- a/spec/ruby/core/array/sample_spec.rb +++ b/spec/ruby/core/array/sample_spec.rb @@ -57,7 +57,7 @@ describe "Array#sample" do end it "raises ArgumentError when passed a negative count" do - lambda { [1, 2].sample(-1) }.should raise_error(ArgumentError) + -> { [1, 2].sample(-1) }.should raise_error(ArgumentError) end it "does not return subclass instances with Array subclass" do @@ -92,7 +92,7 @@ describe "Array#sample" do it "raises a NoMethodError if an object passed for the RNG does not define #rand" do obj = BasicObject.new - lambda { [1, 2].sample(random: obj) }.should raise_error(NoMethodError) + -> { [1, 2].sample(random: obj) }.should raise_error(NoMethodError) end describe "when the object returned by #rand is a Fixnum" do @@ -112,14 +112,14 @@ describe "Array#sample" do random = mock("array_sample_random") random.should_receive(:rand).and_return(-1) - lambda { [1, 2].sample(random: random) }.should raise_error(RangeError) + -> { [1, 2].sample(random: random) }.should raise_error(RangeError) end it "raises a RangeError if the value is equal to the Array size" do random = mock("array_sample_random") random.should_receive(:rand).and_return(2) - lambda { [1, 2].sample(random: random) }.should raise_error(RangeError) + -> { [1, 2].sample(random: random) }.should raise_error(RangeError) end end end @@ -140,7 +140,7 @@ describe "Array#sample" do random = mock("array_sample_random") random.should_receive(:rand).and_return(value) - lambda { [1, 2].sample(random: random) }.should raise_error(RangeError) + -> { [1, 2].sample(random: random) }.should raise_error(RangeError) end it "raises a RangeError if the value is equal to the Array size" do @@ -149,7 +149,7 @@ describe "Array#sample" do random = mock("array_sample_random") random.should_receive(:rand).and_return(value) - lambda { [1, 2].sample(random: random) }.should raise_error(RangeError) + -> { [1, 2].sample(random: random) }.should raise_error(RangeError) end end end diff --git a/spec/ruby/core/array/shared/collect.rb b/spec/ruby/core/array/shared/collect.rb index 8ad6e61855..80e2739893 100644 --- a/spec/ruby/core/array/shared/collect.rb +++ b/spec/ruby/core/array/shared/collect.rb @@ -37,7 +37,7 @@ describe :array_collect, shared: true do it "raises an ArgumentError when no block and with arguments" do a = [1, 2, 3] - lambda { + -> { a.send(@method, :foo) }.should raise_error(ArgumentError) end @@ -111,21 +111,21 @@ describe :array_collect_b, shared: true do describe "when frozen" do it "raises a #{frozen_error_class}" do - lambda { ArraySpecs.frozen_array.send(@method) {} }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.send(@method) {} }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} when empty" do - lambda { ArraySpecs.empty_frozen_array.send(@method) {} }.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.send(@method) {} }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} when calling #each on the returned Enumerator" do enumerator = ArraySpecs.frozen_array.send(@method) - lambda { enumerator.each {|x| x } }.should raise_error(frozen_error_class) + -> { enumerator.each {|x| x } }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} when calling #each on the returned Enumerator when empty" do enumerator = ArraySpecs.empty_frozen_array.send(@method) - lambda { enumerator.each {|x| x } }.should raise_error(frozen_error_class) + -> { enumerator.each {|x| x } }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/shared/difference.rb b/spec/ruby/core/array/shared/difference.rb index c43a6375e0..3e69050d82 100644 --- a/spec/ruby/core/array/shared/difference.rb +++ b/spec/ruby/core/array/shared/difference.rb @@ -27,7 +27,7 @@ describe :array_binary_difference, shared: true do it "raises a TypeError if the argument cannot be coerced to an Array by calling #to_ary" do obj = mock('not an array') - lambda { [1, 2, 3].send(@method, obj) }.should raise_error(TypeError) + -> { [1, 2, 3].send(@method, obj) }.should raise_error(TypeError) end it "does not return subclass instance for Array subclasses" do diff --git a/spec/ruby/core/array/shared/inspect.rb b/spec/ruby/core/array/shared/inspect.rb index 1bcc9f9ca8..434440c25b 100644 --- a/spec/ruby/core/array/shared/inspect.rb +++ b/spec/ruby/core/array/shared/inspect.rb @@ -55,7 +55,7 @@ describe :array_inspect, shared: true do obj.should_receive(:inspect).and_return(obj) obj.should_receive(:to_s).and_raise(Exception) - lambda { [obj].send(@method) }.should raise_error(Exception) + -> { [obj].send(@method) }.should raise_error(Exception) end it "represents a recursive element with '[...]'" do diff --git a/spec/ruby/core/array/shared/join.rb b/spec/ruby/core/array/shared/join.rb index 0d07e93b2c..38bdde9502 100644 --- a/spec/ruby/core/array/shared/join.rb +++ b/spec/ruby/core/array/shared/join.rb @@ -49,13 +49,13 @@ describe :array_join_with_default_separator, shared: true do it "raises a NoMethodError if an element does not respond to #to_str, #to_ary, or #to_s" do obj = mock('o') class << obj; undef :to_s; end - lambda { [1, obj].send(@method) }.should raise_error(NoMethodError) + -> { [1, obj].send(@method) }.should raise_error(NoMethodError) end it "raises an ArgumentError when the Array is recursive" do - lambda { ArraySpecs.recursive_array.send(@method) }.should raise_error(ArgumentError) - lambda { ArraySpecs.head_recursive_array.send(@method) }.should raise_error(ArgumentError) - lambda { ArraySpecs.empty_recursive_array.send(@method) }.should raise_error(ArgumentError) + -> { ArraySpecs.recursive_array.send(@method) }.should raise_error(ArgumentError) + -> { ArraySpecs.head_recursive_array.send(@method) }.should raise_error(ArgumentError) + -> { ArraySpecs.empty_recursive_array.send(@method) }.should raise_error(ArgumentError) end it "taints the result if the Array is tainted and non-empty" do @@ -109,7 +109,7 @@ describe :array_join_with_default_separator, shared: true do it "fails for arrays with incompatibly-encoded strings" do ary_utf8_bad_binary = ArraySpecs.array_with_utf8_and_binary_strings - lambda { ary_utf8_bad_binary.send(@method) }.should raise_error(EncodingError) + -> { ary_utf8_bad_binary.send(@method) }.should raise_error(EncodingError) end end diff --git a/spec/ruby/core/array/shared/keep_if.rb b/spec/ruby/core/array/shared/keep_if.rb index 906ad9b9e2..2f1299c2b3 100644 --- a/spec/ruby/core/array/shared/keep_if.rb +++ b/spec/ruby/core/array/shared/keep_if.rb @@ -37,23 +37,23 @@ describe :keep_if, shared: true do describe "with truthy block" do it "keeps elements after any exception" do - lambda { @frozen.send(@method) { true } }.should raise_error(Exception) + -> { @frozen.send(@method) { true } }.should raise_error(Exception) @frozen.should == @origin end it "raises a #{frozen_error_class}" do - lambda { @frozen.send(@method) { true } }.should raise_error(frozen_error_class) + -> { @frozen.send(@method) { true } }.should raise_error(frozen_error_class) end end describe "with falsy block" do it "keeps elements after any exception" do - lambda { @frozen.send(@method) { false } }.should raise_error(Exception) + -> { @frozen.send(@method) { false } }.should raise_error(Exception) @frozen.should == @origin end it "raises a #{frozen_error_class}" do - lambda { @frozen.send(@method) { false } }.should raise_error(frozen_error_class) + -> { @frozen.send(@method) { false } }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/array/shared/push.rb b/spec/ruby/core/array/shared/push.rb index effa632890..df307073cd 100644 --- a/spec/ruby/core/array/shared/push.rb +++ b/spec/ruby/core/array/shared/push.rb @@ -27,7 +27,7 @@ describe :array_push, shared: true do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.send(@method, 1) }.should raise_error(frozen_error_class) - lambda { ArraySpecs.frozen_array.send(@method) }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.send(@method, 1) }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.send(@method) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/shared/replace.rb b/spec/ruby/core/array/shared/replace.rb index b8dae8d33e..b3474fad09 100644 --- a/spec/ruby/core/array/shared/replace.rb +++ b/spec/ruby/core/array/shared/replace.rb @@ -53,7 +53,7 @@ describe :array_replace, shared: true do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { + -> { ArraySpecs.frozen_array.send(@method, ArraySpecs.frozen_array) }.should raise_error(frozen_error_class) end diff --git a/spec/ruby/core/array/shared/slice.rb b/spec/ruby/core/array/shared/slice.rb index b3f4ccb9a6..73456eb297 100644 --- a/spec/ruby/core/array/shared/slice.rb +++ b/spec/ruby/core/array/shared/slice.rb @@ -266,10 +266,10 @@ describe :array_slice, shared: true do a.send(@method, 1..0).should == [] a.send(@method, 1...0).should == [] - lambda { a.send(@method, "a" .. "b") }.should raise_error(TypeError) - lambda { a.send(@method, "a" ... "b") }.should raise_error(TypeError) - lambda { a.send(@method, from .. "b") }.should raise_error(TypeError) - lambda { a.send(@method, from ... "b") }.should raise_error(TypeError) + -> { a.send(@method, "a" .. "b") }.should raise_error(TypeError) + -> { a.send(@method, "a" ... "b") }.should raise_error(TypeError) + -> { a.send(@method, from .. "b") }.should raise_error(TypeError) + -> { a.send(@method, from ... "b") }.should raise_error(TypeError) end it "returns the same elements as [m..n] and [m...n] with Range subclasses" do @@ -441,19 +441,19 @@ describe :array_slice, shared: true do array = [1, 2, 3, 4, 5, 6] obj = mock('large value') obj.should_receive(:to_int).and_return(0x8000_0000_0000_0000_0000) - lambda { array.send(@method, obj) }.should raise_error(RangeError) + -> { array.send(@method, obj) }.should raise_error(RangeError) obj = 8e19 - lambda { array.send(@method, obj) }.should raise_error(RangeError) + -> { array.send(@method, obj) }.should raise_error(RangeError) end it "raises a RangeError when the length is out of range of Fixnum" do array = [1, 2, 3, 4, 5, 6] obj = mock('large value') obj.should_receive(:to_int).and_return(0x8000_0000_0000_0000_0000) - lambda { array.send(@method, 1, obj) }.should raise_error(RangeError) + -> { array.send(@method, 1, obj) }.should raise_error(RangeError) obj = 8e19 - lambda { array.send(@method, 1, obj) }.should raise_error(RangeError) + -> { array.send(@method, 1, obj) }.should raise_error(RangeError) end end diff --git a/spec/ruby/core/array/shared/unshift.rb b/spec/ruby/core/array/shared/unshift.rb index d7464cdaca..be62084e95 100644 --- a/spec/ruby/core/array/shared/unshift.rb +++ b/spec/ruby/core/array/shared/unshift.rb @@ -36,11 +36,11 @@ describe :array_unshift, shared: true do end it "raises a #{frozen_error_class} on a frozen array when the array is modified" do - lambda { ArraySpecs.frozen_array.send(@method, 1) }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.send(@method, 1) }.should raise_error(frozen_error_class) end # see [ruby-core:23666] it "raises a #{frozen_error_class} on a frozen array when the array would not be modified" do - lambda { ArraySpecs.frozen_array.send(@method) }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.send(@method) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/shift_spec.rb b/spec/ruby/core/array/shift_spec.rb index 26bce8aeb3..ef3c9fe1cd 100644 --- a/spec/ruby/core/array/shift_spec.rb +++ b/spec/ruby/core/array/shift_spec.rb @@ -31,10 +31,10 @@ describe "Array#shift" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.shift }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.shift }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.shift }.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.shift }.should raise_error(frozen_error_class) end describe "passed a number n as an argument" do @@ -90,7 +90,7 @@ describe "Array#shift" do end it "raises an ArgumentError if n is negative" do - lambda{ [1, 2, 3].shift(-1) }.should raise_error(ArgumentError) + ->{ [1, 2, 3].shift(-1) }.should raise_error(ArgumentError) end it "tries to convert n to an Integer using #to_int" do @@ -105,12 +105,12 @@ describe "Array#shift" do end it "raises a TypeError when the passed n cannot be coerced to Integer" do - lambda{ [1, 2].shift("cat") }.should raise_error(TypeError) - lambda{ [1, 2].shift(nil) }.should raise_error(TypeError) + ->{ [1, 2].shift("cat") }.should raise_error(TypeError) + ->{ [1, 2].shift(nil) }.should raise_error(TypeError) end it "raises an ArgumentError if more arguments are passed" do - lambda{ [1, 2].shift(1, 2) }.should raise_error(ArgumentError) + ->{ [1, 2].shift(1, 2) }.should raise_error(ArgumentError) end it "does not return subclass instances with Array subclass" do diff --git a/spec/ruby/core/array/shuffle_spec.rb b/spec/ruby/core/array/shuffle_spec.rb index 4f793acf19..7a2fed7d50 100644 --- a/spec/ruby/core/array/shuffle_spec.rb +++ b/spec/ruby/core/array/shuffle_spec.rb @@ -43,7 +43,7 @@ describe "Array#shuffle" do it "raises a NoMethodError if an object passed for the RNG does not define #rand" do obj = BasicObject.new - lambda { [1, 2].shuffle(random: obj) }.should raise_error(NoMethodError) + -> { [1, 2].shuffle(random: obj) }.should raise_error(NoMethodError) end it "accepts a Float for the value returned by #rand" do @@ -68,7 +68,7 @@ describe "Array#shuffle" do random = mock("array_shuffle_random") random.should_receive(:rand).and_return(value) - lambda { [1, 2].shuffle(random: random) }.should raise_error(RangeError) + -> { [1, 2].shuffle(random: random) }.should raise_error(RangeError) end it "raises a RangeError if the value is equal to one" do @@ -77,7 +77,7 @@ describe "Array#shuffle" do random = mock("array_shuffle_random") random.should_receive(:rand).at_least(1).times.and_return(value) - lambda { [1, 2].shuffle(random: random) }.should raise_error(RangeError) + -> { [1, 2].shuffle(random: random) }.should raise_error(RangeError) end end @@ -96,7 +96,7 @@ describe "Array#shuffle!" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.shuffle! }.should raise_error(frozen_error_class) - lambda { ArraySpecs.empty_frozen_array.shuffle! }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.shuffle! }.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.shuffle! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/slice_spec.rb b/spec/ruby/core/array/slice_spec.rb index cd16b3892c..16220bdf0d 100644 --- a/spec/ruby/core/array/slice_spec.rb +++ b/spec/ruby/core/array/slice_spec.rb @@ -116,8 +116,8 @@ describe "Array#slice!" do a.slice!(from .. to).should == [2, 3, 4] a.should == [1, 5] - lambda { a.slice!("a" .. "b") }.should raise_error(TypeError) - lambda { a.slice!(from .. "b") }.should raise_error(TypeError) + -> { a.slice!("a" .. "b") }.should raise_error(TypeError) + -> { a.slice!(from .. "b") }.should raise_error(TypeError) end it "returns last element for consecutive calls at zero index" do @@ -151,7 +151,7 @@ describe "Array#slice!" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.slice!(0, 0) }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.slice!(0, 0) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/array/sort_by_spec.rb b/spec/ruby/core/array/sort_by_spec.rb index 6428194dfb..045051d307 100644 --- a/spec/ruby/core/array/sort_by_spec.rb +++ b/spec/ruby/core/array/sort_by_spec.rb @@ -24,11 +24,11 @@ describe "Array#sort_by!" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.sort_by! {}}.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.sort_by! {}}.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} on an empty frozen array" do - lambda { ArraySpecs.empty_frozen_array.sort_by! {}}.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.sort_by! {}}.should raise_error(frozen_error_class) end it "returns the specified value when it would break in the given block" do diff --git a/spec/ruby/core/array/sort_spec.rb b/spec/ruby/core/array/sort_spec.rb index c0d6628549..6b84a82a48 100644 --- a/spec/ruby/core/array/sort_spec.rb +++ b/spec/ruby/core/array/sort_spec.rb @@ -66,7 +66,7 @@ describe "Array#sort" do it "does not deal with exceptions raised by unimplemented or incorrect #<=>" do o = Object.new - lambda { + -> { [o, 1].sort }.should raise_error(ArgumentError) end @@ -78,7 +78,7 @@ describe "Array#sort" do end it "raises an error when a given block returns nil" do - lambda { [1, 2].sort {} }.should raise_error(ArgumentError) + -> { [1, 2].sort {} }.should raise_error(ArgumentError) end it "does not call #<=> on contained objects when invoked with a block" do @@ -134,7 +134,7 @@ describe "Array#sort" do a.sort { |n, m| ArraySpecs::ComparableWithFixnum.new(n-m) }.should == [-4, 1, 2, 5, 7, 10, 12] - lambda { + -> { a.sort { |n, m| (n - m).to_s } }.should raise_error(ArgumentError) end @@ -155,7 +155,7 @@ describe "Array#sort" do it "raises an error if objects can't be compared" do a=[ArraySpecs::Uncomparable.new, ArraySpecs::Uncomparable.new] - lambda {a.sort}.should raise_error(ArgumentError) + -> {a.sort}.should raise_error(ArgumentError) end # From a strange Rubinius bug @@ -234,7 +234,7 @@ describe "Array#sort!" do end it "raises a #{frozen_error_class} on a frozen array" do - lambda { ArraySpecs.frozen_array.sort! }.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.sort! }.should raise_error(frozen_error_class) end it "returns the specified value when it would break in the given block" do diff --git a/spec/ruby/core/array/sum_spec.rb b/spec/ruby/core/array/sum_spec.rb index a7e77d8c2e..39c769d328 100644 --- a/spec/ruby/core/array/sum_spec.rb +++ b/spec/ruby/core/array/sum_spec.rb @@ -26,11 +26,11 @@ describe "Array#sum" do end it 'raises TypeError if any element are not numeric' do - lambda { ["a"].sum }.should raise_error(TypeError) + -> { ["a"].sum }.should raise_error(TypeError) end it 'raises TypeError if any element cannot be added to init value' do - lambda { [1].sum([]) }.should raise_error(TypeError) + -> { [1].sum([]) }.should raise_error(TypeError) end it "calls + to sum the elements" do diff --git a/spec/ruby/core/array/take_spec.rb b/spec/ruby/core/array/take_spec.rb index 2c9e3f5cfe..0de99b0a7e 100644 --- a/spec/ruby/core/array/take_spec.rb +++ b/spec/ruby/core/array/take_spec.rb @@ -22,6 +22,6 @@ describe "Array#take" do end it "raises an ArgumentError when the argument is negative" do - lambda{ [1].take(-3) }.should raise_error(ArgumentError) + ->{ [1].take(-3) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/array/to_h_spec.rb b/spec/ruby/core/array/to_h_spec.rb index 4431430216..46a79ba58b 100644 --- a/spec/ruby/core/array/to_h_spec.rb +++ b/spec/ruby/core/array/to_h_spec.rb @@ -24,15 +24,15 @@ describe "Array#to_h" do end it "raises TypeError if an element is not an array" do - lambda { [:x].to_h }.should raise_error(TypeError) + -> { [:x].to_h }.should raise_error(TypeError) end it "raises ArgumentError if an element is not a [key, value] pair" do - lambda { [[:x]].to_h }.should raise_error(ArgumentError) + -> { [[:x]].to_h }.should raise_error(ArgumentError) end it "does not accept arguments" do - lambda { [].to_h(:a, :b) }.should raise_error(ArgumentError) + -> { [].to_h(:a, :b) }.should raise_error(ArgumentError) end it "produces a hash that returns nil for a missing element" do diff --git a/spec/ruby/core/array/transpose_spec.rb b/spec/ruby/core/array/transpose_spec.rb index c7bd7e7338..b39077f4c9 100644 --- a/spec/ruby/core/array/transpose_spec.rb +++ b/spec/ruby/core/array/transpose_spec.rb @@ -32,7 +32,7 @@ describe "Array#transpose" do end it "raises a TypeError if the passed Argument does not respond to #to_ary" do - lambda { [Object.new, [:a, :b]].transpose }.should raise_error(TypeError) + -> { [Object.new, [:a, :b]].transpose }.should raise_error(TypeError) end it "does not call to_ary on array subclass elements" do @@ -41,7 +41,7 @@ describe "Array#transpose" do end it "raises an IndexError if the arrays are not of the same length" do - lambda { [[1, 2], [:a]].transpose }.should raise_error(IndexError) + -> { [[1, 2], [:a]].transpose }.should raise_error(IndexError) end it "does not return subclass instance on Array subclasses" do diff --git a/spec/ruby/core/array/try_convert_spec.rb b/spec/ruby/core/array/try_convert_spec.rb index 5f653b6807..47b4722d80 100644 --- a/spec/ruby/core/array/try_convert_spec.rb +++ b/spec/ruby/core/array/try_convert_spec.rb @@ -39,12 +39,12 @@ describe "Array.try_convert" do it "sends #to_ary to the argument and raises TypeError if it's not a kind of Array" do obj = mock("to_ary") obj.should_receive(:to_ary).and_return(Object.new) - lambda { Array.try_convert obj }.should raise_error(TypeError) + -> { Array.try_convert obj }.should raise_error(TypeError) end it "does not rescue exceptions raised by #to_ary" do obj = mock("to_ary") obj.should_receive(:to_ary).and_raise(RuntimeError) - lambda { Array.try_convert obj }.should raise_error(RuntimeError) + -> { Array.try_convert obj }.should raise_error(RuntimeError) end end diff --git a/spec/ruby/core/array/uniq_spec.rb b/spec/ruby/core/array/uniq_spec.rb index 471717b8e2..c9bdd3dacd 100644 --- a/spec/ruby/core/array/uniq_spec.rb +++ b/spec/ruby/core/array/uniq_spec.rb @@ -191,17 +191,17 @@ describe "Array#uniq!" do it "raises a #{frozen_error_class} on a frozen array when the array is modified" do dup_ary = [1, 1, 2] dup_ary.freeze - lambda { dup_ary.uniq! }.should raise_error(frozen_error_class) + -> { dup_ary.uniq! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] it "raises a #{frozen_error_class} on a frozen array when the array would not be modified" do - lambda { ArraySpecs.frozen_array.uniq!}.should raise_error(frozen_error_class) - lambda { ArraySpecs.empty_frozen_array.uniq!}.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.uniq!}.should raise_error(frozen_error_class) + -> { ArraySpecs.empty_frozen_array.uniq!}.should raise_error(frozen_error_class) end it "doesn't yield to the block on a frozen array" do - lambda { ArraySpecs.frozen_array.uniq!{ raise RangeError, "shouldn't yield"}}.should raise_error(frozen_error_class) + -> { ArraySpecs.frozen_array.uniq!{ raise RangeError, "shouldn't yield"}}.should raise_error(frozen_error_class) end it "compares elements based on the value returned from the block" do diff --git a/spec/ruby/core/basicobject/basicobject_spec.rb b/spec/ruby/core/basicobject/basicobject_spec.rb index ccaa9c8593..27a322e72c 100644 --- a/spec/ruby/core/basicobject/basicobject_spec.rb +++ b/spec/ruby/core/basicobject/basicobject_spec.rb @@ -8,7 +8,7 @@ describe "BasicObject" do end it "raises NameError when referencing built-in constants" do - lambda { class BasicObjectSpecs::BOSubclass; Kernel; end }.should raise_error(NameError) + -> { class BasicObjectSpecs::BOSubclass; Kernel; end }.should raise_error(NameError) end it "does not define built-in constants (according to const_defined?)" do @@ -85,7 +85,7 @@ describe "BasicObject subclass" do describe "BasicObject references" do it "can refer to BasicObject from within itself" do - lambda { BasicObject::BasicObject }.should_not raise_error + -> { BasicObject::BasicObject }.should_not raise_error end end end diff --git a/spec/ruby/core/basicobject/initialize_spec.rb b/spec/ruby/core/basicobject/initialize_spec.rb index 0266496856..b7ce73ffd5 100644 --- a/spec/ruby/core/basicobject/initialize_spec.rb +++ b/spec/ruby/core/basicobject/initialize_spec.rb @@ -6,7 +6,7 @@ describe "BasicObject#initialize" do end it "does not accept arguments" do - lambda { + -> { BasicObject.new("This", "makes it easier", "to call super", "from other constructors") }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/basicobject/instance_eval_spec.rb b/spec/ruby/core/basicobject/instance_eval_spec.rb index 24b4d6dc69..d3dd05b745 100644 --- a/spec/ruby/core/basicobject/instance_eval_spec.rb +++ b/spec/ruby/core/basicobject/instance_eval_spec.rb @@ -21,11 +21,11 @@ describe "BasicObject#instance_eval" do end it "expects a block with no arguments" do - lambda { "hola".instance_eval }.should raise_error(ArgumentError) + -> { "hola".instance_eval }.should raise_error(ArgumentError) end it "takes no arguments with a block" do - lambda { "hola".instance_eval(4, 5) {|a,b| a + b } }.should raise_error(ArgumentError) + -> { "hola".instance_eval(4, 5) {|a,b| a + b } }.should raise_error(ArgumentError) end it "yields the object to the block" do @@ -45,7 +45,7 @@ describe "BasicObject#instance_eval" do end end f.foo.should == 1 - lambda { Object.new.foo }.should raise_error(NoMethodError) + -> { Object.new.foo }.should raise_error(NoMethodError) end it "preserves self in the original block when passed a block argument" do @@ -122,10 +122,10 @@ describe "BasicObject#instance_eval" do end it "raises a TypeError when defining methods on an immediate" do - lambda do + -> do 1.instance_eval { def foo; end } end.should raise_error(TypeError) - lambda do + -> do :foo.instance_eval { def foo; end } end.should raise_error(TypeError) end @@ -143,10 +143,10 @@ quarantine! do # Not clean, leaves cvars lying around to break other specs end it "raises a TypeError when defining methods on numerics" do - lambda do + -> do (1.0).instance_eval { def foo; end } end.should raise_error(TypeError) - lambda do + -> do (1 << 64).instance_eval { def foo; end } end.should raise_error(TypeError) end diff --git a/spec/ruby/core/basicobject/instance_exec_spec.rb b/spec/ruby/core/basicobject/instance_exec_spec.rb index 33c6b5a1d3..e25482d58a 100644 --- a/spec/ruby/core/basicobject/instance_exec_spec.rb +++ b/spec/ruby/core/basicobject/instance_exec_spec.rb @@ -17,7 +17,7 @@ describe "BasicObject#instance_exec" do end it "raises a LocalJumpError unless given a block" do - lambda { "hola".instance_exec }.should raise_error(LocalJumpError) + -> { "hola".instance_exec }.should raise_error(LocalJumpError) end it "has an arity of -1" do @@ -25,7 +25,7 @@ describe "BasicObject#instance_exec" do end it "accepts arguments with a block" do - lambda { "hola".instance_exec(4, 5) { |a,b| a + b } }.should_not raise_error + -> { "hola".instance_exec(4, 5) { |a,b| a + b } }.should_not raise_error end it "doesn't pass self to the block as an argument" do @@ -44,7 +44,7 @@ describe "BasicObject#instance_exec" do end end f.foo.should == 1 - lambda { Object.new.foo }.should raise_error(NoMethodError) + -> { Object.new.foo }.should raise_error(NoMethodError) end # TODO: This should probably be replaced with a "should behave like" that uses @@ -76,10 +76,10 @@ describe "BasicObject#instance_exec" do end it "raises a TypeError when defining methods on an immediate" do - lambda do + -> do 1.instance_exec { def foo; end } end.should raise_error(TypeError) - lambda do + -> do :foo.instance_exec { def foo; end } end.should raise_error(TypeError) end @@ -97,10 +97,10 @@ quarantine! do # Not clean, leaves cvars lying around to break other specs end it "raises a TypeError when defining methods on numerics" do - lambda do + -> do (1.0).instance_exec { def foo; end } end.should raise_error(TypeError) - lambda do + -> do (1 << 64).instance_exec { def foo; end } end.should raise_error(TypeError) end diff --git a/spec/ruby/core/binding/local_variable_defined_spec.rb b/spec/ruby/core/binding/local_variable_defined_spec.rb index 7b48257294..2fc6504ee5 100644 --- a/spec/ruby/core/binding/local_variable_defined_spec.rb +++ b/spec/ruby/core/binding/local_variable_defined_spec.rb @@ -26,7 +26,7 @@ describe 'Binding#local_variable_defined?' do it 'returns true when a local variable is defined in a parent scope' do foo = 10 - lambda { + -> { binding.local_variable_defined?(:foo) }.call.should == true end diff --git a/spec/ruby/core/binding/local_variable_get_spec.rb b/spec/ruby/core/binding/local_variable_get_spec.rb index eeb3ae44ed..005670becc 100644 --- a/spec/ruby/core/binding/local_variable_get_spec.rb +++ b/spec/ruby/core/binding/local_variable_get_spec.rb @@ -11,7 +11,7 @@ describe "Binding#local_variable_get" do it "raises a NameError for missing variables" do bind = BindingSpecs::Demo.new(1).get_empty_binding - lambda { + -> { bind.local_variable_get(:no_such_variable) }.should raise_error(NameError) end @@ -19,7 +19,7 @@ describe "Binding#local_variable_get" do it "reads variables added later to the binding" do bind = BindingSpecs::Demo.new(1).get_empty_binding - lambda { + -> { bind.local_variable_get(:a) }.should raise_error(NameError) @@ -31,7 +31,7 @@ describe "Binding#local_variable_get" do it 'gets a local variable defined in a parent scope' do number = 10 - lambda { + -> { binding.local_variable_get(:number) }.call.should == 10 end @@ -45,12 +45,12 @@ describe "Binding#local_variable_get" do it "raises a NameError on global access" do bind = binding - lambda { bind.local_variable_get(:$0) }.should raise_error(NameError) + -> { bind.local_variable_get(:$0) }.should raise_error(NameError) end it "raises a NameError on special variable access" do bind = binding - lambda { bind.local_variable_get(:$~) }.should raise_error(NameError) - lambda { bind.local_variable_get(:$_) }.should raise_error(NameError) + -> { bind.local_variable_get(:$~) }.should raise_error(NameError) + -> { bind.local_variable_get(:$_) }.should raise_error(NameError) end end diff --git a/spec/ruby/core/binding/local_variable_set_spec.rb b/spec/ruby/core/binding/local_variable_set_spec.rb index 035e9a3c2e..1456c6dda1 100644 --- a/spec/ruby/core/binding/local_variable_set_spec.rb +++ b/spec/ruby/core/binding/local_variable_set_spec.rb @@ -38,7 +38,7 @@ describe "Binding#local_variable_set" do bind = binding bind.local_variable_set(:number, 10) - lambda { number }.should raise_error(NameError) + -> { number }.should raise_error(NameError) end it 'overwrites an existing local variable defined before a Binding' do @@ -59,13 +59,13 @@ describe "Binding#local_variable_set" do it "raises a NameError on global access" do bind = binding - lambda { bind.local_variable_set(:$0, "") }.should raise_error(NameError) + -> { bind.local_variable_set(:$0, "") }.should raise_error(NameError) end it "raises a NameError on special variable access" do bind = binding - lambda { bind.local_variable_set(:$~, "") }.should raise_error(NameError) - lambda { bind.local_variable_set(:$_, "") }.should raise_error(NameError) + -> { bind.local_variable_set(:$~, "") }.should raise_error(NameError) + -> { bind.local_variable_set(:$_, "") }.should raise_error(NameError) end end diff --git a/spec/ruby/core/class/allocate_spec.rb b/spec/ruby/core/class/allocate_spec.rb index 4cf5665392..c426c38ff9 100644 --- a/spec/ruby/core/class/allocate_spec.rb +++ b/spec/ruby/core/class/allocate_spec.rb @@ -14,7 +14,7 @@ describe "Class#allocate" do it "throws an exception when calling a method on a new instance" do klass = Class.allocate - lambda do + -> do klass.new end.should raise_error(Exception) end @@ -34,7 +34,7 @@ describe "Class#allocate" do end it "raises TypeError for #superclass" do - lambda do + -> do Class.allocate.superclass end.should raise_error(TypeError) end diff --git a/spec/ruby/core/class/inherited_spec.rb b/spec/ruby/core/class/inherited_spec.rb index fb7fb8e75a..8ef8bb8c35 100644 --- a/spec/ruby/core/class/inherited_spec.rb +++ b/spec/ruby/core/class/inherited_spec.rb @@ -92,10 +92,10 @@ describe "Class.inherited" do end class << top; private :inherited; end - lambda { Class.new(top) }.should_not raise_error + -> { Class.new(top) }.should_not raise_error class << top; protected :inherited; end - lambda { Class.new(top) }.should_not raise_error + -> { Class.new(top) }.should_not raise_error end end diff --git a/spec/ruby/core/class/initialize_spec.rb b/spec/ruby/core/class/initialize_spec.rb index 88a9fcfa7a..9678d7b373 100644 --- a/spec/ruby/core/class/initialize_spec.rb +++ b/spec/ruby/core/class/initialize_spec.rb @@ -6,18 +6,18 @@ describe "Class#initialize" do end it "raises a TypeError when called on already initialized classes" do - lambda{ + ->{ Fixnum.send :initialize }.should raise_error(TypeError) - lambda{ + ->{ Object.send :initialize }.should raise_error(TypeError) end # See [redmine:2601] it "raises a TypeError when called on BasicObject" do - lambda{ + ->{ BasicObject.send :initialize }.should raise_error(TypeError) end @@ -28,7 +28,7 @@ describe "Class#initialize" do end it "raises a TypeError" do - lambda{@uninitialized.send(:initialize, Class)}.should raise_error(TypeError) + ->{@uninitialized.send(:initialize, Class)}.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/class/new_spec.rb b/spec/ruby/core/class/new_spec.rb index 7f7ec183ea..8191ce6a37 100644 --- a/spec/ruby/core/class/new_spec.rb +++ b/spec/ruby/core/class/new_spec.rb @@ -70,7 +70,7 @@ describe "Class.new" do it "raises a TypeError if passed a metaclass" do obj = mock("Class.new metaclass") meta = obj.singleton_class - lambda { Class.new meta }.should raise_error(TypeError) + -> { Class.new meta }.should raise_error(TypeError) end it "creates a class without a name" do @@ -96,11 +96,11 @@ describe "Class.new" do it "raises a TypeError when given a non-Class" do error_msg = /superclass must be a Class/ - lambda { Class.new("") }.should raise_error(TypeError, error_msg) - lambda { Class.new(1) }.should raise_error(TypeError, error_msg) - lambda { Class.new(:symbol) }.should raise_error(TypeError, error_msg) - lambda { Class.new(mock('o')) }.should raise_error(TypeError, error_msg) - lambda { Class.new(Module.new) }.should raise_error(TypeError, error_msg) + -> { Class.new("") }.should raise_error(TypeError, error_msg) + -> { Class.new(1) }.should raise_error(TypeError, error_msg) + -> { Class.new(:symbol) }.should raise_error(TypeError, error_msg) + -> { Class.new(mock('o')) }.should raise_error(TypeError, error_msg) + -> { Class.new(Module.new) }.should raise_error(TypeError, error_msg) end end diff --git a/spec/ruby/core/comparable/clamp_spec.rb b/spec/ruby/core/comparable/clamp_spec.rb index d3f1022499..6d216220d4 100644 --- a/spec/ruby/core/comparable/clamp_spec.rb +++ b/spec/ruby/core/comparable/clamp_spec.rb @@ -4,8 +4,8 @@ require_relative 'fixtures/classes' describe 'Comparable#clamp' do it 'raises an Argument error unless given 2 parameters' do c = ComparableSpecs::Weird.new(0) - lambda { c.clamp(c) }.should raise_error(ArgumentError) - lambda { c.clamp(c, c, c) }.should raise_error(ArgumentError) + -> { c.clamp(c) }.should raise_error(ArgumentError) + -> { c.clamp(c, c, c) }.should raise_error(ArgumentError) end it 'raises an Argument error unless the 2 parameters are correctly ordered' do @@ -13,9 +13,9 @@ describe 'Comparable#clamp' do two = ComparableSpecs::WithOnlyCompareDefined.new(2) c = ComparableSpecs::Weird.new(3) - lambda { c.clamp(two, one) }.should raise_error(ArgumentError) + -> { c.clamp(two, one) }.should raise_error(ArgumentError) one.should_receive(:<=>).any_number_of_times.and_return(nil) - lambda { c.clamp(one, two) }.should raise_error(ArgumentError) + -> { c.clamp(one, two) }.should raise_error(ArgumentError) end it 'returns self if within the given parameters' do diff --git a/spec/ruby/core/comparable/equal_value_spec.rb b/spec/ruby/core/comparable/equal_value_spec.rb index 53c83aa2d3..ddcc03cb41 100644 --- a/spec/ruby/core/comparable/equal_value_spec.rb +++ b/spec/ruby/core/comparable/equal_value_spec.rb @@ -49,7 +49,7 @@ describe "Comparable#==" do end it "raises an ArgumentError" do - lambda { (a == b) }.should raise_error(ArgumentError) + -> { (a == b) }.should raise_error(ArgumentError) end end @@ -60,7 +60,7 @@ describe "Comparable#==" do end it "lets it go through" do - lambda { (a == b) }.should raise_error(StandardError) + -> { (a == b) }.should raise_error(StandardError) end end @@ -71,13 +71,13 @@ describe "Comparable#==" do end it "lets it go through" do - lambda { (a == b) }.should raise_error(TypeError) + -> { (a == b) }.should raise_error(TypeError) end end it "lets it go through if it is not a StandardError" do a.should_receive(:<=>).once.and_raise(Exception) - lambda { (a == b) }.should raise_error(Exception) + -> { (a == b) }.should raise_error(Exception) end end diff --git a/spec/ruby/core/comparable/gt_spec.rb b/spec/ruby/core/comparable/gt_spec.rb index 6dd661bbfa..150e653dc7 100644 --- a/spec/ruby/core/comparable/gt_spec.rb +++ b/spec/ruby/core/comparable/gt_spec.rb @@ -38,6 +38,6 @@ describe "Comparable#>" do b = ComparableSpecs::Weird.new(20) a.should_receive(:<=>).any_number_of_times.and_return(nil) - lambda { (a > b) }.should raise_error(ArgumentError) + -> { (a > b) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/comparable/gte_spec.rb b/spec/ruby/core/comparable/gte_spec.rb index cdaeb60843..328f58c66c 100644 --- a/spec/ruby/core/comparable/gte_spec.rb +++ b/spec/ruby/core/comparable/gte_spec.rb @@ -42,6 +42,6 @@ describe "Comparable#>=" do b = ComparableSpecs::Weird.new(20) a.should_receive(:<=>).any_number_of_times.and_return(nil) - lambda { (a >= b) }.should raise_error(ArgumentError) + -> { (a >= b) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/comparable/lt_spec.rb b/spec/ruby/core/comparable/lt_spec.rb index 02f77dba50..4db92719e2 100644 --- a/spec/ruby/core/comparable/lt_spec.rb +++ b/spec/ruby/core/comparable/lt_spec.rb @@ -38,6 +38,6 @@ describe "Comparable#<" do b = ComparableSpecs::Weird.new(20) a.should_receive(:<=>).any_number_of_times.and_return(nil) - lambda { (a < b) }.should raise_error(ArgumentError) + -> { (a < b) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/comparable/lte_spec.rb b/spec/ruby/core/comparable/lte_spec.rb index baf2c57229..b5cb9cc4e7 100644 --- a/spec/ruby/core/comparable/lte_spec.rb +++ b/spec/ruby/core/comparable/lte_spec.rb @@ -41,6 +41,6 @@ describe "Comparable#<=" do b = ComparableSpecs::Weird.new(20) a.should_receive(:<=>).any_number_of_times.and_return(nil) - lambda { (a <= b) }.should raise_error(ArgumentError) + -> { (a <= b) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/complex/coerce_spec.rb b/spec/ruby/core/complex/coerce_spec.rb index ce2fb36b73..a30a6c1d5f 100644 --- a/spec/ruby/core/complex/coerce_spec.rb +++ b/spec/ruby/core/complex/coerce_spec.rb @@ -53,18 +53,18 @@ describe "Complex#coerce" do it "raises TypeError when other is a Numeric which responds to #real? with false" do other = mock_numeric('other') other.should_receive(:real?).any_number_of_times.and_return(false) - lambda { @one.coerce(other) }.should raise_error(TypeError) + -> { @one.coerce(other) }.should raise_error(TypeError) end it "raises a TypeError when other is a String" do - lambda { @one.coerce("20") }.should raise_error(TypeError) + -> { @one.coerce("20") }.should raise_error(TypeError) end it "raises a TypeError when other is nil" do - lambda { @one.coerce(nil) }.should raise_error(TypeError) + -> { @one.coerce(nil) }.should raise_error(TypeError) end it "raises a TypeError when other is false" do - lambda { @one.coerce(false) }.should raise_error(TypeError) + -> { @one.coerce(false) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/complex/fdiv_spec.rb b/spec/ruby/core/complex/fdiv_spec.rb index 20d2f41354..68f7d1b309 100644 --- a/spec/ruby/core/complex/fdiv_spec.rb +++ b/spec/ruby/core/complex/fdiv_spec.rb @@ -2,21 +2,21 @@ require_relative '../../spec_helper' describe "Complex#fdiv" do it "accepts a numeric argument" do - lambda { Complex(20).fdiv(2) }.should_not raise_error(TypeError) - lambda { Complex(20).fdiv(2.0) }.should_not raise_error(TypeError) - lambda { Complex(20).fdiv(bignum_value) }.should_not raise_error(TypeError) + -> { Complex(20).fdiv(2) }.should_not raise_error(TypeError) + -> { Complex(20).fdiv(2.0) }.should_not raise_error(TypeError) + -> { Complex(20).fdiv(bignum_value) }.should_not raise_error(TypeError) end it "accepts a negative numeric argument" do - lambda { Complex(20).fdiv(-2) }.should_not raise_error(TypeError) - lambda { Complex(20).fdiv(-2.0) }.should_not raise_error(TypeError) - lambda { Complex(20).fdiv(-bignum_value) }.should_not raise_error(TypeError) + -> { Complex(20).fdiv(-2) }.should_not raise_error(TypeError) + -> { Complex(20).fdiv(-2.0) }.should_not raise_error(TypeError) + -> { Complex(20).fdiv(-bignum_value) }.should_not raise_error(TypeError) end it "raises a TypeError if passed a non-numeric argument" do - lambda { Complex(20).fdiv([]) }.should raise_error(TypeError) - lambda { Complex(20).fdiv(:sym) }.should raise_error(TypeError) - lambda { Complex(20).fdiv('s') }.should raise_error(TypeError) + -> { Complex(20).fdiv([]) }.should raise_error(TypeError) + -> { Complex(20).fdiv(:sym) }.should raise_error(TypeError) + -> { Complex(20).fdiv('s') }.should raise_error(TypeError) end it "sets the real part to NaN if self's real part is NaN" do diff --git a/spec/ruby/core/complex/negative_spec.rb b/spec/ruby/core/complex/negative_spec.rb index 1ea5392f39..62ab89c04a 100644 --- a/spec/ruby/core/complex/negative_spec.rb +++ b/spec/ruby/core/complex/negative_spec.rb @@ -6,7 +6,7 @@ describe "Complex#negative?" do c.methods.should_not include(:negative?) - lambda { + -> { c.negative? }.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/complex/polar_spec.rb b/spec/ruby/core/complex/polar_spec.rb index f9d28b8388..2a5d8ebd69 100644 --- a/spec/ruby/core/complex/polar_spec.rb +++ b/spec/ruby/core/complex/polar_spec.rb @@ -7,8 +7,8 @@ describe "Complex.polar" do end it "raises a TypeError when given non real arguments" do - lambda{ Complex.polar(nil) }.should raise_error(TypeError) - lambda{ Complex.polar(nil, nil) }.should raise_error(TypeError) + ->{ Complex.polar(nil) }.should raise_error(TypeError) + ->{ Complex.polar(nil, nil) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/complex/positive_spec.rb b/spec/ruby/core/complex/positive_spec.rb index eea0af3755..f1bad8608c 100644 --- a/spec/ruby/core/complex/positive_spec.rb +++ b/spec/ruby/core/complex/positive_spec.rb @@ -6,7 +6,7 @@ describe "Complex#positive?" do c.methods.should_not include(:positive?) - lambda { + -> { c.positive? }.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/complex/rationalize_spec.rb b/spec/ruby/core/complex/rationalize_spec.rb index 165f3d2700..043b8ddf2a 100644 --- a/spec/ruby/core/complex/rationalize_spec.rb +++ b/spec/ruby/core/complex/rationalize_spec.rb @@ -2,11 +2,11 @@ require_relative '../../spec_helper' describe "Complex#rationalize" do it "raises RangeError if self has non-zero imaginary part" do - lambda { Complex(1,5).rationalize }.should raise_error(RangeError) + -> { Complex(1,5).rationalize }.should raise_error(RangeError) end it "raises RangeError if self has 0.0 imaginary part" do - lambda { Complex(1,0.0).rationalize }.should raise_error(RangeError) + -> { Complex(1,0.0).rationalize }.should raise_error(RangeError) end it "returns a Rational if self has zero imaginary part" do @@ -25,7 +25,7 @@ describe "Complex#rationalize" do end it "raises ArgumentError when passed more than one argument" do - lambda { Complex(1,0).rationalize(0.1, 0.1) }.should raise_error(ArgumentError) - lambda { Complex(1,0).rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) + -> { Complex(1,0).rationalize(0.1, 0.1) }.should raise_error(ArgumentError) + -> { Complex(1,0).rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/complex/shared/divide.rb b/spec/ruby/core/complex/shared/divide.rb index e3701405b9..a60802c74c 100644 --- a/spec/ruby/core/complex/shared/divide.rb +++ b/spec/ruby/core/complex/shared/divide.rb @@ -19,7 +19,7 @@ describe :complex_divide, shared: true do end it "raises a ZeroDivisionError when given zero" do - lambda { Complex(20, 40).send(@method, 0) }.should raise_error(ZeroDivisionError) + -> { Complex(20, 40).send(@method, 0) }.should raise_error(ZeroDivisionError) end it "produces Rational parts" do diff --git a/spec/ruby/core/complex/shared/rect.rb b/spec/ruby/core/complex/shared/rect.rb index 971821ac33..9f5de1ffeb 100644 --- a/spec/ruby/core/complex/shared/rect.rb +++ b/spec/ruby/core/complex/shared/rect.rb @@ -37,7 +37,7 @@ describe :complex_rect, shared: true do it "raises an ArgumentError if given any arguments" do @numbers.each do |number| - lambda { number.send(@method, number) }.should raise_error(ArgumentError) + -> { number.send(@method, number) }.should raise_error(ArgumentError) end end end @@ -57,7 +57,7 @@ describe :complex_rect_class, shared: true do it "raises TypeError" do n = mock_numeric('n') n.should_receive(:real?).any_number_of_times.and_return(false) - lambda { Complex.send(@method, n) }.should raise_error(TypeError) + -> { Complex.send(@method, n) }.should raise_error(TypeError) end end @@ -68,7 +68,7 @@ describe :complex_rect_class, shared: true do n2 = mock_numeric('n2') n1.should_receive(:real?).any_number_of_times.and_return(r1) n2.should_receive(:real?).any_number_of_times.and_return(r2) - lambda { Complex.send(@method, n1, n2) }.should raise_error(TypeError) + -> { Complex.send(@method, n1, n2) }.should raise_error(TypeError) end end end @@ -87,8 +87,8 @@ describe :complex_rect_class, shared: true do describe "passed a non-Numeric" do it "raises TypeError" do - lambda { Complex.send(@method, :sym) }.should raise_error(TypeError) - lambda { Complex.send(@method, 0, :sym) }.should raise_error(TypeError) + -> { Complex.send(@method, :sym) }.should raise_error(TypeError) + -> { Complex.send(@method, 0, :sym) }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/complex/to_f_spec.rb b/spec/ruby/core/complex/to_f_spec.rb index 12c34dfbb1..78e6526491 100644 --- a/spec/ruby/core/complex/to_f_spec.rb +++ b/spec/ruby/core/complex/to_f_spec.rb @@ -29,13 +29,13 @@ describe "Complex#to_f" do describe "when the imaginary part is non-zero" do it "raises RangeError" do - lambda { Complex(0, 1).to_f }.should raise_error(RangeError) + -> { Complex(0, 1).to_f }.should raise_error(RangeError) end end describe "when the imaginary part is Float 0.0" do it "raises RangeError" do - lambda { Complex(0, 0.0).to_f }.should raise_error(RangeError) + -> { Complex(0, 0.0).to_f }.should raise_error(RangeError) end end end diff --git a/spec/ruby/core/complex/to_i_spec.rb b/spec/ruby/core/complex/to_i_spec.rb index acdf719376..23134705ba 100644 --- a/spec/ruby/core/complex/to_i_spec.rb +++ b/spec/ruby/core/complex/to_i_spec.rb @@ -29,13 +29,13 @@ describe "Complex#to_i" do describe "when the imaginary part is non-zero" do it "raises RangeError" do - lambda { Complex(0, 1).to_i }.should raise_error(RangeError) + -> { Complex(0, 1).to_i }.should raise_error(RangeError) end end describe "when the imaginary part is Float 0.0" do it "raises RangeError" do - lambda { Complex(0, 0.0).to_i }.should raise_error(RangeError) + -> { Complex(0, 0.0).to_i }.should raise_error(RangeError) end end end diff --git a/spec/ruby/core/complex/to_r_spec.rb b/spec/ruby/core/complex/to_r_spec.rb index 46bac98ef4..76a69a0b93 100644 --- a/spec/ruby/core/complex/to_r_spec.rb +++ b/spec/ruby/core/complex/to_r_spec.rb @@ -29,13 +29,13 @@ describe "Complex#to_r" do describe "when the imaginary part is non-zero" do it "raises RangeError" do - lambda { Complex(0, 1).to_r }.should raise_error(RangeError) + -> { Complex(0, 1).to_r }.should raise_error(RangeError) end end describe "when the imaginary part is Float 0.0" do it "raises RangeError" do - lambda { Complex(0, 0.0).to_r }.should raise_error(RangeError) + -> { Complex(0, 0.0).to_r }.should raise_error(RangeError) end end end diff --git a/spec/ruby/core/dir/chdir_spec.rb b/spec/ruby/core/dir/chdir_spec.rb index a2383e6bf2..e9b8274382 100644 --- a/spec/ruby/core/dir/chdir_spec.rb +++ b/spec/ruby/core/dir/chdir_spec.rb @@ -88,8 +88,8 @@ describe "Dir.chdir" do end it "raises an Errno::ENOENT if the directory does not exist" do - lambda { Dir.chdir DirSpecs.nonexistent }.should raise_error(Errno::ENOENT) - lambda { Dir.chdir(DirSpecs.nonexistent) { } }.should raise_error(Errno::ENOENT) + -> { Dir.chdir DirSpecs.nonexistent }.should raise_error(Errno::ENOENT) + -> { Dir.chdir(DirSpecs.nonexistent) { } }.should raise_error(Errno::ENOENT) end it "raises an Errno::ENOENT if the original directory no longer exists" do @@ -100,7 +100,7 @@ describe "Dir.chdir" do Dir.mkdir dir1 Dir.mkdir dir2 begin - lambda { + -> { Dir.chdir dir1 do Dir.chdir(dir2) { Dir.unlink dir1 } end diff --git a/spec/ruby/core/dir/children_spec.rb b/spec/ruby/core/dir/children_spec.rb index ef8b20b1f0..8f6e62b463 100644 --- a/spec/ruby/core/dir/children_spec.rb +++ b/spec/ruby/core/dir/children_spec.rb @@ -66,7 +66,7 @@ ruby_version_is "2.5" do end it "raises a SystemCallError if called with a nonexistent directory" do - lambda { Dir.children DirSpecs.nonexistent }.should raise_error(SystemCallError) + -> { Dir.children DirSpecs.nonexistent }.should raise_error(SystemCallError) end end end diff --git a/spec/ruby/core/dir/chroot_spec.rb b/spec/ruby/core/dir/chroot_spec.rb index bce4d6f286..55392410e7 100644 --- a/spec/ruby/core/dir/chroot_spec.rb +++ b/spec/ruby/core/dir/chroot_spec.rb @@ -21,17 +21,17 @@ platform_is_not :windows do end it "raises an Errno::EPERM exception if the directory exists" do - lambda { Dir.chroot('.') }.should raise_error(Errno::EPERM) + -> { Dir.chroot('.') }.should raise_error(Errno::EPERM) end it "raises a SystemCallError if the directory doesn't exist" do - lambda { Dir.chroot('xgwhwhsjai2222jg') }.should raise_error(SystemCallError) + -> { Dir.chroot('xgwhwhsjai2222jg') }.should raise_error(SystemCallError) end it "calls #to_path on non-String argument" do p = mock('path') p.should_receive(:to_path).and_return('.') - lambda { Dir.chroot(p) }.should raise_error(Errno::EPERM) + -> { Dir.chroot(p) }.should raise_error(Errno::EPERM) end end end diff --git a/spec/ruby/core/dir/close_spec.rb b/spec/ruby/core/dir/close_spec.rb index 64d87140ae..5fad5eecfb 100644 --- a/spec/ruby/core/dir/close_spec.rb +++ b/spec/ruby/core/dir/close_spec.rb @@ -12,7 +12,7 @@ describe "Dir#close" do it "does not raise an IOError even if the Dir instance is closed" do dir = Dir.open DirSpecs.mock_dir dir.close - lambda { + -> { dir.close }.should_not raise_error(IOError) end diff --git a/spec/ruby/core/dir/each_child_spec.rb b/spec/ruby/core/dir/each_child_spec.rb index c04d212bfa..dcc9a456c7 100644 --- a/spec/ruby/core/dir/each_child_spec.rb +++ b/spec/ruby/core/dir/each_child_spec.rb @@ -32,7 +32,7 @@ ruby_version_is "2.5" do end it "raises a SystemCallError if passed a nonexistent directory" do - lambda { Dir.each_child(DirSpecs.nonexistent) {} }.should raise_error(SystemCallError) + -> { Dir.each_child(DirSpecs.nonexistent) {} }.should raise_error(SystemCallError) end describe "when no block is given" do diff --git a/spec/ruby/core/dir/empty_spec.rb b/spec/ruby/core/dir/empty_spec.rb index 626b228439..8cc8757798 100644 --- a/spec/ruby/core/dir/empty_spec.rb +++ b/spec/ruby/core/dir/empty_spec.rb @@ -26,6 +26,6 @@ describe "Dir.empty?" do end it "raises ENOENT for nonexistent directories" do - lambda { Dir.empty? tmp("nonexistent") }.should raise_error(Errno::ENOENT) + -> { Dir.empty? tmp("nonexistent") }.should raise_error(Errno::ENOENT) end end diff --git a/spec/ruby/core/dir/entries_spec.rb b/spec/ruby/core/dir/entries_spec.rb index ed45287e82..33568b6fc4 100644 --- a/spec/ruby/core/dir/entries_spec.rb +++ b/spec/ruby/core/dir/entries_spec.rb @@ -65,6 +65,6 @@ describe "Dir.entries" do end it "raises a SystemCallError if called with a nonexistent directory" do - lambda { Dir.entries DirSpecs.nonexistent }.should raise_error(SystemCallError) + -> { Dir.entries DirSpecs.nonexistent }.should raise_error(SystemCallError) end end diff --git a/spec/ruby/core/dir/fileno_spec.rb b/spec/ruby/core/dir/fileno_spec.rb index 5a893d2da9..504e36d44b 100644 --- a/spec/ruby/core/dir/fileno_spec.rb +++ b/spec/ruby/core/dir/fileno_spec.rb @@ -31,7 +31,7 @@ describe "Dir#fileno" do end else it "raises an error when not implemented on the platform" do - lambda { @dir.fileno }.should raise_error(NotImplementedError) + -> { @dir.fileno }.should raise_error(NotImplementedError) end end end diff --git a/spec/ruby/core/dir/foreach_spec.rb b/spec/ruby/core/dir/foreach_spec.rb index fed0aa8065..1560b85f8a 100644 --- a/spec/ruby/core/dir/foreach_spec.rb +++ b/spec/ruby/core/dir/foreach_spec.rb @@ -31,7 +31,7 @@ describe "Dir.foreach" do end it "raises a SystemCallError if passed a nonexistent directory" do - lambda { Dir.foreach(DirSpecs.nonexistent) {} }.should raise_error(SystemCallError) + -> { Dir.foreach(DirSpecs.nonexistent) {} }.should raise_error(SystemCallError) end it "returns an Enumerator if no block given" do diff --git a/spec/ruby/core/dir/home_spec.rb b/spec/ruby/core/dir/home_spec.rb index db46b80c54..cdfc9346dc 100644 --- a/spec/ruby/core/dir/home_spec.rb +++ b/spec/ruby/core/dir/home_spec.rb @@ -40,6 +40,6 @@ describe "Dir.home" do end it "raises an ArgumentError if the named user doesn't exist" do - lambda { Dir.home('geuw2n288dh2k') }.should raise_error(ArgumentError) + -> { Dir.home('geuw2n288dh2k') }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/dir/mkdir_spec.rb b/spec/ruby/core/dir/mkdir_spec.rb index d0bf32c143..58767a5aa0 100644 --- a/spec/ruby/core/dir/mkdir_spec.rb +++ b/spec/ruby/core/dir/mkdir_spec.rb @@ -51,15 +51,15 @@ describe "Dir.mkdir" do end it "raises a SystemCallError if any of the directories in the path before the last does not exist" do - lambda { Dir.mkdir "#{DirSpecs.nonexistent}/subdir" }.should raise_error(SystemCallError) + -> { Dir.mkdir "#{DirSpecs.nonexistent}/subdir" }.should raise_error(SystemCallError) end it "raises Errno::EEXIST if the specified directory already exists" do - lambda { Dir.mkdir("#{DirSpecs.mock_dir}/dir") }.should raise_error(Errno::EEXIST) + -> { Dir.mkdir("#{DirSpecs.mock_dir}/dir") }.should raise_error(Errno::EEXIST) end it "raises Errno::EEXIST if the argument points to the existing file" do - lambda { Dir.mkdir("#{DirSpecs.mock_dir}/file_one.ext") }.should raise_error(Errno::EEXIST) + -> { Dir.mkdir("#{DirSpecs.mock_dir}/file_one.ext") }.should raise_error(Errno::EEXIST) end end @@ -80,7 +80,7 @@ platform_is_not :windows do it "raises a SystemCallError when lacking adequate permissions in the parent dir" do Dir.mkdir @dir, 0000 - lambda { Dir.mkdir "#{@dir}/subdir" }.should raise_error(SystemCallError) + -> { Dir.mkdir "#{@dir}/subdir" }.should raise_error(SystemCallError) end end end diff --git a/spec/ruby/core/dir/shared/chroot.rb b/spec/ruby/core/dir/shared/chroot.rb index 2ed033dfed..93699f93be 100644 --- a/spec/ruby/core/dir/shared/chroot.rb +++ b/spec/ruby/core/dir/shared/chroot.rb @@ -15,7 +15,7 @@ describe :dir_chroot_as_root, shared: true do end it "can be used to change the process' root directory" do - lambda { Dir.send(@method, File.dirname(__FILE__)) }.should_not raise_error + -> { Dir.send(@method, File.dirname(__FILE__)) }.should_not raise_error File.exist?("/#{File.basename(__FILE__)}").should be_true end @@ -24,7 +24,7 @@ describe :dir_chroot_as_root, shared: true do end it "raises an Errno::ENOENT exception if the directory doesn't exist" do - lambda { Dir.send(@method, 'xgwhwhsjai2222jg') }.should raise_error(Errno::ENOENT) + -> { Dir.send(@method, 'xgwhwhsjai2222jg') }.should raise_error(Errno::ENOENT) end it "can be escaped from with ../" do diff --git a/spec/ruby/core/dir/shared/closed.rb b/spec/ruby/core/dir/shared/closed.rb index a1bce06a08..17d8332c2a 100644 --- a/spec/ruby/core/dir/shared/closed.rb +++ b/spec/ruby/core/dir/shared/closed.rb @@ -1,6 +1,6 @@ describe :dir_closed, shared: true do it "raises an IOError when called on a closed Dir instance" do - lambda { + -> { dir = Dir.open DirSpecs.mock_dir dir.close dir.send(@method) {} diff --git a/spec/ruby/core/dir/shared/delete.rb b/spec/ruby/core/dir/shared/delete.rb index 649708cd76..49e88360e8 100644 --- a/spec/ruby/core/dir/shared/delete.rb +++ b/spec/ruby/core/dir/shared/delete.rb @@ -19,7 +19,7 @@ describe :dir_delete, shared: true do platform_is_not :solaris do it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do - lambda do + -> do Dir.send @method, DirSpecs.mock_rmdir("nonempty") end.should raise_error(Errno::ENOTEMPTY) end @@ -27,14 +27,14 @@ describe :dir_delete, shared: true do platform_is :solaris do it "raises an Errno::EEXIST when trying to remove a nonempty directory" do - lambda do + -> do Dir.send @method, DirSpecs.mock_rmdir("nonempty") end.should raise_error(Errno::EEXIST) end end it "raises an Errno::ENOENT when trying to remove a non-existing directory" do - lambda do + -> do Dir.send @method, DirSpecs.nonexistent end.should raise_error(Errno::ENOENT) end @@ -42,7 +42,7 @@ describe :dir_delete, shared: true do it "raises an Errno::ENOTDIR when trying to remove a non-directory" do file = DirSpecs.mock_rmdir("nonempty/regular") touch(file) - lambda do + -> do Dir.send @method, file end.should raise_error(Errno::ENOTDIR) end @@ -54,7 +54,7 @@ describe :dir_delete, shared: true do parent = DirSpecs.mock_rmdir("noperm") child = DirSpecs.mock_rmdir("noperm", "child") File.chmod(0000, parent) - lambda do + -> do Dir.send @method, child end.should raise_error(Errno::EACCES) end diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb index af587dd33b..e4ffb51286 100644 --- a/spec/ruby/core/dir/shared/glob.rb +++ b/spec/ruby/core/dir/shared/glob.rb @@ -13,7 +13,7 @@ describe :dir_glob, shared: true do it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do pattern = "file*".force_encoding Encoding::UTF_16BE - lambda { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError) + -> { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError) end it "calls #to_path to convert a pattern" do diff --git a/spec/ruby/core/dir/shared/open.rb b/spec/ruby/core/dir/shared/open.rb index 63e9036053..fb2af71e05 100644 --- a/spec/ruby/core/dir/shared/open.rb +++ b/spec/ruby/core/dir/shared/open.rb @@ -6,7 +6,7 @@ describe :dir_open, shared: true do end it "raises a SystemCallError if the directory does not exist" do - lambda do + -> do Dir.send @method, DirSpecs.nonexistent end.should raise_error(SystemCallError) end @@ -21,20 +21,20 @@ describe :dir_open, shared: true do it "closes the Dir instance when the block exits if given a block" do closed_dir = Dir.send(@method, DirSpecs.mock_dir) { |dir| dir } - lambda { closed_dir.read }.should raise_error(IOError) + -> { closed_dir.read }.should raise_error(IOError) end it "closes the Dir instance when the block exits the block even due to an exception" do closed_dir = nil - lambda do + -> do Dir.send(@method, DirSpecs.mock_dir) do |dir| closed_dir = dir raise "dir specs" end end.should raise_error(RuntimeError, "dir specs") - lambda { closed_dir.read }.should raise_error(IOError) + -> { closed_dir.read }.should raise_error(IOError) end it "calls #to_path on non-String arguments" do diff --git a/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb b/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb index e39d590e3a..1beb40af3f 100644 --- a/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb +++ b/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb @@ -2,7 +2,7 @@ require_relative '../../../spec_helper' describe "Encoding::Converter.asciicompat_encoding" do it "accepts an encoding name as a String argument" do - lambda { Encoding::Converter.asciicompat_encoding('UTF-8') }. + -> { Encoding::Converter.asciicompat_encoding('UTF-8') }. should_not raise_error end diff --git a/spec/ruby/core/encoding/converter/convert_spec.rb b/spec/ruby/core/encoding/converter/convert_spec.rb index 362e027a58..95a9e0b758 100644 --- a/spec/ruby/core/encoding/converter/convert_spec.rb +++ b/spec/ruby/core/encoding/converter/convert_spec.rb @@ -33,13 +33,13 @@ describe "Encoding::Converter#convert" do it "raises UndefinedConversionError if the String contains characters invalid for the target encoding" do ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic')) - lambda { ec.convert("\u{6543}".force_encoding('UTF-8')) }.should \ + -> { ec.convert("\u{6543}".force_encoding('UTF-8')) }.should \ raise_error(Encoding::UndefinedConversionError) end it "raises an ArgumentError if called on a finished stream" do ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic')) ec.finish - lambda { ec.convert("\u{65}") }.should raise_error(ArgumentError) + -> { ec.convert("\u{65}") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/encoding/converter/new_spec.rb b/spec/ruby/core/encoding/converter/new_spec.rb index 6b9c76a093..6a6343012c 100644 --- a/spec/ruby/core/encoding/converter/new_spec.rb +++ b/spec/ruby/core/encoding/converter/new_spec.rb @@ -23,7 +23,7 @@ describe "Encoding::Converter.new" do end it "raises an Encoding::ConverterNotFoundError if both encodings are the same" do - lambda do + -> do Encoding::Converter.new "utf-8", "utf-8" end.should raise_error(Encoding::ConverterNotFoundError) end @@ -65,25 +65,25 @@ describe "Encoding::Converter.new" do obj = mock("encoding converter replacement") obj.should_receive(:to_str).and_return(1) - lambda do + -> do Encoding::Converter.new("us-ascii", "utf-8", replace: obj) end.should raise_error(TypeError) end it "raises a TypeError if passed true for the replacement object" do - lambda do + -> do Encoding::Converter.new("us-ascii", "utf-8", replace: true) end.should raise_error(TypeError) end it "raises a TypeError if passed false for the replacement object" do - lambda do + -> do Encoding::Converter.new("us-ascii", "utf-8", replace: false) end.should raise_error(TypeError) end it "raises a TypeError if passed a Fixnum for the replacement object" do - lambda do + -> do Encoding::Converter.new("us-ascii", "utf-8", replace: 1) end.should raise_error(TypeError) end diff --git a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb index 710cc262bb..4a22606375 100644 --- a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb +++ b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb @@ -7,19 +7,19 @@ describe "Encoding::Converter#primitive_convert" do end it "accepts a nil source buffer" do - lambda { @ec.primitive_convert(nil,"") }.should_not raise_error + -> { @ec.primitive_convert(nil,"") }.should_not raise_error end it "accepts a String as the source buffer" do - lambda { @ec.primitive_convert("","") }.should_not raise_error + -> { @ec.primitive_convert("","") }.should_not raise_error end it "accepts nil for the destination byte offset" do - lambda { @ec.primitive_convert("","", nil) }.should_not raise_error + -> { @ec.primitive_convert("","", nil) }.should_not raise_error end it "accepts an integer for the destination byte offset" do - lambda { @ec.primitive_convert("","a", 1) }.should_not raise_error + -> { @ec.primitive_convert("","a", 1) }.should_not raise_error end it "calls #to_int to convert the destination byte offset" do @@ -30,10 +30,10 @@ describe "Encoding::Converter#primitive_convert" do end it "raises an ArgumentError if the destination byte offset is greater than the bytesize of the destination buffer" do - lambda { @ec.primitive_convert("","am", 0) }.should_not raise_error - lambda { @ec.primitive_convert("","am", 1) }.should_not raise_error - lambda { @ec.primitive_convert("","am", 2) }.should_not raise_error - lambda { @ec.primitive_convert("","am", 3) }.should raise_error(ArgumentError) + -> { @ec.primitive_convert("","am", 0) }.should_not raise_error + -> { @ec.primitive_convert("","am", 1) }.should_not raise_error + -> { @ec.primitive_convert("","am", 2) }.should_not raise_error + -> { @ec.primitive_convert("","am", 3) }.should raise_error(ArgumentError) end it "uses the destination byte offset to determine where to write the result in the destination buffer" do @@ -49,19 +49,19 @@ describe "Encoding::Converter#primitive_convert" do end it "accepts nil for the destination bytesize" do - lambda { @ec.primitive_convert("","", nil, nil) }.should_not raise_error + -> { @ec.primitive_convert("","", nil, nil) }.should_not raise_error end it "accepts an integer for the destination bytesize" do - lambda { @ec.primitive_convert("","", nil, 0) }.should_not raise_error + -> { @ec.primitive_convert("","", nil, 0) }.should_not raise_error end it "allows a destination bytesize value greater than the bytesize of the source buffer" do - lambda { @ec.primitive_convert("am","", nil, 3) }.should_not raise_error + -> { @ec.primitive_convert("am","", nil, 3) }.should_not raise_error end it "allows a destination bytesize value less than the bytesize of the source buffer" do - lambda { @ec.primitive_convert("am","", nil, 1) }.should_not raise_error + -> { @ec.primitive_convert("am","", nil, 1) }.should_not raise_error end it "calls #to_int to convert the destination byte size" do diff --git a/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb b/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb index e0a5378155..1f836b259f 100644 --- a/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb +++ b/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb @@ -54,7 +54,7 @@ describe "Encoding::Converter#primitive_errinfo" do it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #convert last raised InvalidByteSequenceError" do ec = Encoding::Converter.new("utf-8", "iso-8859-1") - lambda { ec.convert("\xf1abcd") }.should raise_error(Encoding::InvalidByteSequenceError) + -> { ec.convert("\xf1abcd") }.should raise_error(Encoding::InvalidByteSequenceError) ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-8", "ISO-8859-1", "\xF1", "a"] end @@ -62,7 +62,7 @@ describe "Encoding::Converter#primitive_errinfo" do it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #finish last raised InvalidByteSequenceError" do ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") ec.convert("\xa4") - lambda { ec.finish }.should raise_error(Encoding::InvalidByteSequenceError) + -> { ec.finish }.should raise_error(Encoding::InvalidByteSequenceError) ec.primitive_errinfo.should == [:incomplete_input, "EUC-JP", "UTF-8", "\xA4", ""] end end diff --git a/spec/ruby/core/encoding/converter/replacement_spec.rb b/spec/ruby/core/encoding/converter/replacement_spec.rb index a23be74e9b..5ca42e7e5a 100644 --- a/spec/ruby/core/encoding/converter/replacement_spec.rb +++ b/spec/ruby/core/encoding/converter/replacement_spec.rb @@ -33,7 +33,7 @@ describe "Encoding::Converter#replacement=" do it "raises a TypeError if assigned a non-String argument" do ec = Encoding::Converter.new("utf-8", "us-ascii") - lambda { ec.replacement = nil }.should raise_error(TypeError) + -> { ec.replacement = nil }.should raise_error(TypeError) end it "sets #replacement" do @@ -47,7 +47,7 @@ describe "Encoding::Converter#replacement=" do ec = Encoding::Converter.new("sjis", "ascii") utf8_q = "\u{986}".force_encoding('utf-8') ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion - lambda { ec.replacement = utf8_q }.should \ + -> { ec.replacement = utf8_q }.should \ raise_error(Encoding::UndefinedConversionError) end @@ -55,7 +55,7 @@ describe "Encoding::Converter#replacement=" do ec = Encoding::Converter.new("sjis", "ascii") utf8_q = "\u{986}".force_encoding('utf-8') ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion - lambda { ec.replacement = utf8_q }.should \ + -> { ec.replacement = utf8_q }.should \ raise_error(Encoding::UndefinedConversionError) ec.replacement.should == "?".force_encoding('us-ascii') end diff --git a/spec/ruby/core/encoding/converter/search_convpath_spec.rb b/spec/ruby/core/encoding/converter/search_convpath_spec.rb index bd7530405b..0535e7bdc3 100644 --- a/spec/ruby/core/encoding/converter/search_convpath_spec.rb +++ b/spec/ruby/core/encoding/converter/search_convpath_spec.rb @@ -25,7 +25,7 @@ describe "Encoding::Converter.search_convpath" do end it "raises an Encoding::ConverterNotFoundError if no conversion path exists" do - lambda do + -> do Encoding::Converter.search_convpath(Encoding::BINARY, Encoding::Emacs_Mule) end.should raise_error(Encoding::ConverterNotFoundError) end diff --git a/spec/ruby/core/encoding/default_external_spec.rb b/spec/ruby/core/encoding/default_external_spec.rb index 8973490901..e2cb9b02f4 100644 --- a/spec/ruby/core/encoding/default_external_spec.rb +++ b/spec/ruby/core/encoding/default_external_spec.rb @@ -54,10 +54,10 @@ describe "Encoding.default_external=" do end it "raises a TypeError unless the argument is an Encoding or convertible to a String" do - lambda { Encoding.default_external = [] }.should raise_error(TypeError) + -> { Encoding.default_external = [] }.should raise_error(TypeError) end it "raises an ArgumentError if the argument is nil" do - lambda { Encoding.default_external = nil }.should raise_error(ArgumentError) + -> { Encoding.default_external = nil }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/encoding/default_internal_spec.rb b/spec/ruby/core/encoding/default_internal_spec.rb index 47a6887eee..855f4e9f32 100644 --- a/spec/ruby/core/encoding/default_internal_spec.rb +++ b/spec/ruby/core/encoding/default_internal_spec.rb @@ -60,11 +60,11 @@ describe "Encoding.default_internal=" do obj = mock('string') obj.should_receive(:to_str).at_least(1).times.and_return(1) - lambda { Encoding.default_internal = obj }.should raise_error(TypeError) + -> { Encoding.default_internal = obj }.should raise_error(TypeError) end it "raises a TypeError when passed an object not providing #to_str" do - lambda { Encoding.default_internal = mock("encoding") }.should raise_error(TypeError) + -> { Encoding.default_internal = mock("encoding") }.should raise_error(TypeError) end it "accepts an argument of nil to unset the default internal encoding" do diff --git a/spec/ruby/core/encoding/find_spec.rb b/spec/ruby/core/encoding/find_spec.rb index 5635a51c69..8a0873070f 100644 --- a/spec/ruby/core/encoding/find_spec.rb +++ b/spec/ruby/core/encoding/find_spec.rb @@ -18,7 +18,7 @@ describe "Encoding.find" do end it "raises a TypeError if passed a Symbol" do - lambda { Encoding.find(:"utf-8") }.should raise_error(TypeError) + -> { Encoding.find(:"utf-8") }.should raise_error(TypeError) end it "returns the passed Encoding object" do @@ -50,7 +50,7 @@ describe "Encoding.find" do end it "raises an ArgumentError if the given encoding does not exist" do - lambda { Encoding.find('dh2dh278d') }.should raise_error(ArgumentError) + -> { Encoding.find('dh2dh278d') }.should raise_error(ArgumentError) end # Not sure how to do a better test, since locale depends on weird platform-specific stuff 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 diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb index 5a62d3f346..7227581fb9 100644 --- a/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb +++ b/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb @@ -3,7 +3,7 @@ require_relative '../../../spec_helper' ruby_version_is "2.6" do describe "Enumerator::ArithmeticSequence.new" do it "is not defined" do - lambda { + -> { Enumerator::ArithmeticSequence.new }.should raise_error(NoMethodError) end @@ -11,7 +11,7 @@ ruby_version_is "2.6" do describe "Enumerator::ArithmeticSequence.allocate" do it "is not defined" do - lambda { + -> { Enumerator::ArithmeticSequence.allocate }.should raise_error(TypeError, 'allocator undefined for Enumerator::ArithmeticSequence') end diff --git a/spec/ruby/core/enumerator/chain/initialize_spec.rb b/spec/ruby/core/enumerator/chain/initialize_spec.rb index 4ede1b8670..e5aa32fd02 100644 --- a/spec/ruby/core/enumerator/chain/initialize_spec.rb +++ b/spec/ruby/core/enumerator/chain/initialize_spec.rb @@ -24,7 +24,7 @@ ruby_version_is "2.6" do describe "on frozen instance" do it "raises a RuntimeError" do - lambda { + -> { @uninitialized.freeze.send(:initialize) }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerator/chain/rewind_spec.rb b/spec/ruby/core/enumerator/chain/rewind_spec.rb index c6b82c831f..951b364f07 100644 --- a/spec/ruby/core/enumerator/chain/rewind_spec.rb +++ b/spec/ruby/core/enumerator/chain/rewind_spec.rb @@ -36,7 +36,7 @@ ruby_version_is "2.6" do @obj.should_not_receive(:rewind) @second.should_receive(:rewind).and_raise(RuntimeError) @enum.each {} - lambda { @enum.rewind }.should raise_error(RuntimeError) + -> { @enum.rewind }.should raise_error(RuntimeError) end it "calls rewind only for objects that have actually been iterated on" do @@ -46,7 +46,7 @@ ruby_version_is "2.6" do @obj.should_receive(:rewind) @second.should_not_receive(:rewind) - lambda { @enum.each {} }.should raise_error(RuntimeError) + -> { @enum.each {} }.should raise_error(RuntimeError) @enum.rewind end end diff --git a/spec/ruby/core/enumerator/each_spec.rb b/spec/ruby/core/enumerator/each_spec.rb index f66951851e..d88c09cdb5 100644 --- a/spec/ruby/core/enumerator/each_spec.rb +++ b/spec/ruby/core/enumerator/each_spec.rb @@ -49,7 +49,7 @@ describe "Enumerator#each" do it "raises a NoMethodError if the object doesn't respond to #each" do enum = Object.new.to_enum - lambda do + -> do enum.each { |e| e } end.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/enumerator/each_with_index_spec.rb b/spec/ruby/core/enumerator/each_with_index_spec.rb index 7332fd628b..96e53a2804 100644 --- a/spec/ruby/core/enumerator/each_with_index_spec.rb +++ b/spec/ruby/core/enumerator/each_with_index_spec.rb @@ -14,7 +14,7 @@ describe "Enumerator#each_with_index" do end it "raises an ArgumentError if passed extra arguments" do - lambda do + -> do [1].to_enum.each_with_index(:glark) end.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/enumerator/feed_spec.rb b/spec/ruby/core/enumerator/feed_spec.rb index 90f0af8f14..e387c6cd39 100644 --- a/spec/ruby/core/enumerator/feed_spec.rb +++ b/spec/ruby/core/enumerator/feed_spec.rb @@ -39,14 +39,14 @@ describe "Enumerator#feed" do it "raises a TypeError if called more than once without advancing the enumerator" do @enum.feed :a @enum.next - lambda { @enum.feed :b }.should raise_error(TypeError) + -> { @enum.feed :b }.should raise_error(TypeError) end it "sets the return value of Yielder#yield" do enum = Enumerator.new { |y| ScratchPad << y.yield } enum.next enum.feed :a - lambda { enum.next }.should raise_error(StopIteration) + -> { enum.next }.should raise_error(StopIteration) ScratchPad.recorded.should == [:a] end end diff --git a/spec/ruby/core/enumerator/generator/each_spec.rb b/spec/ruby/core/enumerator/generator/each_spec.rb index cbdf863bec..a43805dd16 100644 --- a/spec/ruby/core/enumerator/generator/each_spec.rb +++ b/spec/ruby/core/enumerator/generator/each_spec.rb @@ -21,7 +21,7 @@ describe "Enumerator::Generator#each" do end it "raises a LocalJumpError if no block given" do - lambda { @generator.each }.should raise_error(LocalJumpError) + -> { @generator.each }.should raise_error(LocalJumpError) end it "returns the block returned value" do diff --git a/spec/ruby/core/enumerator/generator/initialize_spec.rb b/spec/ruby/core/enumerator/generator/initialize_spec.rb index 38da37a479..f75c7d6f26 100644 --- a/spec/ruby/core/enumerator/generator/initialize_spec.rb +++ b/spec/ruby/core/enumerator/generator/initialize_spec.rb @@ -18,7 +18,7 @@ describe "Enumerator::Generator#initialize" do describe "on frozen instance" do it "raises a RuntimeError" do - lambda { + -> { @uninitialized.freeze.send(:initialize) {} }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerator/initialize_spec.rb b/spec/ruby/core/enumerator/initialize_spec.rb index 1305f150dc..53bf5d4ef2 100644 --- a/spec/ruby/core/enumerator/initialize_spec.rb +++ b/spec/ruby/core/enumerator/initialize_spec.rb @@ -48,12 +48,12 @@ describe "Enumerator#initialize" do end it "sets size to the given size if the given size is a Proc" do - @uninitialized.send(:initialize, lambda { 200 }) {}.size.should == 200 + @uninitialized.send(:initialize, -> { 200 }) {}.size.should == 200 end describe "on frozen instance" do it "raises a RuntimeError" do - lambda { + -> { @uninitialized.freeze.send(:initialize) {} }.should raise_error(RuntimeError) end diff --git a/spec/ruby/core/enumerator/lazy/drop_while_spec.rb b/spec/ruby/core/enumerator/lazy/drop_while_spec.rb index 6f6472e393..4f6e366f88 100644 --- a/spec/ruby/core/enumerator/lazy/drop_while_spec.rb +++ b/spec/ruby/core/enumerator/lazy/drop_while_spec.rb @@ -40,7 +40,7 @@ describe "Enumerator::Lazy#drop_while" do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.drop_while }.should raise_error(ArgumentError) + -> { @yieldsmixed.drop_while }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/grep_spec.rb b/spec/ruby/core/enumerator/lazy/grep_spec.rb index e759cc4a2c..e67686c9a3 100644 --- a/spec/ruby/core/enumerator/lazy/grep_spec.rb +++ b/spec/ruby/core/enumerator/lazy/grep_spec.rb @@ -33,6 +33,39 @@ describe "Enumerator::Lazy#grep" do Enumerator::Lazy.new(Object.new, 100) {}.grep(Object).size.should == nil end + it "sets $~ in the block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep(/b/) { |e| + e.should == "abc" + $&.should == "b" + }.force + + # Set by the failed match of "def" + $~.should == nil + end + + it "sets $~ in the next block with each" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep(/b/).each { |e| + e.should == "abc" + $&.should == "b" + } + + # Set by the failed match of "def" + $~.should == nil + end + + it "sets $~ in the next block with map" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep(/b/).map { |e| + e.should == "abc" + $&.should == "b" + }.force + + # Set by the failed match of "def" + $~.should == nil + end + describe "when the returned lazy enumerator is evaluated by Enumerable#first" do it "stops after specified times when not given a block" do (0..Float::INFINITY).lazy.grep(Integer).first(3).should == [0, 1, 2] diff --git a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb index 13d474a8c4..67173021bb 100644 --- a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb +++ b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb @@ -31,6 +31,39 @@ describe "Enumerator::Lazy#grep_v" do Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).size.should == nil end + it "sets $~ in the block" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep_v(/e/) { |e| + e.should == "abc" + $~.should == nil + }.force + + # Set by the match of "def" + $&.should == "e" + end + + it "sets $~ in the next block with each" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep_v(/e/).each { |e| + e.should == "abc" + $~.should == nil + } + + # Set by the match of "def" + $&.should == "e" + end + + it "sets $~ in the next block with map" do + "z" =~ /z/ # Reset $~ + ["abc", "def"].lazy.grep_v(/e/).map { |e| + e.should == "abc" + $~.should == nil + }.force + + # Set by the match of "def" + $&.should == "e" + end + describe "when the returned lazy enumerator is evaluated by Enumerable#first" do it "stops after specified times when not given a block" do (0..Float::INFINITY).lazy.grep_v(3..5).first(3).should == [0, 1, 2] diff --git a/spec/ruby/core/enumerator/lazy/initialize_spec.rb b/spec/ruby/core/enumerator/lazy/initialize_spec.rb index 9fa6eff35a..88c66530b9 100644 --- a/spec/ruby/core/enumerator/lazy/initialize_spec.rb +++ b/spec/ruby/core/enumerator/lazy/initialize_spec.rb @@ -48,16 +48,16 @@ describe "Enumerator::Lazy#initialize" do end it "sets given size to own size if the given size is a Proc" do - @uninitialized.send(:initialize, @receiver, lambda { 200 }) {}.size.should == 200 + @uninitialized.send(:initialize, @receiver, -> { 200 }) {}.size.should == 200 end it "raises an ArgumentError when block is not given" do - lambda { @uninitialized.send :initialize, @receiver }.should raise_error(ArgumentError) + -> { @uninitialized.send :initialize, @receiver }.should raise_error(ArgumentError) end describe "on frozen instance" do it "raises a RuntimeError" do - lambda { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError) + -> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError) end end end diff --git a/spec/ruby/core/enumerator/lazy/reject_spec.rb b/spec/ruby/core/enumerator/lazy/reject_spec.rb index 03444b471f..0e1632d667 100644 --- a/spec/ruby/core/enumerator/lazy/reject_spec.rb +++ b/spec/ruby/core/enumerator/lazy/reject_spec.rb @@ -52,7 +52,7 @@ describe "Enumerator::Lazy#reject" do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.reject }.should raise_error(ArgumentError) + -> { @yieldsmixed.reject }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb b/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb index e8ee4b6940..00d7941a61 100644 --- a/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb +++ b/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb @@ -46,7 +46,7 @@ describe :enumerator_lazy_collect_concat, shared: true do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.send(@method) }.should raise_error(ArgumentError) + -> { @yieldsmixed.send(@method) }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/shared/select.rb b/spec/ruby/core/enumerator/lazy/shared/select.rb index 39074408ee..50a00bcbf4 100644 --- a/spec/ruby/core/enumerator/lazy/shared/select.rb +++ b/spec/ruby/core/enumerator/lazy/shared/select.rb @@ -40,7 +40,7 @@ describe :enumerator_lazy_select, shared: true do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.send(@method) }.should raise_error(ArgumentError) + -> { @yieldsmixed.send(@method) }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/take_while_spec.rb b/spec/ruby/core/enumerator/lazy/take_while_spec.rb index 412ff76787..bcea0b1419 100644 --- a/spec/ruby/core/enumerator/lazy/take_while_spec.rb +++ b/spec/ruby/core/enumerator/lazy/take_while_spec.rb @@ -40,7 +40,7 @@ describe "Enumerator::Lazy#take_while" do end it "raises an ArgumentError when not given a block" do - lambda { @yieldsmixed.take_while }.should raise_error(ArgumentError) + -> { @yieldsmixed.take_while }.should raise_error(ArgumentError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/lazy/zip_spec.rb b/spec/ruby/core/enumerator/lazy/zip_spec.rb index a28a7f5d5e..5a828c1dcc 100644 --- a/spec/ruby/core/enumerator/lazy/zip_spec.rb +++ b/spec/ruby/core/enumerator/lazy/zip_spec.rb @@ -44,7 +44,7 @@ describe "Enumerator::Lazy#zip" do end it "raises a TypeError if arguments contain non-list object" do - lambda { @yieldsmixed.zip [], Object.new, [] }.should raise_error(TypeError) + -> { @yieldsmixed.zip [], Object.new, [] }.should raise_error(TypeError) end describe "on a nested Lazy" do diff --git a/spec/ruby/core/enumerator/next_spec.rb b/spec/ruby/core/enumerator/next_spec.rb index e0d3c0a39b..3e9ed8b015 100644 --- a/spec/ruby/core/enumerator/next_spec.rb +++ b/spec/ruby/core/enumerator/next_spec.rb @@ -13,14 +13,14 @@ describe "Enumerator#next" do it "raises a StopIteration exception at the end of the stream" do 3.times { @enum.next } - lambda { @enum.next }.should raise_error(StopIteration) + -> { @enum.next }.should raise_error(StopIteration) end it "cannot be called again until the enumerator is rewound" do 3.times { @enum.next } - lambda { @enum.next }.should raise_error(StopIteration) - lambda { @enum.next }.should raise_error(StopIteration) - lambda { @enum.next }.should raise_error(StopIteration) + -> { @enum.next }.should raise_error(StopIteration) + -> { @enum.next }.should raise_error(StopIteration) + -> { @enum.next }.should raise_error(StopIteration) @enum.rewind @enum.next.should == 1 end diff --git a/spec/ruby/core/enumerator/next_values_spec.rb b/spec/ruby/core/enumerator/next_values_spec.rb index 8b57332c28..201b5d323f 100644 --- a/spec/ruby/core/enumerator/next_values_spec.rb +++ b/spec/ruby/core/enumerator/next_values_spec.rb @@ -50,6 +50,6 @@ describe "Enumerator#next_values" do it "raises StopIteration if called on a finished enumerator" do 7.times { @e.next } - lambda { @e.next_values }.should raise_error(StopIteration) + -> { @e.next_values }.should raise_error(StopIteration) end end diff --git a/spec/ruby/core/enumerator/peek_spec.rb b/spec/ruby/core/enumerator/peek_spec.rb index 0e4f60893d..2334385437 100644 --- a/spec/ruby/core/enumerator/peek_spec.rb +++ b/spec/ruby/core/enumerator/peek_spec.rb @@ -31,6 +31,6 @@ describe "Enumerator#peek" do it "raises StopIteration if called on a finished enumerator" do 5.times { @e.next } - lambda { @e.peek }.should raise_error(StopIteration) + -> { @e.peek }.should raise_error(StopIteration) end end diff --git a/spec/ruby/core/enumerator/peek_values_spec.rb b/spec/ruby/core/enumerator/peek_values_spec.rb index 5c81b4e529..7865546515 100644 --- a/spec/ruby/core/enumerator/peek_values_spec.rb +++ b/spec/ruby/core/enumerator/peek_values_spec.rb @@ -52,6 +52,6 @@ describe "Enumerator#peek_values" do it "raises StopIteration if called on a finished enumerator" do 7.times { @e.next } - lambda { @e.peek_values }.should raise_error(StopIteration) + -> { @e.peek_values }.should raise_error(StopIteration) end end diff --git a/spec/ruby/core/enumerator/rewind_spec.rb b/spec/ruby/core/enumerator/rewind_spec.rb index 2a83b7c6ee..a105f2c619 100644 --- a/spec/ruby/core/enumerator/rewind_spec.rb +++ b/spec/ruby/core/enumerator/rewind_spec.rb @@ -49,7 +49,7 @@ describe "Enumerator#rewind" do obj = mock('rewinder') enum = obj.to_enum obj.should_receive(:each).at_most(1) - lambda { enum.rewind.should == enum }.should_not raise_error + -> { enum.rewind.should == enum }.should_not raise_error end end diff --git a/spec/ruby/core/enumerator/size_spec.rb b/spec/ruby/core/enumerator/size_spec.rb index 5729b9303d..6accd26a4e 100644 --- a/spec/ruby/core/enumerator/size_spec.rb +++ b/spec/ruby/core/enumerator/size_spec.rb @@ -11,7 +11,7 @@ describe "Enumerator#size" do it "returns returning value from size.call if set size is a Proc" do base_size = 100 - enum = Enumerator.new(lambda { base_size + 1 }) {} + enum = Enumerator.new(-> { base_size + 1 }) {} base_size = 200 enum.size.should == 201 base_size = 300 diff --git a/spec/ruby/core/enumerator/with_index_spec.rb b/spec/ruby/core/enumerator/with_index_spec.rb index ca9f5a133e..ac37cee508 100644 --- a/spec/ruby/core/enumerator/with_index_spec.rb +++ b/spec/ruby/core/enumerator/with_index_spec.rb @@ -14,13 +14,13 @@ describe "Enumerator#with_index" do end it "accepts an optional argument when given a block" do - lambda do + -> do @enum.with_index(1) { |f| f} end.should_not raise_error(ArgumentError) end it "accepts an optional argument when not given a block" do - lambda do + -> do @enum.with_index(1) end.should_not raise_error(ArgumentError) end @@ -36,7 +36,7 @@ describe "Enumerator#with_index" do end it "raises a TypeError when the argument cannot be converted to numeric" do - lambda do + -> do @enum.with_index('1') {|*i| i} end.should raise_error(TypeError) end diff --git a/spec/ruby/core/env/fetch_spec.rb b/spec/ruby/core/env/fetch_spec.rb index c8a11430ab..eeaf290cf0 100644 --- a/spec/ruby/core/env/fetch_spec.rb +++ b/spec/ruby/core/env/fetch_spec.rb @@ -9,11 +9,11 @@ describe "ENV.fetch" do end it "raises a TypeError if the key is not a String" do - lambda { ENV.fetch :should_never_be_set }.should raise_error(TypeError) + -> { ENV.fetch :should_never_be_set }.should raise_error(TypeError) end context "when the key is not found" do - it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, ENV + it_behaves_like :key_error, -> obj, key { obj.fetch(key) }, ENV it "formats the object with #inspect in the KeyError message" do -> { @@ -31,7 +31,7 @@ describe "ENV.fetch" do end it "warns on block and default parameter given" do - lambda do + -> do ENV.fetch("should_never_be_set", "default") { 1 }.should == 1 end.should complain(/block supersedes default value argument/) end diff --git a/spec/ruby/core/env/reject_spec.rb b/spec/ruby/core/env/reject_spec.rb index 409efa1385..1026c2f451 100644 --- a/spec/ruby/core/env/reject_spec.rb +++ b/spec/ruby/core/env/reject_spec.rb @@ -29,7 +29,7 @@ describe "ENV.reject!" do orig = ENV.to_hash begin ENV.clear - lambda { ENV.reject! }.should_not raise_error(LocalJumpError) + -> { ENV.reject! }.should_not raise_error(LocalJumpError) ensure ENV.replace orig end @@ -67,7 +67,7 @@ describe "ENV.reject" do orig = ENV.to_hash begin ENV.clear - lambda { ENV.reject }.should_not raise_error(LocalJumpError) + -> { ENV.reject }.should_not raise_error(LocalJumpError) ensure ENV.replace orig end diff --git a/spec/ruby/core/env/shared/store.rb b/spec/ruby/core/env/shared/store.rb index 4949ca8c73..6ae91ef8fc 100644 --- a/spec/ruby/core/env/shared/store.rb +++ b/spec/ruby/core/env/shared/store.rb @@ -34,19 +34,19 @@ describe :env_store, shared: true do end it "raises TypeError when the key is not coercible to String" do - lambda { ENV.send(@method, Object.new, "bar") }.should raise_error(TypeError) + -> { ENV.send(@method, Object.new, "bar") }.should raise_error(TypeError) end it "raises TypeError when the value is not coercible to String" do - lambda { ENV.send(@method, "foo", Object.new) }.should raise_error(TypeError) + -> { ENV.send(@method, "foo", Object.new) }.should raise_error(TypeError) end it "raises Errno::EINVAL when the key contains the '=' character" do - lambda { ENV.send(@method, "foo=", "bar") }.should raise_error(Errno::EINVAL) + -> { ENV.send(@method, "foo=", "bar") }.should raise_error(Errno::EINVAL) end it "raises Errno::EINVAL when the key is an empty string" do - lambda { ENV.send(@method, "", "bar") }.should raise_error(Errno::EINVAL) + -> { ENV.send(@method, "", "bar") }.should raise_error(Errno::EINVAL) end it "does nothing when the key is not a valid environment variable key and the value is nil" do diff --git a/spec/ruby/core/exception/dup_spec.rb b/spec/ruby/core/exception/dup_spec.rb index c7fcd280dd..edd54bfb37 100644 --- a/spec/ruby/core/exception/dup_spec.rb +++ b/spec/ruby/core/exception/dup_spec.rb @@ -20,7 +20,7 @@ describe "Exception#dup" do it "does not copy singleton methods" do def @obj.special() :the_one end dup = @obj.dup - lambda { dup.special }.should raise_error(NameError) + -> { dup.special }.should raise_error(NameError) end it "does not copy modules included in the singleton class" do @@ -29,7 +29,7 @@ describe "Exception#dup" do end dup = @obj.dup - lambda { dup.repr }.should raise_error(NameError) + -> { dup.repr }.should raise_error(NameError) end it "does not copy constants defined in the singleton class" do @@ -38,7 +38,7 @@ describe "Exception#dup" do end dup = @obj.dup - lambda { class << dup; CLONE; end }.should raise_error(NameError) + -> { class << dup; CLONE; end }.should raise_error(NameError) end it "does copy the message" do diff --git a/spec/ruby/core/exception/result_spec.rb b/spec/ruby/core/exception/result_spec.rb index 62247e9d85..5ba26ebab1 100644 --- a/spec/ruby/core/exception/result_spec.rb +++ b/spec/ruby/core/exception/result_spec.rb @@ -20,7 +20,7 @@ describe "StopIteration#result" do it "returns the method-returned-object from an Enumerator" do @enum.next @enum.next - lambda { @enum.next }.should( + -> { @enum.next }.should( raise_error(StopIteration) do |error| error.result.should equal(:method_returned) end diff --git a/spec/ruby/core/exception/set_backtrace_spec.rb b/spec/ruby/core/exception/set_backtrace_spec.rb index 4ebe574dcb..ba2e1bf7aa 100644 --- a/spec/ruby/core/exception/set_backtrace_spec.rb +++ b/spec/ruby/core/exception/set_backtrace_spec.rb @@ -36,21 +36,21 @@ describe "Exception#set_backtrace" do it "raises a TypeError when passed a Symbol" do err = RuntimeError.new - lambda { err.set_backtrace :unhappy }.should raise_error(TypeError) + -> { err.set_backtrace :unhappy }.should raise_error(TypeError) end it "raises a TypeError when the Array contains a Symbol" do err = RuntimeError.new - lambda { err.set_backtrace ["String", :unhappy] }.should raise_error(TypeError) + -> { err.set_backtrace ["String", :unhappy] }.should raise_error(TypeError) end it "raises a TypeError when the array contains nil" do err = Exception.new - lambda { err.set_backtrace ["String", nil] }.should raise_error(TypeError) + -> { err.set_backtrace ["String", nil] }.should raise_error(TypeError) end it "raises a TypeError when the argument is a nested array" do err = Exception.new - lambda { err.set_backtrace ["String", ["String"]] }.should raise_error(TypeError) + -> { err.set_backtrace ["String", ["String"]] }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/exception/signal_exception_spec.rb b/spec/ruby/core/exception/signal_exception_spec.rb index 8e2f273a67..e0b30236f7 100644 --- a/spec/ruby/core/exception/signal_exception_spec.rb +++ b/spec/ruby/core/exception/signal_exception_spec.rb @@ -9,7 +9,7 @@ describe "SignalException.new" do end it "raises an exception with an invalid signal number" do - lambda { SignalException.new(100000) }.should raise_error(ArgumentError) + -> { SignalException.new(100000) }.should raise_error(ArgumentError) end it "takes a signal name without SIG prefix as the first argument" do @@ -27,7 +27,7 @@ describe "SignalException.new" do end it "raises an exception with an invalid signal name" do - lambda { SignalException.new("NONEXISTENT") }.should raise_error(ArgumentError) + -> { SignalException.new("NONEXISTENT") }.should raise_error(ArgumentError) end it "takes a signal symbol without SIG prefix as the first argument" do @@ -45,7 +45,7 @@ describe "SignalException.new" do end it "raises an exception with an invalid signal name" do - lambda { SignalException.new(:NONEXISTENT) }.should raise_error(ArgumentError) + -> { SignalException.new(:NONEXISTENT) }.should raise_error(ArgumentError) end it "takes an optional message argument with a signal number" do @@ -56,7 +56,7 @@ describe "SignalException.new" do end it "raises an exception for an optional argument with a signal name" do - lambda { SignalException.new("INT","name") }.should raise_error(ArgumentError) + -> { SignalException.new("INT","name") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/exception/system_call_error_spec.rb b/spec/ruby/core/exception/system_call_error_spec.rb index d9e303bad8..c07c8af72c 100644 --- a/spec/ruby/core/exception/system_call_error_spec.rb +++ b/spec/ruby/core/exception/system_call_error_spec.rb @@ -21,7 +21,7 @@ end describe "SystemCallError.new" do it "requires at least one argument" do - lambda { SystemCallError.new }.should raise_error(ArgumentError) + -> { SystemCallError.new }.should raise_error(ArgumentError) end it "accepts single Fixnum argument as errno" do diff --git a/spec/ruby/core/false/falseclass_spec.rb b/spec/ruby/core/false/falseclass_spec.rb index a944edd348..c018ef2421 100644 --- a/spec/ruby/core/false/falseclass_spec.rb +++ b/spec/ruby/core/false/falseclass_spec.rb @@ -2,13 +2,13 @@ require_relative '../../spec_helper' describe "FalseClass" do it ".allocate raises a TypeError" do - lambda do + -> do FalseClass.allocate end.should raise_error(TypeError) end it ".new is undefined" do - lambda do + -> do FalseClass.new end.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/fiber/new_spec.rb b/spec/ruby/core/fiber/new_spec.rb index c2175cb612..b43c1386be 100644 --- a/spec/ruby/core/fiber/new_spec.rb +++ b/spec/ruby/core/fiber/new_spec.rb @@ -16,7 +16,7 @@ describe "Fiber.new" do end it "raises an ArgumentError if called without a block" do - lambda { Fiber.new }.should raise_error(ArgumentError) + -> { Fiber.new }.should raise_error(ArgumentError) end it "does not invoke the block" do diff --git a/spec/ruby/core/fiber/yield_spec.rb b/spec/ruby/core/fiber/yield_spec.rb index 4e241d5921..b010912c87 100644 --- a/spec/ruby/core/fiber/yield_spec.rb +++ b/spec/ruby/core/fiber/yield_spec.rb @@ -44,6 +44,6 @@ describe "Fiber.yield" do end it "raises a FiberError if called from the root Fiber" do - lambda{ Fiber.yield }.should raise_error(FiberError) + ->{ Fiber.yield }.should raise_error(FiberError) end end diff --git a/spec/ruby/core/file/atime_spec.rb b/spec/ruby/core/file/atime_spec.rb index c791aa6d74..02e8412722 100644 --- a/spec/ruby/core/file/atime_spec.rb +++ b/spec/ruby/core/file/atime_spec.rb @@ -30,7 +30,7 @@ describe "File.atime" do end it "raises an Errno::ENOENT exception if the file is not found" do - lambda { File.atime('a_fake_file') }.should raise_error(Errno::ENOENT) + -> { File.atime('a_fake_file') }.should raise_error(Errno::ENOENT) end it "accepts an object that has a #to_path method" do diff --git a/spec/ruby/core/file/basename_spec.rb b/spec/ruby/core/file/basename_spec.rb index 50365b1125..6d7e432086 100644 --- a/spec/ruby/core/file/basename_spec.rb +++ b/spec/ruby/core/file/basename_spec.rb @@ -105,10 +105,10 @@ describe "File.basename" do end it "raises a TypeError if the arguments are not String types" do - lambda { File.basename(nil) }.should raise_error(TypeError) - lambda { File.basename(1) }.should raise_error(TypeError) - lambda { File.basename("bar.txt", 1) }.should raise_error(TypeError) - lambda { File.basename(true) }.should raise_error(TypeError) + -> { File.basename(nil) }.should raise_error(TypeError) + -> { File.basename(1) }.should raise_error(TypeError) + -> { File.basename("bar.txt", 1) }.should raise_error(TypeError) + -> { File.basename(true) }.should raise_error(TypeError) end it "accepts an object that has a #to_path method" do @@ -116,7 +116,7 @@ describe "File.basename" do end it "raises an ArgumentError if passed more than two arguments" do - lambda { File.basename('bar.txt', '.txt', '.txt') }.should raise_error(ArgumentError) + -> { File.basename('bar.txt', '.txt', '.txt') }.should raise_error(ArgumentError) end # specific to MS Windows diff --git a/spec/ruby/core/file/birthtime_spec.rb b/spec/ruby/core/file/birthtime_spec.rb index cab749f7b4..755601df64 100644 --- a/spec/ruby/core/file/birthtime_spec.rb +++ b/spec/ruby/core/file/birthtime_spec.rb @@ -20,13 +20,13 @@ describe "File.birthtime" do end it "raises an Errno::ENOENT exception if the file is not found" do - lambda { File.birthtime('bogus') }.should raise_error(Errno::ENOENT) + -> { File.birthtime('bogus') }.should raise_error(Errno::ENOENT) end end platform_is :openbsd do it "raises an NotImplementedError" do - lambda { File.birthtime(@file) }.should raise_error(NotImplementedError) + -> { File.birthtime(@file) }.should raise_error(NotImplementedError) end end @@ -52,7 +52,7 @@ describe "File#birthtime" do platform_is :openbsd do it "raises an NotImplementedError" do - lambda { @file.birthtime }.should raise_error(NotImplementedError) + -> { @file.birthtime }.should raise_error(NotImplementedError) end end diff --git a/spec/ruby/core/file/chmod_spec.rb b/spec/ruby/core/file/chmod_spec.rb index 6c4e1099e3..86171691f6 100644 --- a/spec/ruby/core/file/chmod_spec.rb +++ b/spec/ruby/core/file/chmod_spec.rb @@ -106,11 +106,11 @@ describe "File.chmod" do end it "throws a TypeError if the given path is not coercable into a string" do - lambda { File.chmod(0, []) }.should raise_error(TypeError) + -> { File.chmod(0, []) }.should raise_error(TypeError) end it "raises an error for a non existent path" do - lambda { + -> { File.chmod(0644, "#{@file}.not.existing") }.should raise_error(Errno::ENOENT) end diff --git a/spec/ruby/core/file/chown_spec.rb b/spec/ruby/core/file/chown_spec.rb index 512d5b4738..8cc8f0d04b 100644 --- a/spec/ruby/core/file/chown_spec.rb +++ b/spec/ruby/core/file/chown_spec.rb @@ -66,7 +66,7 @@ describe "File.chown" do platform_is_not :windows do it "raises an error for a non existent path" do - lambda { + -> { File.chown(nil, nil, "#{@fname}_not_existing") }.should raise_error(Errno::ENOENT) end diff --git a/spec/ruby/core/file/ctime_spec.rb b/spec/ruby/core/file/ctime_spec.rb index 5753e0d90e..68a9fa43cb 100644 --- a/spec/ruby/core/file/ctime_spec.rb +++ b/spec/ruby/core/file/ctime_spec.rb @@ -30,7 +30,7 @@ describe "File.ctime" do end it "raises an Errno::ENOENT exception if the file is not found" do - lambda { File.ctime('bogus') }.should raise_error(Errno::ENOENT) + -> { File.ctime('bogus') }.should raise_error(Errno::ENOENT) end end diff --git a/spec/ruby/core/file/dirname_spec.rb b/spec/ruby/core/file/dirname_spec.rb index 0447a4e471..2ef04a7b64 100644 --- a/spec/ruby/core/file/dirname_spec.rb +++ b/spec/ruby/core/file/dirname_spec.rb @@ -72,10 +72,10 @@ describe "File.dirname" do end it "raises a TypeError if not passed a String type" do - lambda { File.dirname(nil) }.should raise_error(TypeError) - lambda { File.dirname(0) }.should raise_error(TypeError) - lambda { File.dirname(true) }.should raise_error(TypeError) - lambda { File.dirname(false) }.should raise_error(TypeError) + -> { File.dirname(nil) }.should raise_error(TypeError) + -> { File.dirname(0) }.should raise_error(TypeError) + -> { File.dirname(true) }.should raise_error(TypeError) + -> { File.dirname(false) }.should raise_error(TypeError) end # Windows specific tests diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb index aa6a3c9c63..88078645ab 100644 --- a/spec/ruby/core/file/expand_path_spec.rb +++ b/spec/ruby/core/file/expand_path_spec.rb @@ -92,7 +92,7 @@ describe "File.expand_path" do end it "raises an ArgumentError if the path is not valid" do - lambda { File.expand_path("~a_not_existing_user") }.should raise_error(ArgumentError) + -> { File.expand_path("~a_not_existing_user") }.should raise_error(ArgumentError) end it "expands ~ENV['USER'] to the user's home directory" do @@ -117,9 +117,9 @@ describe "File.expand_path" do end it "raises a TypeError if not passed a String type" do - lambda { File.expand_path(1) }.should raise_error(TypeError) - lambda { File.expand_path(nil) }.should raise_error(TypeError) - lambda { File.expand_path(true) }.should raise_error(TypeError) + -> { File.expand_path(1) }.should raise_error(TypeError) + -> { File.expand_path(nil) }.should raise_error(TypeError) + -> { File.expand_path(true) }.should raise_error(TypeError) end platform_is_not :windows do @@ -159,7 +159,7 @@ describe "File.expand_path" do platform_is_not :windows do it "raises an Encoding::CompatibilityError if the external encoding is not compatible" do Encoding.default_external = Encoding::UTF_16BE - lambda { File.expand_path("./a") }.should raise_error(Encoding::CompatibilityError) + -> { File.expand_path("./a") }.should raise_error(Encoding::CompatibilityError) end end @@ -244,7 +244,7 @@ platform_is_not :windows do it "raises an ArgumentError when passed '~' if HOME == ''" do ENV["HOME"] = "" - lambda { File.expand_path("~") }.should raise_error(ArgumentError) + -> { File.expand_path("~") }.should raise_error(ArgumentError) end end @@ -259,7 +259,7 @@ platform_is_not :windows do it "raises an ArgumentError" do ENV["HOME"] = "non-absolute" - lambda { File.expand_path("~") }.should raise_error(ArgumentError, 'non-absolute home') + -> { File.expand_path("~") }.should raise_error(ArgumentError, 'non-absolute home') end end end diff --git a/spec/ruby/core/file/extname_spec.rb b/spec/ruby/core/file/extname_spec.rb index 7632b6adc0..358690b44a 100644 --- a/spec/ruby/core/file/extname_spec.rb +++ b/spec/ruby/core/file/extname_spec.rb @@ -33,15 +33,15 @@ describe "File.extname" do end it "raises a TypeError if not passed a String type" do - lambda { File.extname(nil) }.should raise_error(TypeError) - lambda { File.extname(0) }.should raise_error(TypeError) - lambda { File.extname(true) }.should raise_error(TypeError) - lambda { File.extname(false) }.should raise_error(TypeError) + -> { File.extname(nil) }.should raise_error(TypeError) + -> { File.extname(0) }.should raise_error(TypeError) + -> { File.extname(true) }.should raise_error(TypeError) + -> { File.extname(false) }.should raise_error(TypeError) end it "raises an ArgumentError if not passed one argument" do - lambda { File.extname }.should raise_error(ArgumentError) - lambda { File.extname("foo.bar", "foo.baz") }.should raise_error(ArgumentError) + -> { File.extname }.should raise_error(ArgumentError) + -> { File.extname("foo.bar", "foo.baz") }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/file/flock_spec.rb b/spec/ruby/core/file/flock_spec.rb index 6990915a65..751e99d994 100644 --- a/spec/ruby/core/file/flock_spec.rb +++ b/spec/ruby/core/file/flock_spec.rb @@ -92,13 +92,13 @@ platform_is :solaris do end it "fails with EBADF acquiring exclusive lock on read-only File" do - lambda do + -> do @read_file.flock File::LOCK_EX end.should raise_error(Errno::EBADF) end it "fails with EBADF acquiring shared lock on read-only File" do - lambda do + -> do @write_file.flock File::LOCK_SH end.should raise_error(Errno::EBADF) end diff --git a/spec/ruby/core/file/ftype_spec.rb b/spec/ruby/core/file/ftype_spec.rb index e92f04da2c..20e9af7e5f 100644 --- a/spec/ruby/core/file/ftype_spec.rb +++ b/spec/ruby/core/file/ftype_spec.rb @@ -7,12 +7,12 @@ describe "File.ftype" do end it "raises ArgumentError if not given exactly one filename" do - lambda { File.ftype }.should raise_error(ArgumentError) - lambda { File.ftype('blah', 'bleh') }.should raise_error(ArgumentError) + -> { File.ftype }.should raise_error(ArgumentError) + -> { File.ftype('blah', 'bleh') }.should raise_error(ArgumentError) end it "raises Errno::ENOENT if the file is not valid" do - l = lambda { File.ftype("/#{$$}#{Time.now.to_f}") } + l = -> { File.ftype("/#{$$}#{Time.now.to_f}") } l.should raise_error(Errno::ENOENT) end diff --git a/spec/ruby/core/file/join_spec.rb b/spec/ruby/core/file/join_spec.rb index 333b566c3d..f1eab02de0 100644 --- a/spec/ruby/core/file/join_spec.rb +++ b/spec/ruby/core/file/join_spec.rb @@ -104,15 +104,15 @@ describe "File.join" do it "raises an ArgumentError if passed a recursive array" do a = ["a"] a << a - lambda { File.join a }.should raise_error(ArgumentError) + -> { File.join a }.should raise_error(ArgumentError) end it "raises a TypeError exception when args are nil" do - lambda { File.join nil }.should raise_error(TypeError) + -> { File.join nil }.should raise_error(TypeError) end it "calls #to_str" do - lambda { File.join(mock('x')) }.should raise_error(TypeError) + -> { File.join(mock('x')) }.should raise_error(TypeError) bin = mock("bin") bin.should_receive(:to_str).exactly(:twice).and_return("bin") @@ -129,7 +129,7 @@ describe "File.join" do end it "calls #to_path" do - lambda { File.join(mock('x')) }.should raise_error(TypeError) + -> { File.join(mock('x')) }.should raise_error(TypeError) bin = mock("bin") bin.should_receive(:to_path).exactly(:twice).and_return("bin") diff --git a/spec/ruby/core/file/lchmod_spec.rb b/spec/ruby/core/file/lchmod_spec.rb index 7be09a05ef..9490459a02 100644 --- a/spec/ruby/core/file/lchmod_spec.rb +++ b/spec/ruby/core/file/lchmod_spec.rb @@ -36,7 +36,7 @@ describe "File.lchmod" do end it "raises a NotImplementedError when called" do - lambda { File.lchmod 0 }.should raise_error(NotImplementedError) + -> { File.lchmod 0 }.should raise_error(NotImplementedError) end end end diff --git a/spec/ruby/core/file/link_spec.rb b/spec/ruby/core/file/link_spec.rb index 4e186c6076..11d4c8d25b 100644 --- a/spec/ruby/core/file/link_spec.rb +++ b/spec/ruby/core/file/link_spec.rb @@ -22,18 +22,18 @@ describe "File.link" do it "raises an Errno::EEXIST if the target already exists" do File.link(@file, @link) - lambda { File.link(@file, @link) }.should raise_error(Errno::EEXIST) + -> { File.link(@file, @link) }.should raise_error(Errno::EEXIST) end it "raises an ArgumentError if not passed two arguments" do - lambda { File.link }.should raise_error(ArgumentError) - lambda { File.link(@file) }.should raise_error(ArgumentError) - lambda { File.link(@file, @link, @file) }.should raise_error(ArgumentError) + -> { File.link }.should raise_error(ArgumentError) + -> { File.link(@file) }.should raise_error(ArgumentError) + -> { File.link(@file, @link, @file) }.should raise_error(ArgumentError) end it "raises a TypeError if not passed String types" do - lambda { File.link(@file, nil) }.should raise_error(TypeError) - lambda { File.link(@file, 1) }.should raise_error(TypeError) + -> { File.link(@file, nil) }.should raise_error(TypeError) + -> { File.link(@file, 1) }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/file/mkfifo_spec.rb b/spec/ruby/core/file/mkfifo_spec.rb index a6db87a12e..19298c967c 100644 --- a/spec/ruby/core/file/mkfifo_spec.rb +++ b/spec/ruby/core/file/mkfifo_spec.rb @@ -19,13 +19,13 @@ describe "File.mkfifo" do context "when path passed is not a String value" do it "raises a TypeError" do - lambda { File.mkfifo(:"/tmp/fifo") }.should raise_error(TypeError) + -> { File.mkfifo(:"/tmp/fifo") }.should raise_error(TypeError) end end context "when path does not exist" do it "raises an Errno::ENOENT exception" do - lambda { File.mkfifo("/bogus/path") }.should raise_error(Errno::ENOENT) + -> { File.mkfifo("/bogus/path") }.should raise_error(Errno::ENOENT) end end diff --git a/spec/ruby/core/file/mtime_spec.rb b/spec/ruby/core/file/mtime_spec.rb index 833f759eaa..1941e2ff85 100644 --- a/spec/ruby/core/file/mtime_spec.rb +++ b/spec/ruby/core/file/mtime_spec.rb @@ -29,7 +29,7 @@ describe "File.mtime" do end it "raises an Errno::ENOENT exception if the file is not found" do - lambda { File.mtime('bogus') }.should raise_error(Errno::ENOENT) + -> { File.mtime('bogus') }.should raise_error(Errno::ENOENT) end end diff --git a/spec/ruby/core/file/new_spec.rb b/spec/ruby/core/file/new_spec.rb index 3bb2712ada..e99f6ba72b 100644 --- a/spec/ruby/core/file/new_spec.rb +++ b/spec/ruby/core/file/new_spec.rb @@ -44,7 +44,7 @@ describe "File.new" do rm_r @file begin f = File.new(@file, "w", 0444) - lambda { f.puts("test") }.should_not raise_error(IOError) + -> { f.puts("test") }.should_not raise_error(IOError) ensure f.close end @@ -85,7 +85,7 @@ describe "File.new" do end it "raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do - lambda { @fh = File.new(@file, File::CREAT|File::EXCL) }.should raise_error(Errno::EEXIST) + -> { @fh = File.new(@file, File::CREAT|File::EXCL) }.should raise_error(Errno::EEXIST) end it "creates a new file when use File::WRONLY|File::APPEND mode" do @@ -134,22 +134,22 @@ describe "File.new" do end it "raises a TypeError if the first parameter can't be coerced to a string" do - lambda { File.new(true) }.should raise_error(TypeError) - lambda { File.new(false) }.should raise_error(TypeError) + -> { File.new(true) }.should raise_error(TypeError) + -> { File.new(false) }.should raise_error(TypeError) end it "raises a TypeError if the first parameter is nil" do - lambda { File.new(nil) }.should raise_error(TypeError) + -> { File.new(nil) }.should raise_error(TypeError) end it "raises an Errno::EBADF if the first parameter is an invalid file descriptor" do - lambda { File.new(-1) }.should raise_error(Errno::EBADF) + -> { File.new(-1) }.should raise_error(Errno::EBADF) end platform_is_not :windows do it "can't alter mode or permissions when opening a file" do @fh = File.new(@file) - lambda { + -> { f = File.new(@fh.fileno, @flags) f.autoclose = false }.should raise_error(Errno::EINVAL) diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb index 59c13f08ed..d946fc5ecf 100644 --- a/spec/ruby/core/file/open_spec.rb +++ b/spec/ruby/core/file/open_spec.rb @@ -38,7 +38,7 @@ describe "File.open" do end it "propagates non-StandardErrors produced by close" do - lambda { + -> { File.open(@file, 'r') { |f| FileSpecs.make_closer f, Exception } }.should raise_error(Exception) @@ -46,7 +46,7 @@ describe "File.open" do end it "propagates StandardErrors produced by close" do - lambda { + -> { File.open(@file, 'r') { |f| FileSpecs.make_closer f, StandardError } }.should raise_error(StandardError) @@ -166,40 +166,40 @@ describe "File.open" do end it "opens a file that no exists when use File::WRONLY mode" do - lambda { File.open(@nonexistent, File::WRONLY) }.should raise_error(Errno::ENOENT) + -> { File.open(@nonexistent, File::WRONLY) }.should raise_error(Errno::ENOENT) end it "opens a file that no exists when use File::RDONLY mode" do - lambda { File.open(@nonexistent, File::RDONLY) }.should raise_error(Errno::ENOENT) + -> { File.open(@nonexistent, File::RDONLY) }.should raise_error(Errno::ENOENT) end it "opens a file that no exists when use 'r' mode" do - lambda { File.open(@nonexistent, 'r') }.should raise_error(Errno::ENOENT) + -> { File.open(@nonexistent, 'r') }.should raise_error(Errno::ENOENT) end it "opens a file that no exists when use File::EXCL mode" do - lambda { File.open(@nonexistent, File::EXCL) }.should raise_error(Errno::ENOENT) + -> { File.open(@nonexistent, File::EXCL) }.should raise_error(Errno::ENOENT) end it "opens a file that no exists when use File::NONBLOCK mode" do - lambda { File.open(@nonexistent, File::NONBLOCK) }.should raise_error(Errno::ENOENT) + -> { File.open(@nonexistent, File::NONBLOCK) }.should raise_error(Errno::ENOENT) end platform_is_not :openbsd, :windows do it "opens a file that no exists when use File::TRUNC mode" do - lambda { File.open(@nonexistent, File::TRUNC) }.should raise_error(Errno::ENOENT) + -> { File.open(@nonexistent, File::TRUNC) }.should raise_error(Errno::ENOENT) end end platform_is :openbsd, :windows do it "does not open a file that does no exists when using File::TRUNC mode" do - lambda { File.open(@nonexistent, File::TRUNC) }.should raise_error(Errno::EINVAL) + -> { File.open(@nonexistent, File::TRUNC) }.should raise_error(Errno::EINVAL) end end platform_is_not :windows do it "opens a file that no exists when use File::NOCTTY mode" do - lambda { File.open(@nonexistent, File::NOCTTY) }.should raise_error(Errno::ENOENT) + -> { File.open(@nonexistent, File::NOCTTY) }.should raise_error(Errno::ENOENT) end end @@ -223,7 +223,7 @@ describe "File.open" do # Check the grants associated to the different open modes combinations. it "raises an ArgumentError exception when call with an unknown mode" do - lambda { File.open(@file, "q") }.should raise_error(ArgumentError) + -> { File.open(@file, "q") }.should raise_error(ArgumentError) end it "can read in a block when call open with RDONLY mode" do @@ -240,13 +240,13 @@ describe "File.open" do it "raises an IO exception when write in a block opened with RDONLY mode" do File.open(@file, File::RDONLY) do |f| - lambda { f.puts "writing ..." }.should raise_error(IOError) + -> { f.puts "writing ..." }.should raise_error(IOError) end end it "raises an IO exception when write in a block opened with 'r' mode" do File.open(@file, "r") do |f| - lambda { f.puts "writing ..." }.should raise_error(IOError) + -> { f.puts "writing ..." }.should raise_error(IOError) end end @@ -257,7 +257,7 @@ describe "File.open" do end it "can't read in a block when call open with File::WRONLY||File::RDONLY mode" do - lambda { + -> { File.open(@file, File::WRONLY|File::RDONLY ) do |f| f.gets.should == nil end @@ -278,44 +278,44 @@ describe "File.open" do it "raises an IOError when read in a block opened with WRONLY mode" do File.open(@file, File::WRONLY) do |f| - lambda { f.gets }.should raise_error(IOError) + -> { f.gets }.should raise_error(IOError) end end it "raises an IOError when read in a block opened with 'w' mode" do File.open(@file, "w") do |f| - lambda { f.gets }.should raise_error(IOError) + -> { f.gets }.should raise_error(IOError) end end it "raises an IOError when read in a block opened with 'a' mode" do File.open(@file, "a") do |f| - lambda { f.gets }.should raise_error(IOError) + -> { f.gets }.should raise_error(IOError) end end it "raises an IOError when read in a block opened with 'a' mode" do File.open(@file, "a") do |f| f.puts("writing").should == nil - lambda { f.gets }.should raise_error(IOError) + -> { f.gets }.should raise_error(IOError) end end it "raises an IOError when read in a block opened with 'a' mode" do File.open(@file, File::WRONLY|File::APPEND ) do |f| - lambda { f.gets }.should raise_error(IOError) + -> { f.gets }.should raise_error(IOError) end end it "raises an IOError when read in a block opened with File::WRONLY|File::APPEND mode" do File.open(@file, File::WRONLY|File::APPEND ) do |f| f.puts("writing").should == nil - lambda { f.gets }.should raise_error(IOError) + -> { f.gets }.should raise_error(IOError) end end it "raises an IOError when read in a block opened with File::RDONLY|File::APPEND mode" do - lambda { + -> { File.open(@file, File::RDONLY|File::APPEND ) do |f| f.puts("writing") end @@ -332,7 +332,7 @@ describe "File.open" do end it "can't read in a block when call open with File::EXCL mode" do - lambda { + -> { File.open(@file, File::EXCL) do |f| f.puts("writing").should == nil end @@ -355,7 +355,7 @@ describe "File.open" do end it "raises an Errorno::EEXIST if the file exists when open with File::CREAT|File::EXCL" do - lambda { + -> { File.open(@file, File::CREAT|File::EXCL) do |f| f.puts("writing") end @@ -382,7 +382,7 @@ describe "File.open" do end it "raises an IOError if the file exists when open with File::RDONLY|File::APPEND" do - lambda { + -> { File.open(@file, File::RDONLY|File::APPEND) do |f| f.puts("writing").should == nil end @@ -416,7 +416,7 @@ describe "File.open" do platform_is_not :openbsd, :windows do it "can't write in a block when call open with File::TRUNC mode" do - lambda { + -> { File.open(@file, File::TRUNC) do |f| f.puts("writing") end @@ -424,7 +424,7 @@ describe "File.open" do end it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do - lambda { + -> { File.open(@file, File::RDONLY|File::TRUNC) do |f| f.puts("writing").should == nil end @@ -434,7 +434,7 @@ describe "File.open" do platform_is :openbsd, :windows do it "can't write in a block when call open with File::TRUNC mode" do - lambda { + -> { File.open(@file, File::TRUNC) do |f| f.puts("writing") end @@ -442,7 +442,7 @@ describe "File.open" do end it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do - lambda { + -> { File.open(@file, File::RDONLY|File::TRUNC) do |f| f.puts("writing").should == nil end @@ -455,7 +455,7 @@ describe "File.open" do it "raises an Errno::EACCES when opening non-permitted file" do @fh = File.open(@file, "w") @fh.chmod(000) - lambda { fh1 = File.open(@file); fh1.close }.should raise_error(Errno::EACCES) + -> { fh1 = File.open(@file); fh1.close }.should raise_error(Errno::EACCES) end end end @@ -464,7 +464,7 @@ describe "File.open" do it "raises an Errno::EACCES when opening read-only file" do @fh = File.open(@file, "w") @fh.chmod(0444) - lambda { File.open(@file, "w") }.should raise_error(Errno::EACCES) + -> { File.open(@file, "w") }.should raise_error(Errno::EACCES) end end @@ -535,21 +535,21 @@ describe "File.open" do end it "raises a TypeError if passed a filename that is not a String or Integer type" do - lambda { File.open(true) }.should raise_error(TypeError) - lambda { File.open(false) }.should raise_error(TypeError) - lambda { File.open(nil) }.should raise_error(TypeError) + -> { File.open(true) }.should raise_error(TypeError) + -> { File.open(false) }.should raise_error(TypeError) + -> { File.open(nil) }.should raise_error(TypeError) end it "raises a SystemCallError if passed an invalid Integer type" do - lambda { File.open(-1) }.should raise_error(SystemCallError) + -> { File.open(-1) }.should raise_error(SystemCallError) end it "raises an ArgumentError if passed the wrong number of arguments" do - lambda { File.open(@file, File::CREAT, 0755, 'test') }.should raise_error(ArgumentError) + -> { File.open(@file, File::CREAT, 0755, 'test') }.should raise_error(ArgumentError) end it "raises an ArgumentError if passed an invalid string for mode" do - lambda { File.open(@file, 'fake') }.should raise_error(ArgumentError) + -> { File.open(@file, 'fake') }.should raise_error(ArgumentError) end it "defaults external_encoding to BINARY for binary modes" do @@ -570,17 +570,17 @@ describe "File.open" do end it "accepts extra flags as a keyword argument and combine with a string mode" do - lambda { + -> { File.open(@file, "w", flags: File::EXCL) { } }.should raise_error(Errno::EEXIST) - lambda { + -> { File.open(@file, mode: "w", flags: File::EXCL) { } }.should raise_error(Errno::EEXIST) end it "accepts extra flags as a keyword argument and combine with an integer mode" do - lambda { + -> { File.open(@file, File::WRONLY | File::CREAT, flags: File::EXCL) { } }.should raise_error(Errno::EEXIST) end @@ -641,12 +641,12 @@ describe "File.open" do it "throws a Errno::EEXIST error if the file exists" do touch @xfile - lambda { File.open(@xfile, "wx") }.should raise_error(Errno::EEXIST) + -> { File.open(@xfile, "wx") }.should raise_error(Errno::EEXIST) end it "can't be used with 'r' and 'a' flags" do - lambda { File.open(@xfile, "rx") }.should raise_error(ArgumentError, 'invalid access mode rx') - lambda { File.open(@xfile, "ax") }.should raise_error(ArgumentError, 'invalid access mode ax') + -> { File.open(@xfile, "rx") }.should raise_error(ArgumentError, 'invalid access mode rx') + -> { File.open(@xfile, "ax") }.should raise_error(ArgumentError, 'invalid access mode ax') end end end diff --git a/spec/ruby/core/file/printf_spec.rb b/spec/ruby/core/file/printf_spec.rb index 95ce3589c5..2530419fc7 100644 --- a/spec/ruby/core/file/printf_spec.rb +++ b/spec/ruby/core/file/printf_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' require_relative '../kernel/shared/sprintf' describe "File#printf" do - it_behaves_like :kernel_sprintf, -> (format, *args) { + it_behaves_like :kernel_sprintf, -> format, *args { begin @filename = tmp("printf.txt") diff --git a/spec/ruby/core/file/readlink_spec.rb b/spec/ruby/core/file/readlink_spec.rb index 7b1fe74047..eb3bfda30e 100644 --- a/spec/ruby/core/file/readlink_spec.rb +++ b/spec/ruby/core/file/readlink_spec.rb @@ -26,12 +26,12 @@ describe "File.readlink" do it "raises an Errno::ENOENT if there is no such file" do # TODO: missing_file - lambda { File.readlink("/this/surely/doesnt/exist") }.should raise_error(Errno::ENOENT) + -> { File.readlink("/this/surely/doesnt/exist") }.should raise_error(Errno::ENOENT) end it "raises an Errno::EINVAL if called with a normal file" do touch @file - lambda { File.readlink(@file) }.should raise_error(Errno::EINVAL) + -> { File.readlink(@file) }.should raise_error(Errno::EINVAL) end end diff --git a/spec/ruby/core/file/realdirpath_spec.rb b/spec/ruby/core/file/realdirpath_spec.rb index 9c90d7330f..74053afce3 100644 --- a/spec/ruby/core/file/realdirpath_spec.rb +++ b/spec/ruby/core/file/realdirpath_spec.rb @@ -61,7 +61,7 @@ platform_is_not :windows do it "raises an Errno::ELOOP if the symlink points to itself" do File.unlink @link File.symlink(@link, @link) - lambda { File.realdirpath(@link) }.should raise_error(Errno::ELOOP) + -> { File.realdirpath(@link) }.should raise_error(Errno::ELOOP) end it "returns the real (absolute) pathname if the file is absent" do @@ -69,7 +69,7 @@ platform_is_not :windows do end it "raises Errno::ENOENT if the directory is absent" do - lambda { File.realdirpath(@fake_file_in_fake_dir) }.should raise_error(Errno::ENOENT) + -> { File.realdirpath(@fake_file_in_fake_dir) }.should raise_error(Errno::ENOENT) end it "returns the real (absolute) pathname if the symlink points to an absent file" do @@ -77,7 +77,7 @@ platform_is_not :windows do end it "raises Errno::ENOENT if the symlink points to an absent directory" do - lambda { File.realdirpath(@fake_link_to_fake_dir) }.should raise_error(Errno::ENOENT) + -> { File.realdirpath(@fake_link_to_fake_dir) }.should raise_error(Errno::ENOENT) end end end diff --git a/spec/ruby/core/file/realpath_spec.rb b/spec/ruby/core/file/realpath_spec.rb index d7bb842759..0c5d19287a 100644 --- a/spec/ruby/core/file/realpath_spec.rb +++ b/spec/ruby/core/file/realpath_spec.rb @@ -57,15 +57,15 @@ platform_is_not :windows do it "raises an Errno::ELOOP if the symlink points to itself" do File.unlink @link File.symlink(@link, @link) - lambda { File.realpath(@link) }.should raise_error(Errno::ELOOP) + -> { File.realpath(@link) }.should raise_error(Errno::ELOOP) end it "raises Errno::ENOENT if the file is absent" do - lambda { File.realpath(@fake_file) }.should raise_error(Errno::ENOENT) + -> { File.realpath(@fake_file) }.should raise_error(Errno::ENOENT) end it "raises Errno::ENOENT if the symlink points to an absent file" do - lambda { File.realpath(@fake_link) }.should raise_error(Errno::ENOENT) + -> { File.realpath(@fake_link) }.should raise_error(Errno::ENOENT) end end end diff --git a/spec/ruby/core/file/rename_spec.rb b/spec/ruby/core/file/rename_spec.rb index 5f47000d38..d903e7a0d5 100644 --- a/spec/ruby/core/file/rename_spec.rb +++ b/spec/ruby/core/file/rename_spec.rb @@ -23,15 +23,15 @@ describe "File.rename" do it "raises an Errno::ENOENT if the source does not exist" do rm_r @old - lambda { File.rename(@old, @new) }.should raise_error(Errno::ENOENT) + -> { File.rename(@old, @new) }.should raise_error(Errno::ENOENT) end it "raises an ArgumentError if not passed two arguments" do - lambda { File.rename }.should raise_error(ArgumentError) - lambda { File.rename(@file) }.should raise_error(ArgumentError) + -> { File.rename }.should raise_error(ArgumentError) + -> { File.rename(@file) }.should raise_error(ArgumentError) end it "raises a TypeError if not passed String types" do - lambda { File.rename(1, 2) }.should raise_error(TypeError) + -> { File.rename(1, 2) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/file/shared/fnmatch.rb b/spec/ruby/core/file/shared/fnmatch.rb index 49a870e95a..a8488fd30a 100644 --- a/spec/ruby/core/file/shared/fnmatch.rb +++ b/spec/ruby/core/file/shared/fnmatch.rb @@ -218,21 +218,21 @@ describe :file_fnmatch, shared: true do end it "raises a TypeError if the first and second arguments are not string-like" do - lambda { File.send(@method, nil, nil, 0, 0) }.should raise_error(ArgumentError) - lambda { File.send(@method, 1, 'some/thing') }.should raise_error(TypeError) - lambda { File.send(@method, 'some/thing', 1) }.should raise_error(TypeError) - lambda { File.send(@method, 1, 1) }.should raise_error(TypeError) + -> { File.send(@method, nil, nil, 0, 0) }.should raise_error(ArgumentError) + -> { File.send(@method, 1, 'some/thing') }.should raise_error(TypeError) + -> { File.send(@method, 'some/thing', 1) }.should raise_error(TypeError) + -> { File.send(@method, 1, 1) }.should raise_error(TypeError) end it "raises a TypeError if the third argument is not an Integer" do - lambda { File.send(@method, "*/place", "path/to/file", "flags") }.should raise_error(TypeError) - lambda { File.send(@method, "*/place", "path/to/file", nil) }.should raise_error(TypeError) + -> { File.send(@method, "*/place", "path/to/file", "flags") }.should raise_error(TypeError) + -> { File.send(@method, "*/place", "path/to/file", nil) }.should raise_error(TypeError) end it "does not raise a TypeError if the third argument can be coerced to an Integer" do flags = mock("flags") flags.should_receive(:to_int).and_return(10) - lambda { File.send(@method, "*/place", "path/to/file", flags) }.should_not raise_error + -> { File.send(@method, "*/place", "path/to/file", flags) }.should_not raise_error end it "matches multibyte characters" do diff --git a/spec/ruby/core/file/shared/read.rb b/spec/ruby/core/file/shared/read.rb index 7fff7f29d6..a2d479966d 100644 --- a/spec/ruby/core/file/shared/read.rb +++ b/spec/ruby/core/file/shared/read.rb @@ -3,13 +3,13 @@ require_relative '../../dir/fixtures/common' describe :file_read_directory, shared: true do platform_is :darwin, :linux, :openbsd, :windows do it "raises an Errno::EISDIR when passed a path that is a directory" do - lambda { @object.send(@method, ".") }.should raise_error(Errno::EISDIR) + -> { @object.send(@method, ".") }.should raise_error(Errno::EISDIR) end end platform_is :freebsd, :netbsd do it "does not raises any exception when passed a path that is a directory" do - lambda { @object.send(@method, ".") }.should_not raise_error + -> { @object.send(@method, ".") }.should_not raise_error end end end diff --git a/spec/ruby/core/file/shared/stat.rb b/spec/ruby/core/file/shared/stat.rb index aac710dd2f..fdaf97ea61 100644 --- a/spec/ruby/core/file/shared/stat.rb +++ b/spec/ruby/core/file/shared/stat.rb @@ -25,7 +25,7 @@ describe :file_stat, shared: true do end it "raises an Errno::ENOENT if the file does not exist" do - lambda { + -> { File.send(@method, "fake_file") }.should raise_error(Errno::ENOENT) end diff --git a/spec/ruby/core/file/shared/unlink.rb b/spec/ruby/core/file/shared/unlink.rb index 42b6a77c5d..d72ab4701f 100644 --- a/spec/ruby/core/file/shared/unlink.rb +++ b/spec/ruby/core/file/shared/unlink.rb @@ -31,11 +31,11 @@ describe :file_unlink, shared: true do end it "raises a TypeError if not passed a String type" do - lambda { File.send(@method, 1) }.should raise_error(TypeError) + -> { File.send(@method, 1) }.should raise_error(TypeError) end it "raises an Errno::ENOENT when the given file doesn't exist" do - lambda { File.send(@method, 'bogus') }.should raise_error(Errno::ENOENT) + -> { File.send(@method, 'bogus') }.should raise_error(Errno::ENOENT) end it "coerces a given parameter into a string if possible" do diff --git a/spec/ruby/core/file/size_spec.rb b/spec/ruby/core/file/size_spec.rb index b0ab2c0651..a2bf408da1 100644 --- a/spec/ruby/core/file/size_spec.rb +++ b/spec/ruby/core/file/size_spec.rb @@ -81,7 +81,7 @@ describe "File#size" do it "raises an IOError on a closed file" do @file.close - lambda { @file.size }.should raise_error(IOError) + -> { @file.size }.should raise_error(IOError) end platform_is_not :windows do diff --git a/spec/ruby/core/file/split_spec.rb b/spec/ruby/core/file/split_spec.rb index 2b22b0a08f..7b958621b9 100644 --- a/spec/ruby/core/file/split_spec.rb +++ b/spec/ruby/core/file/split_spec.rb @@ -44,12 +44,12 @@ describe "File.split" do end it "raises an ArgumentError when not passed a single argument" do - lambda { File.split }.should raise_error(ArgumentError) - lambda { File.split('string', 'another string') }.should raise_error(ArgumentError) + -> { File.split }.should raise_error(ArgumentError) + -> { File.split('string', 'another string') }.should raise_error(ArgumentError) end it "raises a TypeError if the argument is not a String type" do - lambda { File.split(1) }.should raise_error(TypeError) + -> { File.split(1) }.should raise_error(TypeError) end it "coerces the argument with to_str if it is not a String type" do diff --git a/spec/ruby/core/file/stat/birthtime_spec.rb b/spec/ruby/core/file/stat/birthtime_spec.rb index 40e501e87b..a727bbe566 100644 --- a/spec/ruby/core/file/stat/birthtime_spec.rb +++ b/spec/ruby/core/file/stat/birthtime_spec.rb @@ -21,7 +21,7 @@ describe "File::Stat#birthtime" do platform_is :linux, :openbsd do it "raises an NotImplementedError" do st = File.stat(@file) - lambda { st.birthtime }.should raise_error(NotImplementedError) + -> { st.birthtime }.should raise_error(NotImplementedError) end end end diff --git a/spec/ruby/core/file/stat/new_spec.rb b/spec/ruby/core/file/stat/new_spec.rb index f5f22e6711..c0d9432ac8 100644 --- a/spec/ruby/core/file/stat/new_spec.rb +++ b/spec/ruby/core/file/stat/new_spec.rb @@ -13,7 +13,7 @@ describe "File::Stat#initialize" do end it "raises an exception if the file doesn't exist" do - lambda { + -> { File::Stat.new(tmp("i_am_a_dummy_file_that_doesnt_exist")) }.should raise_error(Errno::ENOENT) end diff --git a/spec/ruby/core/file/symlink_spec.rb b/spec/ruby/core/file/symlink_spec.rb index a8486db04a..0e8b0a5a20 100644 --- a/spec/ruby/core/file/symlink_spec.rb +++ b/spec/ruby/core/file/symlink_spec.rb @@ -32,18 +32,18 @@ describe "File.symlink" do it "raises an Errno::EEXIST if the target already exists" do File.symlink(@file, @link) - lambda { File.symlink(@file, @link) }.should raise_error(Errno::EEXIST) + -> { File.symlink(@file, @link) }.should raise_error(Errno::EEXIST) end it "raises an ArgumentError if not called with two arguments" do - lambda { File.symlink }.should raise_error(ArgumentError) - lambda { File.symlink(@file) }.should raise_error(ArgumentError) + -> { File.symlink }.should raise_error(ArgumentError) + -> { File.symlink(@file) }.should raise_error(ArgumentError) end it "raises a TypeError if not called with String types" do - lambda { File.symlink(@file, nil) }.should raise_error(TypeError) - lambda { File.symlink(@file, 1) }.should raise_error(TypeError) - lambda { File.symlink(1, 1) }.should raise_error(TypeError) + -> { File.symlink(@file, nil) }.should raise_error(TypeError) + -> { File.symlink(@file, 1) }.should raise_error(TypeError) + -> { File.symlink(1, 1) }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/file/truncate_spec.rb b/spec/ruby/core/file/truncate_spec.rb index 36fe26a2fe..43b86b7382 100644 --- a/spec/ruby/core/file/truncate_spec.rb +++ b/spec/ruby/core/file/truncate_spec.rb @@ -54,29 +54,29 @@ describe "File.truncate" do rm_r not_existing_file begin - lambda { File.truncate(not_existing_file, 5) }.should raise_error(Errno::ENOENT) + -> { File.truncate(not_existing_file, 5) }.should raise_error(Errno::ENOENT) ensure rm_r not_existing_file end end it "raises an ArgumentError if not passed two arguments" do - lambda { File.truncate }.should raise_error(ArgumentError) - lambda { File.truncate(@name) }.should raise_error(ArgumentError) + -> { File.truncate }.should raise_error(ArgumentError) + -> { File.truncate(@name) }.should raise_error(ArgumentError) end platform_is_not :netbsd, :openbsd do it "raises an Errno::EINVAL if the length argument is not valid" do - lambda { File.truncate(@name, -1) }.should raise_error(Errno::EINVAL) # May fail + -> { File.truncate(@name, -1) }.should raise_error(Errno::EINVAL) # May fail end end it "raises a TypeError if not passed a String type for the first argument" do - lambda { File.truncate(1, 1) }.should raise_error(TypeError) + -> { File.truncate(1, 1) }.should raise_error(TypeError) end it "raises a TypeError if not passed an Integer type for the second argument" do - lambda { File.truncate(@name, nil) }.should raise_error(TypeError) + -> { File.truncate(@name, nil) }.should raise_error(TypeError) end it "accepts an object that has a #to_path method" do @@ -149,29 +149,29 @@ describe "File#truncate" do end it "raises an ArgumentError if not passed one argument" do - lambda { @file.truncate }.should raise_error(ArgumentError) - lambda { @file.truncate(1) }.should_not raise_error(ArgumentError) + -> { @file.truncate }.should raise_error(ArgumentError) + -> { @file.truncate(1) }.should_not raise_error(ArgumentError) end platform_is_not :netbsd do it "raises an Errno::EINVAL if the length argument is not valid" do - lambda { @file.truncate(-1) }.should raise_error(Errno::EINVAL) # May fail + -> { @file.truncate(-1) }.should raise_error(Errno::EINVAL) # May fail end end it "raises an IOError if file is closed" do @file.close @file.closed?.should == true - lambda { @file.truncate(42) }.should raise_error(IOError) + -> { @file.truncate(42) }.should raise_error(IOError) end it "raises an IOError if file is not opened for writing" do File.open(@name, 'r') do |file| - lambda { file.truncate(42) }.should raise_error(IOError) + -> { file.truncate(42) }.should raise_error(IOError) end end it "raises a TypeError if not passed an Integer type for the for the argument" do - lambda { @file.truncate(nil) }.should raise_error(TypeError) + -> { @file.truncate(nil) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/file/umask_spec.rb b/spec/ruby/core/file/umask_spec.rb index 9a4beb8998..2640e3c316 100644 --- a/spec/ruby/core/file/umask_spec.rb +++ b/spec/ruby/core/file/umask_spec.rb @@ -52,6 +52,6 @@ describe "File.umask" do end it "raises ArgumentError when more than one argument is provided" do - lambda { File.umask(022, 022) }.should raise_error(ArgumentError) + -> { File.umask(022, 022) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/float/divide_spec.rb b/spec/ruby/core/float/divide_spec.rb index f41b9f1f93..d8f71a6b98 100644 --- a/spec/ruby/core/float/divide_spec.rb +++ b/spec/ruby/core/float/divide_spec.rb @@ -33,7 +33,7 @@ describe "Float#/" do end it "raises a TypeError when given a non-Numeric" do - lambda { 13.0 / "10" }.should raise_error(TypeError) - lambda { 13.0 / :symbol }.should raise_error(TypeError) + -> { 13.0 / "10" }.should raise_error(TypeError) + -> { 13.0 / :symbol }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/float/divmod_spec.rb b/spec/ruby/core/float/divmod_spec.rb index 5983efe1d9..ec55dd3681 100644 --- a/spec/ruby/core/float/divmod_spec.rb +++ b/spec/ruby/core/float/divmod_spec.rb @@ -18,22 +18,22 @@ describe "Float#divmod" do # Behaviour established as correct in r23953 it "raises a FloatDomainError if self is NaN" do - lambda { nan_value.divmod(1) }.should raise_error(FloatDomainError) + -> { nan_value.divmod(1) }.should raise_error(FloatDomainError) end # Behaviour established as correct in r23953 it "raises a FloatDomainError if other is NaN" do - lambda { 1.divmod(nan_value) }.should raise_error(FloatDomainError) + -> { 1.divmod(nan_value) }.should raise_error(FloatDomainError) end # Behaviour established as correct in r23953 it "raises a FloatDomainError if self is Infinity" do - lambda { infinity_value.divmod(1) }.should raise_error(FloatDomainError) + -> { infinity_value.divmod(1) }.should raise_error(FloatDomainError) end it "raises a ZeroDivisionError if other is zero" do - lambda { 1.0.divmod(0) }.should raise_error(ZeroDivisionError) - lambda { 1.0.divmod(0.0) }.should raise_error(ZeroDivisionError) + -> { 1.0.divmod(0) }.should raise_error(ZeroDivisionError) + -> { 1.0.divmod(0.0) }.should raise_error(ZeroDivisionError) end # redmine #5276" diff --git a/spec/ruby/core/float/float_spec.rb b/spec/ruby/core/float/float_spec.rb index 3ad4ce817a..263ae82079 100644 --- a/spec/ruby/core/float/float_spec.rb +++ b/spec/ruby/core/float/float_spec.rb @@ -6,13 +6,13 @@ describe "Float" do end it ".allocate raises a TypeError" do - lambda do + -> do Float.allocate end.should raise_error(TypeError) end it ".new is undefined" do - lambda do + -> do Float.new end.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/float/gt_spec.rb b/spec/ruby/core/float/gt_spec.rb index 6ecab3592d..0d73f1c3df 100644 --- a/spec/ruby/core/float/gt_spec.rb +++ b/spec/ruby/core/float/gt_spec.rb @@ -11,7 +11,7 @@ describe "Float#>" do end it "raises an ArgumentError when given a non-Numeric" do - lambda { 5.0 > "4" }.should raise_error(ArgumentError) - lambda { 5.0 > mock('x') }.should raise_error(ArgumentError) + -> { 5.0 > "4" }.should raise_error(ArgumentError) + -> { 5.0 > mock('x') }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/float/gte_spec.rb b/spec/ruby/core/float/gte_spec.rb index 0886dffd97..98ec60b70b 100644 --- a/spec/ruby/core/float/gte_spec.rb +++ b/spec/ruby/core/float/gte_spec.rb @@ -11,7 +11,7 @@ describe "Float#>=" do end it "raises an ArgumentError when given a non-Numeric" do - lambda { 5.0 >= "4" }.should raise_error(ArgumentError) - lambda { 5.0 >= mock('x') }.should raise_error(ArgumentError) + -> { 5.0 >= "4" }.should raise_error(ArgumentError) + -> { 5.0 >= mock('x') }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/float/lt_spec.rb b/spec/ruby/core/float/lt_spec.rb index 9723b59c5e..c01b6e0e02 100644 --- a/spec/ruby/core/float/lt_spec.rb +++ b/spec/ruby/core/float/lt_spec.rb @@ -11,7 +11,7 @@ describe "Float#<" do end it "raises an ArgumentError when given a non-Numeric" do - lambda { 5.0 < "4" }.should raise_error(ArgumentError) - lambda { 5.0 < mock('x') }.should raise_error(ArgumentError) + -> { 5.0 < "4" }.should raise_error(ArgumentError) + -> { 5.0 < mock('x') }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/float/lte_spec.rb b/spec/ruby/core/float/lte_spec.rb index 0a0a06d753..66f2ddc2c7 100644 --- a/spec/ruby/core/float/lte_spec.rb +++ b/spec/ruby/core/float/lte_spec.rb @@ -12,7 +12,7 @@ describe "Float#<=" do end it "raises an ArgumentError when given a non-Numeric" do - lambda { 5.0 <= "4" }.should raise_error(ArgumentError) - lambda { 5.0 <= mock('x') }.should raise_error(ArgumentError) + -> { 5.0 <= "4" }.should raise_error(ArgumentError) + -> { 5.0 <= mock('x') }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/float/multiply_spec.rb b/spec/ruby/core/float/multiply_spec.rb index 69a5dcc95a..eca0b52c4f 100644 --- a/spec/ruby/core/float/multiply_spec.rb +++ b/spec/ruby/core/float/multiply_spec.rb @@ -11,7 +11,7 @@ describe "Float#*" do end it "raises a TypeError when given a non-Numeric" do - lambda { 13.0 * "10" }.should raise_error(TypeError) - lambda { 13.0 * :symbol }.should raise_error(TypeError) + -> { 13.0 * "10" }.should raise_error(TypeError) + -> { 13.0 * :symbol }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/float/rationalize_spec.rb b/spec/ruby/core/float/rationalize_spec.rb index 978425e084..0c5bef7ac4 100644 --- a/spec/ruby/core/float/rationalize_spec.rb +++ b/spec/ruby/core/float/rationalize_spec.rb @@ -29,15 +29,15 @@ describe "Float#rationalize" do end it "raises a FloatDomainError for Infinity" do - lambda {infinity_value.rationalize}.should raise_error(FloatDomainError) + -> {infinity_value.rationalize}.should raise_error(FloatDomainError) end it "raises a FloatDomainError for NaN" do - lambda { nan_value.rationalize }.should raise_error(FloatDomainError) + -> { nan_value.rationalize }.should raise_error(FloatDomainError) end it "raises ArgumentError when passed more than one argument" do - lambda { 0.3.rationalize(0.1, 0.1) }.should raise_error(ArgumentError) - lambda { 0.3.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) + -> { 0.3.rationalize(0.1, 0.1) }.should raise_error(ArgumentError) + -> { 0.3.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/float/round_spec.rb b/spec/ruby/core/float/round_spec.rb index d5ca532c5a..e143682362 100644 --- a/spec/ruby/core/float/round_spec.rb +++ b/spec/ruby/core/float/round_spec.rb @@ -16,9 +16,9 @@ describe "Float#round" do end it "raises FloatDomainError for exceptional values" do - lambda { (+infinity_value).round }.should raise_error(FloatDomainError) - lambda { (-infinity_value).round }.should raise_error(FloatDomainError) - lambda { nan_value.round }.should raise_error(FloatDomainError) + -> { (+infinity_value).round }.should raise_error(FloatDomainError) + -> { (-infinity_value).round }.should raise_error(FloatDomainError) + -> { nan_value.round }.should raise_error(FloatDomainError) end it "rounds self to an optionally given precision" do @@ -35,20 +35,20 @@ describe "Float#round" do end it "raises a TypeError when its argument can not be converted to an Integer" do - lambda { 1.0.round("4") }.should raise_error(TypeError) - lambda { 1.0.round(nil) }.should raise_error(TypeError) + -> { 1.0.round("4") }.should raise_error(TypeError) + -> { 1.0.round(nil) }.should raise_error(TypeError) end it "raises FloatDomainError for exceptional values when passed a non-positive precision" do - lambda { Float::INFINITY.round( 0) }.should raise_error(FloatDomainError) - lambda { Float::INFINITY.round(-2) }.should raise_error(FloatDomainError) - lambda { (-Float::INFINITY).round( 0) }.should raise_error(FloatDomainError) - lambda { (-Float::INFINITY).round(-2) }.should raise_error(FloatDomainError) + -> { Float::INFINITY.round( 0) }.should raise_error(FloatDomainError) + -> { Float::INFINITY.round(-2) }.should raise_error(FloatDomainError) + -> { (-Float::INFINITY).round( 0) }.should raise_error(FloatDomainError) + -> { (-Float::INFINITY).round(-2) }.should raise_error(FloatDomainError) end it "raises RangeError for NAN when passed a non-positive precision" do - lambda { Float::NAN.round(0) }.should raise_error(RangeError) - lambda { Float::NAN.round(-2) }.should raise_error(RangeError) + -> { Float::NAN.round(0) }.should raise_error(RangeError) + -> { Float::NAN.round(-2) }.should raise_error(RangeError) end it "returns self for exceptional values when passed a non-negative precision" do @@ -106,12 +106,12 @@ describe "Float#round" do end it "raises FloatDomainError for exceptional values with a half option" do - lambda { (+infinity_value).round(half: :up) }.should raise_error(FloatDomainError) - lambda { (-infinity_value).round(half: :down) }.should raise_error(FloatDomainError) - lambda { nan_value.round(half: :even) }.should raise_error(FloatDomainError) + -> { (+infinity_value).round(half: :up) }.should raise_error(FloatDomainError) + -> { (-infinity_value).round(half: :down) }.should raise_error(FloatDomainError) + -> { nan_value.round(half: :even) }.should raise_error(FloatDomainError) end it "raise for a non-existent round mode" do - lambda { 14.2.round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense") + -> { 14.2.round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense") end end diff --git a/spec/ruby/core/float/shared/modulo.rb b/spec/ruby/core/float/shared/modulo.rb index 6c423a3a28..6700bd4f4e 100644 --- a/spec/ruby/core/float/shared/modulo.rb +++ b/spec/ruby/core/float/shared/modulo.rb @@ -42,7 +42,7 @@ describe :float_modulo, shared: true do end it "raises a ZeroDivisionError if other is zero" do - lambda { 1.0.send(@method, 0) }.should raise_error(ZeroDivisionError) - lambda { 1.0.send(@method, 0.0) }.should raise_error(ZeroDivisionError) + -> { 1.0.send(@method, 0) }.should raise_error(ZeroDivisionError) + -> { 1.0.send(@method, 0.0) }.should raise_error(ZeroDivisionError) end end diff --git a/spec/ruby/core/float/shared/quo.rb b/spec/ruby/core/float/shared/quo.rb index afc921a2c1..3487824f70 100644 --- a/spec/ruby/core/float/shared/quo.rb +++ b/spec/ruby/core/float/shared/quo.rb @@ -50,10 +50,10 @@ describe :float_quo, shared: true do end it "raises a TypeError when argument isn't numeric" do - lambda { 27292.2.send(@method, mock('non-numeric')) }.should raise_error(TypeError) + -> { 27292.2.send(@method, mock('non-numeric')) }.should raise_error(TypeError) end it "raises an ArgumentError when passed multiple arguments" do - lambda { 272.221.send(@method, 6,0.2) }.should raise_error(ArgumentError) + -> { 272.221.send(@method, 6,0.2) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/hash/clear_spec.rb b/spec/ruby/core/hash/clear_spec.rb index 706fe57e1c..e7816acbbc 100644 --- a/spec/ruby/core/hash/clear_spec.rb +++ b/spec/ruby/core/hash/clear_spec.rb @@ -26,7 +26,7 @@ describe "Hash#clear" do end it "raises a #{frozen_error_class} if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.clear }.should raise_error(frozen_error_class) - lambda { HashSpecs.empty_frozen_hash.clear }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.clear }.should raise_error(frozen_error_class) + -> { HashSpecs.empty_frozen_hash.clear }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/compare_by_identity_spec.rb b/spec/ruby/core/hash/compare_by_identity_spec.rb index 33db59124e..0658b4954a 100644 --- a/spec/ruby/core/hash/compare_by_identity_spec.rb +++ b/spec/ruby/core/hash/compare_by_identity_spec.rb @@ -82,7 +82,7 @@ describe "Hash#compare_by_identity" do it "raises a #{frozen_error_class} on frozen hashes" do @h = @h.freeze - lambda { @h.compare_by_identity }.should raise_error(frozen_error_class) + -> { @h.compare_by_identity }.should raise_error(frozen_error_class) end # Behaviour confirmed in bug #1871 diff --git a/spec/ruby/core/hash/constructor_spec.rb b/spec/ruby/core/hash/constructor_spec.rb index 14674a018b..ad67274802 100644 --- a/spec/ruby/core/hash/constructor_spec.rb +++ b/spec/ruby/core/hash/constructor_spec.rb @@ -65,7 +65,7 @@ describe "Hash.[]" do end it "raises an ArgumentError for arrays of more than 2 elements" do - lambda{ Hash[[[:a, :b, :c]]].should == {} }.should raise_error(ArgumentError) + ->{ Hash[[[:a, :b, :c]]].should == {} }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed a list of value-invalid-pairs in an array" do @@ -89,8 +89,8 @@ describe "Hash.[]" do end it "raises an ArgumentError when passed an odd number of arguments" do - lambda { Hash[1, 2, 3] }.should raise_error(ArgumentError) - lambda { Hash[1, 2, { 3 => 4 }] }.should raise_error(ArgumentError) + -> { Hash[1, 2, 3] }.should raise_error(ArgumentError) + -> { Hash[1, 2, { 3 => 4 }] }.should raise_error(ArgumentError) end it "calls to_hash" do diff --git a/spec/ruby/core/hash/default_proc_spec.rb b/spec/ruby/core/hash/default_proc_spec.rb index 2254609607..83ad98e5b6 100644 --- a/spec/ruby/core/hash/default_proc_spec.rb +++ b/spec/ruby/core/hash/default_proc_spec.rb @@ -37,7 +37,7 @@ describe "Hash#default_proc=" do end it "raises an error if passed stuff not convertible to procs" do - lambda{{}.default_proc = 42}.should raise_error(TypeError) + ->{{}.default_proc = 42}.should raise_error(TypeError) end it "returns the passed Proc" do @@ -58,23 +58,23 @@ describe "Hash#default_proc=" do it "accepts a lambda with an arity of 2" do h = {} - lambda do - h.default_proc = lambda {|a,b| } + -> do + h.default_proc = -> a, b { } end.should_not raise_error(TypeError) end it "raises a TypeError if passed a lambda with an arity other than 2" do h = {} - lambda do - h.default_proc = lambda {|a| } + -> do + h.default_proc = -> a { } end.should raise_error(TypeError) - lambda do - h.default_proc = lambda {|a,b,c| } + -> do + h.default_proc = -> a, b, c { } end.should raise_error(TypeError) end it "raises a #{frozen_error_class} if self is frozen" do - lambda { {}.freeze.default_proc = Proc.new {} }.should raise_error(frozen_error_class) - lambda { {}.freeze.default_proc = nil }.should raise_error(frozen_error_class) + -> { {}.freeze.default_proc = Proc.new {} }.should raise_error(frozen_error_class) + -> { {}.freeze.default_proc = nil }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/default_spec.rb b/spec/ruby/core/hash/default_spec.rb index afc4f9780f..6cad65bb62 100644 --- a/spec/ruby/core/hash/default_spec.rb +++ b/spec/ruby/core/hash/default_spec.rb @@ -30,7 +30,7 @@ describe "Hash#default=" do end it "unsets the default proc" do - [99, nil, lambda { 6 }].each do |default| + [99, nil, -> { 6 }].each do |default| h = Hash.new { 5 } h.default_proc.should_not == nil h.default = default @@ -40,7 +40,7 @@ describe "Hash#default=" do end it "raises a #{frozen_error_class} if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.default = nil }.should raise_error(frozen_error_class) - lambda { HashSpecs.empty_frozen_hash.default = nil }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.default = nil }.should raise_error(frozen_error_class) + -> { HashSpecs.empty_frozen_hash.default = nil }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/delete_if_spec.rb b/spec/ruby/core/hash/delete_if_spec.rb index 58fba1ff80..345a24a726 100644 --- a/spec/ruby/core/hash/delete_if_spec.rb +++ b/spec/ruby/core/hash/delete_if_spec.rb @@ -35,8 +35,8 @@ describe "Hash#delete_if" do end it "raises a #{frozen_error_class} if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.delete_if { false } }.should raise_error(frozen_error_class) - lambda { HashSpecs.empty_frozen_hash.delete_if { true } }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.delete_if { false } }.should raise_error(frozen_error_class) + -> { HashSpecs.empty_frozen_hash.delete_if { true } }.should raise_error(frozen_error_class) end it_behaves_like :hash_iteration_no_block, :delete_if diff --git a/spec/ruby/core/hash/delete_spec.rb b/spec/ruby/core/hash/delete_spec.rb index 6f0079dafa..a69815c1d9 100644 --- a/spec/ruby/core/hash/delete_spec.rb +++ b/spec/ruby/core/hash/delete_spec.rb @@ -38,7 +38,7 @@ describe "Hash#delete" do end it "raises a #{frozen_error_class} if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.delete("foo") }.should raise_error(frozen_error_class) - lambda { HashSpecs.empty_frozen_hash.delete("foo") }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.delete("foo") }.should raise_error(frozen_error_class) + -> { HashSpecs.empty_frozen_hash.delete("foo") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/dig_spec.rb b/spec/ruby/core/hash/dig_spec.rb index dcba049ac4..aa0ecadd2f 100644 --- a/spec/ruby/core/hash/dig_spec.rb +++ b/spec/ruby/core/hash/dig_spec.rb @@ -28,7 +28,7 @@ describe "Hash#dig" do end it "raises an ArgumentError if no arguments provided" do - lambda { { the: 'borg' }.dig() }.should raise_error(ArgumentError) + -> { { the: 'borg' }.dig() }.should raise_error(ArgumentError) end it "handles type-mixed deep digging" do @@ -47,8 +47,8 @@ describe "Hash#dig" do it "raises TypeError if an intermediate element does not respond to #dig" do h = {} h[:foo] = [ { bar: [ 1 ] }, [ nil, 'str' ] ] - lambda { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError) - lambda { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError) + -> { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError) + -> { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError) end it "calls #dig on the result of #[] with the remaining arguments" do diff --git a/spec/ruby/core/hash/fetch_spec.rb b/spec/ruby/core/hash/fetch_spec.rb index 197832e311..753167f709 100644 --- a/spec/ruby/core/hash/fetch_spec.rb +++ b/spec/ruby/core/hash/fetch_spec.rb @@ -4,10 +4,10 @@ require_relative '../../shared/hash/key_error' describe "Hash#fetch" do context "when the key is not found" do - it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, Hash.new(a: 5) - it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, {} - it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, Hash.new { 5 } - it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, Hash.new(5) + it_behaves_like :key_error, -> obj, key { obj.fetch(key) }, Hash.new(a: 5) + it_behaves_like :key_error, -> obj, key { obj.fetch(key) }, {} + it_behaves_like :key_error, -> obj, key { obj.fetch(key) }, Hash.new { 5 } + it_behaves_like :key_error, -> obj, key { obj.fetch(key) }, Hash.new(5) it "formats the object with #inspect in the KeyError message" do -> { @@ -31,14 +31,14 @@ describe "Hash#fetch" do end it "gives precedence to the default block over the default argument when passed both" do - lambda { + -> { @result = {}.fetch(9, :foo) { |i| i * i } }.should complain(/block supersedes default value argument/) @result.should == 81 end it "raises an ArgumentError when not passed one or two arguments" do - lambda { {}.fetch() }.should raise_error(ArgumentError) - lambda { {}.fetch(1, 2, 3) }.should raise_error(ArgumentError) + -> { {}.fetch() }.should raise_error(ArgumentError) + -> { {}.fetch(1, 2, 3) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/hash/fetch_values_spec.rb b/spec/ruby/core/hash/fetch_values_spec.rb index a4af153bf7..041a3f07e9 100644 --- a/spec/ruby/core/hash/fetch_values_spec.rb +++ b/spec/ruby/core/hash/fetch_values_spec.rb @@ -15,7 +15,7 @@ describe "Hash#fetch_values" do end describe "with unmatched keys" do - it_behaves_like :key_error, ->(obj, key) { obj.fetch_values(key) }, Hash.new(a: 5) + it_behaves_like :key_error, -> obj, key { obj.fetch_values(key) }, Hash.new(a: 5) it "returns the default value from block" do @hash.fetch_values(:z) { |key| "`#{key}' is not found" }.should == ["`z' is not found"] diff --git a/spec/ruby/core/hash/flatten_spec.rb b/spec/ruby/core/hash/flatten_spec.rb index 5a7ddd8baa..825da15bfc 100644 --- a/spec/ruby/core/hash/flatten_spec.rb +++ b/spec/ruby/core/hash/flatten_spec.rb @@ -55,7 +55,7 @@ describe "Hash#flatten" do end it "raises a TypeError if given a non-Integer argument" do - lambda do + -> do @h.flatten(Object.new) end.should raise_error(TypeError) end diff --git a/spec/ruby/core/hash/initialize_spec.rb b/spec/ruby/core/hash/initialize_spec.rb index 344571631a..00e1174ec8 100644 --- a/spec/ruby/core/hash/initialize_spec.rb +++ b/spec/ruby/core/hash/initialize_spec.rb @@ -46,16 +46,16 @@ describe "Hash#initialize" do end it "raises a #{frozen_error_class} if called on a frozen instance" do - block = lambda { HashSpecs.frozen_hash.instance_eval { initialize() }} + block = -> { HashSpecs.frozen_hash.instance_eval { initialize() }} block.should raise_error(frozen_error_class) - block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(nil) } } + block = -> { HashSpecs.frozen_hash.instance_eval { initialize(nil) } } block.should raise_error(frozen_error_class) - block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(5) } } + block = -> { HashSpecs.frozen_hash.instance_eval { initialize(5) } } block.should raise_error(frozen_error_class) - block = lambda { HashSpecs.frozen_hash.instance_eval { initialize { 5 } } } + block = -> { HashSpecs.frozen_hash.instance_eval { initialize { 5 } } } block.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/keep_if_spec.rb b/spec/ruby/core/hash/keep_if_spec.rb index 80f7fbbf64..278eafc969 100644 --- a/spec/ruby/core/hash/keep_if_spec.rb +++ b/spec/ruby/core/hash/keep_if_spec.rb @@ -28,8 +28,8 @@ describe "Hash#keep_if" do end it "raises a #{frozen_error_class} if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.keep_if { true } }.should raise_error(frozen_error_class) - lambda { HashSpecs.empty_frozen_hash.keep_if { false } }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.keep_if { true } }.should raise_error(frozen_error_class) + -> { HashSpecs.empty_frozen_hash.keep_if { false } }.should raise_error(frozen_error_class) end it_behaves_like :hash_iteration_no_block, :keep_if diff --git a/spec/ruby/core/hash/merge_spec.rb b/spec/ruby/core/hash/merge_spec.rb index 77e5c42071..91ded30eb7 100644 --- a/spec/ruby/core/hash/merge_spec.rb +++ b/spec/ruby/core/hash/merge_spec.rb @@ -28,7 +28,7 @@ describe "Hash#merge" do r = h1.merge(h2) { |k,x,y| "#{k}:#{x+2*y}" } r.should == { a: "a:-2", b: "b:9", c: -3, d: 5 } - lambda { + -> { h1.merge(h2) { |k, x, y| raise(IndexError) } }.should raise_error(IndexError) diff --git a/spec/ruby/core/hash/new_spec.rb b/spec/ruby/core/hash/new_spec.rb index c21266777f..6054b69bdd 100644 --- a/spec/ruby/core/hash/new_spec.rb +++ b/spec/ruby/core/hash/new_spec.rb @@ -26,11 +26,11 @@ describe "Hash.new" do end it "raises an ArgumentError if more than one argument is passed" do - lambda { Hash.new(5,6) }.should raise_error(ArgumentError) + -> { Hash.new(5,6) }.should raise_error(ArgumentError) end it "raises an ArgumentError if passed both default argument and default block" do - lambda { Hash.new(5) { 0 } }.should raise_error(ArgumentError) - lambda { Hash.new(nil) { 0 } }.should raise_error(ArgumentError) + -> { Hash.new(5) { 0 } }.should raise_error(ArgumentError) + -> { Hash.new(nil) { 0 } }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/hash/rehash_spec.rb b/spec/ruby/core/hash/rehash_spec.rb index 32ba3fcfb9..9816648f08 100644 --- a/spec/ruby/core/hash/rehash_spec.rb +++ b/spec/ruby/core/hash/rehash_spec.rb @@ -51,7 +51,7 @@ describe "Hash#rehash" do end it "raises a #{frozen_error_class} if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.rehash }.should raise_error(frozen_error_class) - lambda { HashSpecs.empty_frozen_hash.rehash }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.rehash }.should raise_error(frozen_error_class) + -> { HashSpecs.empty_frozen_hash.rehash }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/hash/reject_spec.rb b/spec/ruby/core/hash/reject_spec.rb index a11e80a34a..8016be5e83 100644 --- a/spec/ruby/core/hash/reject_spec.rb +++ b/spec/ruby/core/hash/reject_spec.rb @@ -88,11 +88,11 @@ describe "Hash#reject!" do end it "raises a #{frozen_error_class} if called on a frozen instance that is modified" do - lambda { HashSpecs.empty_frozen_hash.reject! { true } }.should raise_error(frozen_error_class) + -> { HashSpecs.empty_frozen_hash.reject! { true } }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} if called on a frozen instance that would not be modified" do - lambda { HashSpecs.frozen_hash.reject! { false } }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.reject! { false } }.should raise_error(frozen_error_class) end it_behaves_like :hash_iteration_no_block, :reject! diff --git a/spec/ruby/core/hash/shared/comparison.rb b/spec/ruby/core/hash/shared/comparison.rb index bbb9bfd6ad..07564e4cec 100644 --- a/spec/ruby/core/hash/shared/comparison.rb +++ b/spec/ruby/core/hash/shared/comparison.rb @@ -1,8 +1,8 @@ describe :hash_comparison, shared: true do it "raises a TypeError if the right operand is not a hash" do - lambda { { a: 1 }.send(@method, 1) }.should raise_error(TypeError) - lambda { { a: 1 }.send(@method, nil) }.should raise_error(TypeError) - lambda { { a: 1 }.send(@method, []) }.should raise_error(TypeError) + -> { { a: 1 }.send(@method, 1) }.should raise_error(TypeError) + -> { { a: 1 }.send(@method, nil) }.should raise_error(TypeError) + -> { { a: 1 }.send(@method, []) }.should raise_error(TypeError) end it "returns false if both hashes have the same keys but different values" do diff --git a/spec/ruby/core/hash/shared/replace.rb b/spec/ruby/core/hash/shared/replace.rb index eb51130781..b3d098763b 100644 --- a/spec/ruby/core/hash/shared/replace.rb +++ b/spec/ruby/core/hash/shared/replace.rb @@ -32,19 +32,19 @@ describe :hash_replace, shared: true do hash_a.default(5).should == 10 hash_a = Hash.new { |h, k| k * 5 } - hash_b = Hash.new(lambda { raise "Should not invoke lambda" }) + hash_b = Hash.new(-> { raise "Should not invoke lambda" }) hash_a.send(@method, hash_b) hash_a.default.should == hash_b.default end it "raises a #{frozen_error_class} if called on a frozen instance that would not be modified" do - lambda do + -> do HashSpecs.frozen_hash.send(@method, HashSpecs.frozen_hash) end.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} if called on a frozen instance that is modified" do - lambda do + -> do HashSpecs.frozen_hash.send(@method, HashSpecs.empty_frozen_hash) end.should raise_error(frozen_error_class) end diff --git a/spec/ruby/core/hash/shared/select.rb b/spec/ruby/core/hash/shared/select.rb index cc1a54da25..bb781817cb 100644 --- a/spec/ruby/core/hash/shared/select.rb +++ b/spec/ruby/core/hash/shared/select.rb @@ -75,11 +75,11 @@ describe :hash_select!, shared: true do end it "raises a #{frozen_error_class} if called on an empty frozen instance" do - lambda { HashSpecs.empty_frozen_hash.send(@method) { false } }.should raise_error(frozen_error_class) + -> { HashSpecs.empty_frozen_hash.send(@method) { false } }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} if called on a frozen instance that would not be modified" do - lambda { HashSpecs.frozen_hash.send(@method) { true } }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.send(@method) { true } }.should raise_error(frozen_error_class) end it_should_behave_like :hash_iteration_no_block diff --git a/spec/ruby/core/hash/shared/store.rb b/spec/ruby/core/hash/shared/store.rb index de61ed1ad1..ff40bef3ef 100644 --- a/spec/ruby/core/hash/shared/store.rb +++ b/spec/ruby/core/hash/shared/store.rb @@ -87,7 +87,7 @@ describe :hash_store, shared: true do end it "raises a #{frozen_error_class} if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.send(@method, 1, 2) }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.send(@method, 1, 2) }.should raise_error(frozen_error_class) end it "does not raise an exception if changing the value of an existing key during iteration" do diff --git a/spec/ruby/core/hash/shared/to_s.rb b/spec/ruby/core/hash/shared/to_s.rb index 88333e0f42..d180d08c2c 100644 --- a/spec/ruby/core/hash/shared/to_s.rb +++ b/spec/ruby/core/hash/shared/to_s.rb @@ -61,7 +61,7 @@ describe :hash_to_s, shared: true do obj.should_receive(:inspect).and_return(obj) obj.should_receive(:to_s).and_raise(Exception) - lambda { { a: obj }.send(@method) }.should raise_error(Exception) + -> { { a: obj }.send(@method) }.should raise_error(Exception) end it "handles hashes with recursive values" do diff --git a/spec/ruby/core/hash/shared/update.rb b/spec/ruby/core/hash/shared/update.rb index e808add5c0..3af41c450a 100644 --- a/spec/ruby/core/hash/shared/update.rb +++ b/spec/ruby/core/hash/shared/update.rb @@ -35,7 +35,7 @@ describe :hash_update, shared: true do end it "raises a #{frozen_error_class} on a frozen instance that is modified" do - lambda do + -> do HashSpecs.frozen_hash.send(@method, 1 => 2) end.should raise_error(frozen_error_class) end @@ -47,12 +47,12 @@ describe :hash_update, shared: true do def obj.to_hash() raise Exception, "should not receive #to_hash" end obj.freeze - lambda { HashSpecs.frozen_hash.send(@method, obj) }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.send(@method, obj) }.should raise_error(frozen_error_class) end # see redmine #1571 it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do - lambda do + -> do HashSpecs.frozen_hash.send(@method, HashSpecs.empty_frozen_hash) end.should raise_error(frozen_error_class) end diff --git a/spec/ruby/core/hash/shift_spec.rb b/spec/ruby/core/hash/shift_spec.rb index 47c9ac1821..d9f121e38b 100644 --- a/spec/ruby/core/hash/shift_spec.rb +++ b/spec/ruby/core/hash/shift_spec.rb @@ -58,8 +58,8 @@ describe "Hash#shift" do end it "raises a #{frozen_error_class} if called on a frozen instance" do - lambda { HashSpecs.frozen_hash.shift }.should raise_error(frozen_error_class) - lambda { HashSpecs.empty_frozen_hash.shift }.should raise_error(frozen_error_class) + -> { HashSpecs.frozen_hash.shift }.should raise_error(frozen_error_class) + -> { HashSpecs.empty_frozen_hash.shift }.should raise_error(frozen_error_class) end it "works when the hash is at capacity" do diff --git a/spec/ruby/core/hash/to_proc_spec.rb b/spec/ruby/core/hash/to_proc_spec.rb index ca55604043..3e7e57d11f 100644 --- a/spec/ruby/core/hash/to_proc_spec.rb +++ b/spec/ruby/core/hash/to_proc_spec.rb @@ -24,11 +24,11 @@ describe "Hash#to_proc" do end it "raises ArgumentError if not passed exactly one argument" do - lambda { + -> { @proc.call }.should raise_error(ArgumentError) - lambda { + -> { @proc.call 1, 2 }.should raise_error(ArgumentError) end @@ -81,7 +81,7 @@ describe "Hash#to_proc" do end it "raises an ArgumentError when calling #call on the Proc with no arguments" do - lambda { @hash.to_proc.call }.should raise_error(ArgumentError) + -> { @hash.to_proc.call }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/hash/try_convert_spec.rb b/spec/ruby/core/hash/try_convert_spec.rb index 50bb59816c..44195c5010 100644 --- a/spec/ruby/core/hash/try_convert_spec.rb +++ b/spec/ruby/core/hash/try_convert_spec.rb @@ -39,12 +39,12 @@ describe "Hash.try_convert" do it "sends #to_hash to the argument and raises TypeError if it's not a kind of Hash" do obj = mock("to_hash") obj.should_receive(:to_hash).and_return(Object.new) - lambda { Hash.try_convert obj }.should raise_error(TypeError) + -> { Hash.try_convert obj }.should raise_error(TypeError) end it "does not rescue exceptions raised by #to_hash" do obj = mock("to_hash") obj.should_receive(:to_hash).and_raise(RuntimeError) - lambda { Hash.try_convert obj }.should raise_error(RuntimeError) + -> { Hash.try_convert obj }.should raise_error(RuntimeError) end end diff --git a/spec/ruby/core/integer/allbits_spec.rb b/spec/ruby/core/integer/allbits_spec.rb index d7bd58d638..f4a6fe9905 100644 --- a/spec/ruby/core/integer/allbits_spec.rb +++ b/spec/ruby/core/integer/allbits_spec.rb @@ -28,12 +28,12 @@ ruby_version_is '2.5' do end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10]) 13.allbits?(obj) }.should raise_error(TypeError) - lambda { 13.allbits?("10") }.should raise_error(TypeError) - lambda { 13.allbits?(:symbol) }.should raise_error(TypeError) + -> { 13.allbits?("10") }.should raise_error(TypeError) + -> { 13.allbits?(:symbol) }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/anybits_spec.rb b/spec/ruby/core/integer/anybits_spec.rb index 36803694aa..91f349258a 100644 --- a/spec/ruby/core/integer/anybits_spec.rb +++ b/spec/ruby/core/integer/anybits_spec.rb @@ -27,12 +27,12 @@ ruby_version_is '2.5' do end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10]) 13.anybits?(obj) }.should raise_error(TypeError) - lambda { 13.anybits?("10") }.should raise_error(TypeError) - lambda { 13.anybits?(:symbol) }.should raise_error(TypeError) + -> { 13.anybits?("10") }.should raise_error(TypeError) + -> { 13.anybits?(:symbol) }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/bit_and_spec.rb b/spec/ruby/core/integer/bit_and_spec.rb index 8565f82397..15a8026855 100644 --- a/spec/ruby/core/integer/bit_and_spec.rb +++ b/spec/ruby/core/integer/bit_and_spec.rb @@ -35,14 +35,14 @@ describe "Integer#&" do end it "raises a TypeError when passed a Float" do - lambda { (3 & 3.4) }.should raise_error(TypeError) + -> { (3 & 3.4) }.should raise_error(TypeError) end it "raises a TypeError and does not call #to_int when defined on an object" do obj = mock("fixnum bit and") obj.should_not_receive(:to_int) - lambda { 3 & obj }.should raise_error(TypeError) + -> { 3 & obj }.should raise_error(TypeError) end end @@ -84,14 +84,14 @@ describe "Integer#&" do end it "raises a TypeError when passed a Float" do - lambda { (@bignum & 3.4) }.should raise_error(TypeError) + -> { (@bignum & 3.4) }.should raise_error(TypeError) end it "raises a TypeError and does not call #to_int when defined on an object" do obj = mock("bignum bit and") obj.should_not_receive(:to_int) - lambda { @bignum & obj }.should raise_error(TypeError) + -> { @bignum & obj }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/bit_or_spec.rb b/spec/ruby/core/integer/bit_or_spec.rb index 16ab430f8b..e486eeec10 100644 --- a/spec/ruby/core/integer/bit_or_spec.rb +++ b/spec/ruby/core/integer/bit_or_spec.rb @@ -15,14 +15,14 @@ describe "Integer#|" do end it "raises a TypeError when passed a Float" do - lambda { (3 | 3.4) }.should raise_error(TypeError) + -> { (3 | 3.4) }.should raise_error(TypeError) end it "raises a TypeError and does not call #to_int when defined on an object" do obj = mock("integer bit or") obj.should_not_receive(:to_int) - lambda { 3 | obj }.should raise_error(TypeError) + -> { 3 | obj }.should raise_error(TypeError) end end @@ -51,18 +51,18 @@ describe "Integer#|" do it "raises a TypeError when passed a Float" do not_supported_on :opal do - lambda { + -> { bignum_value | bignum_value(0xffff).to_f }.should raise_error(TypeError) end - lambda { @bignum | 9.9 }.should raise_error(TypeError) + -> { @bignum | 9.9 }.should raise_error(TypeError) end it "raises a TypeError and does not call #to_int when defined on an object" do obj = mock("bignum bit or") obj.should_not_receive(:to_int) - lambda { @bignum | obj }.should raise_error(TypeError) + -> { @bignum | obj }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/bit_xor_spec.rb b/spec/ruby/core/integer/bit_xor_spec.rb index 65f88341e0..ac8826a52f 100644 --- a/spec/ruby/core/integer/bit_xor_spec.rb +++ b/spec/ruby/core/integer/bit_xor_spec.rb @@ -13,14 +13,14 @@ describe "Integer#^" do end it "raises a TypeError when passed a Float" do - lambda { (3 ^ 3.4) }.should raise_error(TypeError) + -> { (3 ^ 3.4) }.should raise_error(TypeError) end it "raises a TypeError and does not call #to_int when defined on an object" do obj = mock("integer bit xor") obj.should_not_receive(:to_int) - lambda { 3 ^ obj }.should raise_error(TypeError) + -> { 3 ^ obj }.should raise_error(TypeError) end end @@ -55,18 +55,18 @@ describe "Integer#^" do it "raises a TypeError when passed a Float" do not_supported_on :opal do - lambda { + -> { bignum_value ^ bignum_value(0xffff).to_f }.should raise_error(TypeError) end - lambda { @bignum ^ 14.5 }.should raise_error(TypeError) + -> { @bignum ^ 14.5 }.should raise_error(TypeError) end it "raises a TypeError and does not call #to_int when defined on an object" do obj = mock("bignum bit xor") obj.should_not_receive(:to_int) - lambda { @bignum ^ obj }.should raise_error(TypeError) + -> { @bignum ^ obj }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/chr_spec.rb b/spec/ruby/core/integer/chr_spec.rb index 02d0283182..a8755eeb84 100644 --- a/spec/ruby/core/integer/chr_spec.rb +++ b/spec/ruby/core/integer/chr_spec.rb @@ -10,8 +10,8 @@ describe "Integer#chr without argument" do end it "raises a RangeError is self is less than 0" do - lambda { -1.chr }.should raise_error(RangeError) - lambda { -bignum_value.chr }.should raise_error(RangeError) + -> { -1.chr }.should raise_error(RangeError) + -> { -bignum_value.chr }.should raise_error(RangeError) end describe "when Encoding.default_internal is nil" do @@ -44,8 +44,8 @@ describe "Integer#chr without argument" do end it "raises a RangeError is self is greater than 255" do - lambda { 256.chr }.should raise_error(RangeError) - lambda { bignum_value.chr }.should raise_error(RangeError) + -> { 256.chr }.should raise_error(RangeError) + -> { bignum_value.chr }.should raise_error(RangeError) end end @@ -133,7 +133,7 @@ describe "Integer#chr without argument" do [620, "TIS-620"] ].each do |integer, encoding_name| Encoding.default_internal = Encoding.find(encoding_name) - lambda { integer.chr }.should raise_error(RangeError) + -> { integer.chr }.should raise_error(RangeError) end end end @@ -150,7 +150,7 @@ describe "Integer#chr with an encoding argument" do end it "accepts a String as an argument" do - lambda { 0xA4A2.chr('euc-jp') }.should_not raise_error + -> { 0xA4A2.chr('euc-jp') }.should_not raise_error end it "converts a String to an Encoding as Encoding.find does" do @@ -161,12 +161,12 @@ describe "Integer#chr with an encoding argument" do # http://redmine.ruby-lang.org/issues/4869 it "raises a RangeError is self is less than 0" do - lambda { -1.chr(Encoding::UTF_8) }.should raise_error(RangeError) - lambda { -bignum_value.chr(Encoding::EUC_JP) }.should raise_error(RangeError) + -> { -1.chr(Encoding::UTF_8) }.should raise_error(RangeError) + -> { -bignum_value.chr(Encoding::EUC_JP) }.should raise_error(RangeError) end it "raises a RangeError if self is too large" do - lambda { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError) + -> { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError) end it "returns a String with the specified encoding" do @@ -237,7 +237,7 @@ describe "Integer#chr with an encoding argument" do [0xDC00, "UTF-16"], [0xDFFF, "UTF-16"], ].each do |integer, encoding_name| - lambda { integer.chr(encoding_name) }.should raise_error(RangeError) + -> { integer.chr(encoding_name) }.should raise_error(RangeError) end end end diff --git a/spec/ruby/core/integer/coerce_spec.rb b/spec/ruby/core/integer/coerce_spec.rb index 8db15bbaed..9a19baf2ea 100644 --- a/spec/ruby/core/integer/coerce_spec.rb +++ b/spec/ruby/core/integer/coerce_spec.rb @@ -1,5 +1,7 @@ require_relative '../../spec_helper' +require 'bigdecimal' + describe "Integer#coerce" do context "fixnum" do describe "when given a Fixnum" do @@ -11,7 +13,7 @@ describe "Integer#coerce" do describe "when given a String" do it "raises an ArgumentError when trying to coerce with a non-number String" do - lambda { 1.coerce(":)") }.should raise_error(ArgumentError) + -> { 1.coerce(":)") }.should raise_error(ArgumentError) end it "returns an array containing two Floats" do @@ -21,7 +23,7 @@ describe "Integer#coerce" do end it "raises a TypeError when trying to coerce with nil" do - lambda { 1.coerce(nil) }.should raise_error(TypeError) + -> { 1.coerce(nil) }.should raise_error(TypeError) end it "tries to convert the given Object into a Float by using #to_f" do @@ -29,13 +31,13 @@ describe "Integer#coerce" do 2.coerce(obj).should == [1.0, 2.0] (obj = mock('0')).should_receive(:to_f).and_return('0') - lambda { 2.coerce(obj).should == [1.0, 2.0] }.should raise_error(TypeError) + -> { 2.coerce(obj).should == [1.0, 2.0] }.should raise_error(TypeError) end it "raises a TypeError when given an Object that does not respond to #to_f" do - lambda { 1.coerce(mock('x')) }.should raise_error(TypeError) - lambda { 1.coerce(1..4) }.should raise_error(TypeError) - lambda { 1.coerce(:test) }.should raise_error(TypeError) + -> { 1.coerce(mock('x')) }.should raise_error(TypeError) + -> { 1.coerce(1..4) }.should raise_error(TypeError) + -> { 1.coerce(:test) }.should raise_error(TypeError) end end @@ -62,10 +64,10 @@ describe "Integer#coerce" do it "raises a TypeError when not passed a Fixnum or Bignum" do a = bignum_value - lambda { a.coerce(nil) }.should raise_error(TypeError) - lambda { a.coerce(mock('str')) }.should raise_error(TypeError) - lambda { a.coerce(1..4) }.should raise_error(TypeError) - lambda { a.coerce(:test) }.should raise_error(TypeError) + -> { a.coerce(nil) }.should raise_error(TypeError) + -> { a.coerce(mock('str')) }.should raise_error(TypeError) + -> { a.coerce(1..4) }.should raise_error(TypeError) + -> { a.coerce(:test) }.should raise_error(TypeError) end it "coerces both values to Floats and returns [other, self] when passed a Float" do @@ -88,4 +90,15 @@ describe "Integer#coerce" do ary.should == [1.2, a.to_f] end end + + context "bigdecimal" do + it "produces Floats" do + x, y = 3.coerce(BigDecimal("3.4")) + x.class.should == Float + x.should == 3.4 + y.class.should == Float + y.should == 3.0 + end + end + end diff --git a/spec/ruby/core/integer/comparison_spec.rb b/spec/ruby/core/integer/comparison_spec.rb index 4cf1d7cdc7..762af51535 100644 --- a/spec/ruby/core/integer/comparison_spec.rb +++ b/spec/ruby/core/integer/comparison_spec.rb @@ -127,7 +127,7 @@ describe "Integer#<=>" do ruby_version_is ""..."2.5" do it "returns nil if #coerce raises an exception" do @num.should_receive(:coerce).with(@big).and_raise(RuntimeError) - lambda { + -> { @result = (@big <=> @num) }.should complain(/Numerical comparison operators will no more rescue exceptions/) @result.should be_nil @@ -137,7 +137,7 @@ describe "Integer#<=>" do ruby_version_is "2.5" do it "lets the exception go through if #coerce raises an exception" do @num.should_receive(:coerce).with(@big).and_raise(RuntimeError.new("my error")) - lambda { + -> { @big <=> @num }.should raise_error(RuntimeError, "my error") end @@ -145,7 +145,7 @@ describe "Integer#<=>" do it "raises an exception if #coerce raises a non-StandardError exception" do @num.should_receive(:coerce).with(@big).and_raise(Exception) - lambda { @big <=> @num }.should raise_error(Exception) + -> { @big <=> @num }.should raise_error(Exception) end it "returns nil if #coerce does not return an Array" do diff --git a/spec/ruby/core/integer/digits_spec.rb b/spec/ruby/core/integer/digits_spec.rb index 85afb6f50f..4a8e33980c 100644 --- a/spec/ruby/core/integer/digits_spec.rb +++ b/spec/ruby/core/integer/digits_spec.rb @@ -19,14 +19,14 @@ describe "Integer#digits" do end it "raises ArgumentError when calling with a radix less than 2" do - lambda { 12345.digits(1) }.should raise_error(ArgumentError) + -> { 12345.digits(1) }.should raise_error(ArgumentError) end it "raises ArgumentError when calling with a negative radix" do - lambda { 12345.digits(-2) }.should raise_error(ArgumentError) + -> { 12345.digits(-2) }.should raise_error(ArgumentError) end it "raises Math::DomainError when calling digits on a negative number" do - lambda { -12345.digits(7) }.should raise_error(Math::DomainError) + -> { -12345.digits(7) }.should raise_error(Math::DomainError) end end diff --git a/spec/ruby/core/integer/div_spec.rb b/spec/ruby/core/integer/div_spec.rb index ca69ff4681..087d012fe0 100644 --- a/spec/ruby/core/integer/div_spec.rb +++ b/spec/ruby/core/integer/div_spec.rb @@ -46,21 +46,21 @@ describe "Integer#div" do end it "raises a ZeroDivisionError when the given argument is 0 and a Float" do - lambda { 0.div(0.0) }.should raise_error(ZeroDivisionError) - lambda { 10.div(0.0) }.should raise_error(ZeroDivisionError) - lambda { -10.div(0.0) }.should raise_error(ZeroDivisionError) + -> { 0.div(0.0) }.should raise_error(ZeroDivisionError) + -> { 10.div(0.0) }.should raise_error(ZeroDivisionError) + -> { -10.div(0.0) }.should raise_error(ZeroDivisionError) end it "raises a ZeroDivisionError when the given argument is 0 and not a Float" do - lambda { 13.div(0) }.should raise_error(ZeroDivisionError) - lambda { 13.div(-0) }.should raise_error(ZeroDivisionError) + -> { 13.div(0) }.should raise_error(ZeroDivisionError) + -> { 13.div(-0) }.should raise_error(ZeroDivisionError) end it "raises a TypeError when given a non-numeric argument" do - lambda { 13.div(mock('10')) }.should raise_error(TypeError) - lambda { 5.div("2") }.should raise_error(TypeError) - lambda { 5.div(:"2") }.should raise_error(TypeError) - lambda { 5.div([]) }.should raise_error(TypeError) + -> { 13.div(mock('10')) }.should raise_error(TypeError) + -> { 5.div("2") }.should raise_error(TypeError) + -> { 5.div(:"2") }.should raise_error(TypeError) + -> { 5.div([]) }.should raise_error(TypeError) end end @@ -118,9 +118,9 @@ describe "Integer#div" do end it "raises a TypeError when given a non-numeric" do - lambda { @bignum.div(mock("10")) }.should raise_error(TypeError) - lambda { @bignum.div("2") }.should raise_error(TypeError) - lambda { @bignum.div(:symbol) }.should raise_error(TypeError) + -> { @bignum.div(mock("10")) }.should raise_error(TypeError) + -> { @bignum.div("2") }.should raise_error(TypeError) + -> { @bignum.div(:symbol) }.should raise_error(TypeError) end it "returns a result of integer division of self by a float argument" do @@ -134,13 +134,13 @@ describe "Integer#div" do # #5490 it "raises ZeroDivisionError if the argument is 0 and is a Float" do - lambda { @bignum.div(0.0) }.should raise_error(ZeroDivisionError) - lambda { @bignum.div(-0.0) }.should raise_error(ZeroDivisionError) + -> { @bignum.div(0.0) }.should raise_error(ZeroDivisionError) + -> { @bignum.div(-0.0) }.should raise_error(ZeroDivisionError) end it "raises ZeroDivisionError if the argument is 0 and is not a Float" do - lambda { @bignum.div(0) }.should raise_error(ZeroDivisionError) - lambda { @bignum.div(-0) }.should raise_error(ZeroDivisionError) + -> { @bignum.div(0) }.should raise_error(ZeroDivisionError) + -> { @bignum.div(-0) }.should raise_error(ZeroDivisionError) end end end diff --git a/spec/ruby/core/integer/divide_spec.rb b/spec/ruby/core/integer/divide_spec.rb index 2d49307628..a32d68c229 100644 --- a/spec/ruby/core/integer/divide_spec.rb +++ b/spec/ruby/core/integer/divide_spec.rb @@ -27,7 +27,7 @@ describe "Integer#/" do end it "raises a ZeroDivisionError if the given argument is zero and not a Float" do - lambda { 1 / 0 }.should raise_error(ZeroDivisionError) + -> { 1 / 0 }.should raise_error(ZeroDivisionError) end it "does NOT raise ZeroDivisionError if the given argument is zero and is a Float" do @@ -41,9 +41,9 @@ describe "Integer#/" do end it "raises a TypeError when given a non-Integer" do - lambda { 13 / mock('10') }.should raise_error(TypeError) - lambda { 13 / "10" }.should raise_error(TypeError) - lambda { 13 / :symbol }.should raise_error(TypeError) + -> { 13 / mock('10') }.should raise_error(TypeError) + -> { 13 / "10" }.should raise_error(TypeError) + -> { 13 / :symbol }.should raise_error(TypeError) end end @@ -83,13 +83,13 @@ describe "Integer#/" do end it "raises a ZeroDivisionError if other is zero and not a Float" do - lambda { @bignum / 0 }.should raise_error(ZeroDivisionError) + -> { @bignum / 0 }.should raise_error(ZeroDivisionError) end it "raises a TypeError when given a non-numeric" do - lambda { @bignum / mock('10') }.should raise_error(TypeError) - lambda { @bignum / "2" }.should raise_error(TypeError) - lambda { @bignum / :symbol }.should raise_error(TypeError) + -> { @bignum / mock('10') }.should raise_error(TypeError) + -> { @bignum / "2" }.should raise_error(TypeError) + -> { @bignum / :symbol }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/divmod_spec.rb b/spec/ruby/core/integer/divmod_spec.rb index 27fb34574c..d88925caad 100644 --- a/spec/ruby/core/integer/divmod_spec.rb +++ b/spec/ruby/core/integer/divmod_spec.rb @@ -14,24 +14,24 @@ describe "Integer#divmod" do end it "raises a ZeroDivisionError when the given argument is 0" do - lambda { 13.divmod(0) }.should raise_error(ZeroDivisionError) - lambda { 0.divmod(0) }.should raise_error(ZeroDivisionError) - lambda { -10.divmod(0) }.should raise_error(ZeroDivisionError) + -> { 13.divmod(0) }.should raise_error(ZeroDivisionError) + -> { 0.divmod(0) }.should raise_error(ZeroDivisionError) + -> { -10.divmod(0) }.should raise_error(ZeroDivisionError) end it "raises a ZeroDivisionError when the given argument is 0 and a Float" do - lambda { 0.divmod(0.0) }.should raise_error(ZeroDivisionError) - lambda { 10.divmod(0.0) }.should raise_error(ZeroDivisionError) - lambda { -10.divmod(0.0) }.should raise_error(ZeroDivisionError) + -> { 0.divmod(0.0) }.should raise_error(ZeroDivisionError) + -> { 10.divmod(0.0) }.should raise_error(ZeroDivisionError) + -> { -10.divmod(0.0) }.should raise_error(ZeroDivisionError) end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10) 13.divmod(obj) }.should raise_error(TypeError) - lambda { 13.divmod("10") }.should raise_error(TypeError) - lambda { 13.divmod(:symbol) }.should raise_error(TypeError) + -> { 13.divmod("10") }.should raise_error(TypeError) + -> { 13.divmod(:symbol) }.should raise_error(TypeError) end end @@ -94,24 +94,24 @@ describe "Integer#divmod" do end it "raises a ZeroDivisionError when the given argument is 0" do - lambda { @bignum.divmod(0) }.should raise_error(ZeroDivisionError) - lambda { (-@bignum).divmod(0) }.should raise_error(ZeroDivisionError) + -> { @bignum.divmod(0) }.should raise_error(ZeroDivisionError) + -> { (-@bignum).divmod(0) }.should raise_error(ZeroDivisionError) end # Behaviour established as correct in r23953 it "raises a FloatDomainError if other is NaN" do - lambda { @bignum.divmod(nan_value) }.should raise_error(FloatDomainError) + -> { @bignum.divmod(nan_value) }.should raise_error(FloatDomainError) end it "raises a ZeroDivisionError when the given argument is 0 and a Float" do - lambda { @bignum.divmod(0.0) }.should raise_error(ZeroDivisionError) - lambda { (-@bignum).divmod(0.0) }.should raise_error(ZeroDivisionError) + -> { @bignum.divmod(0.0) }.should raise_error(ZeroDivisionError) + -> { (-@bignum).divmod(0.0) }.should raise_error(ZeroDivisionError) end it "raises a TypeError when the given argument is not an Integer" do - lambda { @bignum.divmod(mock('10')) }.should raise_error(TypeError) - lambda { @bignum.divmod("10") }.should raise_error(TypeError) - lambda { @bignum.divmod(:symbol) }.should raise_error(TypeError) + -> { @bignum.divmod(mock('10')) }.should raise_error(TypeError) + -> { @bignum.divmod("10") }.should raise_error(TypeError) + -> { @bignum.divmod(:symbol) }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/downto_spec.rb b/spec/ruby/core/integer/downto_spec.rb index 92dee89fc9..af7a7e36b9 100644 --- a/spec/ruby/core/integer/downto_spec.rb +++ b/spec/ruby/core/integer/downto_spec.rb @@ -27,8 +27,8 @@ describe "Integer#downto [stop] when self and stop are Fixnums" do end it "raises an ArgumentError for invalid endpoints" do - lambda {1.downto("A") {|x| p x } }.should raise_error(ArgumentError) - lambda {1.downto(nil) {|x| p x } }.should raise_error(ArgumentError) + -> {1.downto("A") {|x| p x } }.should raise_error(ArgumentError) + -> {1.downto(nil) {|x| p x } }.should raise_error(ArgumentError) end describe "when no block is given" do @@ -45,9 +45,9 @@ describe "Integer#downto [stop] when self and stop are Fixnums" do describe "size" do it "raises an ArgumentError for invalid endpoints" do enum = 1.downto("A") - lambda { enum.size }.should raise_error(ArgumentError) + -> { enum.size }.should raise_error(ArgumentError) enum = 1.downto(nil) - lambda { enum.size }.should raise_error(ArgumentError) + -> { enum.size }.should raise_error(ArgumentError) end it "returns self - stop + 1" do diff --git a/spec/ruby/core/integer/element_reference_spec.rb b/spec/ruby/core/integer/element_reference_spec.rb index 6c72a717d6..99283fac34 100644 --- a/spec/ruby/core/integer/element_reference_spec.rb +++ b/spec/ruby/core/integer/element_reference_spec.rb @@ -59,13 +59,13 @@ describe "Integer#[]" do end it "raises a TypeError when passed a String" do - lambda { 3["3"] }.should raise_error(TypeError) + -> { 3["3"] }.should raise_error(TypeError) end it "raises a TypeError when #to_int does not return an Integer" do obj = mock('asdf') obj.should_receive(:to_int).and_return("asdf") - lambda { 3[obj] }.should raise_error(TypeError) + -> { 3[obj] }.should raise_error(TypeError) end it "calls #to_int to coerce a String to a Bignum and returns 0" do @@ -102,10 +102,10 @@ describe "Integer#[]" do it "raises a TypeError when the given argument can't be converted to Integer" do obj = mock('asdf') - lambda { @bignum[obj] }.should raise_error(TypeError) + -> { @bignum[obj] }.should raise_error(TypeError) obj.should_receive(:to_int).and_return("asdf") - lambda { @bignum[obj] }.should raise_error(TypeError) + -> { @bignum[obj] }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/fdiv_spec.rb b/spec/ruby/core/integer/fdiv_spec.rb index b27e6f1389..6de170278f 100644 --- a/spec/ruby/core/integer/fdiv_spec.rb +++ b/spec/ruby/core/integer/fdiv_spec.rb @@ -35,11 +35,11 @@ describe "Integer#fdiv" do end it "raises a TypeError when argument isn't numeric" do - lambda { 1.fdiv(mock('non-numeric')) }.should raise_error(TypeError) + -> { 1.fdiv(mock('non-numeric')) }.should raise_error(TypeError) end it "raises an ArgumentError when passed multiple arguments" do - lambda { 1.fdiv(6,0.2) }.should raise_error(ArgumentError) + -> { 1.fdiv(6,0.2) }.should raise_error(ArgumentError) end it "follows the coercion protocol" do diff --git a/spec/ruby/core/integer/gcd_spec.rb b/spec/ruby/core/integer/gcd_spec.rb index 238bf66cc0..8aa654a16a 100644 --- a/spec/ruby/core/integer/gcd_spec.rb +++ b/spec/ruby/core/integer/gcd_spec.rb @@ -55,15 +55,15 @@ describe "Integer#gcd" do end it "raises an ArgumentError if not given an argument" do - lambda { 12.gcd }.should raise_error(ArgumentError) + -> { 12.gcd }.should raise_error(ArgumentError) end it "raises an ArgumentError if given more than one argument" do - lambda { 12.gcd(30, 20) }.should raise_error(ArgumentError) + -> { 12.gcd(30, 20) }.should raise_error(ArgumentError) end it "raises a TypeError unless the argument is an Integer" do - lambda { 39.gcd(3.8) }.should raise_error(TypeError) - lambda { 45872.gcd([]) }.should raise_error(TypeError) + -> { 39.gcd(3.8) }.should raise_error(TypeError) + -> { 45872.gcd([]) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/integer/gcdlcm_spec.rb b/spec/ruby/core/integer/gcdlcm_spec.rb index 362f8a51bd..5b3669e62a 100644 --- a/spec/ruby/core/integer/gcdlcm_spec.rb +++ b/spec/ruby/core/integer/gcdlcm_spec.rb @@ -39,15 +39,15 @@ describe "Integer#gcdlcm" do end it "raises an ArgumentError if not given an argument" do - lambda { 12.gcdlcm }.should raise_error(ArgumentError) + -> { 12.gcdlcm }.should raise_error(ArgumentError) end it "raises an ArgumentError if given more than one argument" do - lambda { 12.gcdlcm(30, 20) }.should raise_error(ArgumentError) + -> { 12.gcdlcm(30, 20) }.should raise_error(ArgumentError) end it "raises a TypeError unless the argument is an Integer" do - lambda { 39.gcdlcm(3.8) }.should raise_error(TypeError) - lambda { 45872.gcdlcm([]) }.should raise_error(TypeError) + -> { 39.gcdlcm(3.8) }.should raise_error(TypeError) + -> { 45872.gcdlcm([]) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/integer/gt_spec.rb b/spec/ruby/core/integer/gt_spec.rb index 14c51c9acc..428a6f6888 100644 --- a/spec/ruby/core/integer/gt_spec.rb +++ b/spec/ruby/core/integer/gt_spec.rb @@ -23,8 +23,8 @@ describe "Integer#>" do end it "raises an ArgumentError when given a non-Integer" do - lambda { 5 > "4" }.should raise_error(ArgumentError) - lambda { 5 > mock('x') }.should raise_error(ArgumentError) + -> { 5 > "4" }.should raise_error(ArgumentError) + -> { 5 > mock('x') }.should raise_error(ArgumentError) end end @@ -42,8 +42,8 @@ describe "Integer#>" do end it "raises an ArgumentError when given a non-Integer" do - lambda { @bignum > "4" }.should raise_error(ArgumentError) - lambda { @bignum > mock('str') }.should raise_error(ArgumentError) + -> { @bignum > "4" }.should raise_error(ArgumentError) + -> { @bignum > mock('str') }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/integer/gte_spec.rb b/spec/ruby/core/integer/gte_spec.rb index 3d5c48faa5..ce1385c360 100644 --- a/spec/ruby/core/integer/gte_spec.rb +++ b/spec/ruby/core/integer/gte_spec.rb @@ -24,8 +24,8 @@ describe "Integer#>=" do end it "raises an ArgumentError when given a non-Integer" do - lambda { 5 >= "4" }.should raise_error(ArgumentError) - lambda { 5 >= mock('x') }.should raise_error(ArgumentError) + -> { 5 >= "4" }.should raise_error(ArgumentError) + -> { 5 >= mock('x') }.should raise_error(ArgumentError) end end @@ -42,8 +42,8 @@ describe "Integer#>=" do end it "raises an ArgumentError when given a non-Integer" do - lambda { @bignum >= "4" }.should raise_error(ArgumentError) - lambda { @bignum >= mock('str') }.should raise_error(ArgumentError) + -> { @bignum >= "4" }.should raise_error(ArgumentError) + -> { @bignum >= mock('str') }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/integer/lcm_spec.rb b/spec/ruby/core/integer/lcm_spec.rb index 6d608bdf41..77d3ad3488 100644 --- a/spec/ruby/core/integer/lcm_spec.rb +++ b/spec/ruby/core/integer/lcm_spec.rb @@ -44,15 +44,15 @@ describe "Integer#lcm" do end it "raises an ArgumentError if not given an argument" do - lambda { 12.lcm }.should raise_error(ArgumentError) + -> { 12.lcm }.should raise_error(ArgumentError) end it "raises an ArgumentError if given more than one argument" do - lambda { 12.lcm(30, 20) }.should raise_error(ArgumentError) + -> { 12.lcm(30, 20) }.should raise_error(ArgumentError) end it "raises a TypeError unless the argument is an Integer" do - lambda { 39.lcm(3.8) }.should raise_error(TypeError) - lambda { 45872.lcm([]) }.should raise_error(TypeError) + -> { 39.lcm(3.8) }.should raise_error(TypeError) + -> { 45872.lcm([]) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/integer/left_shift_spec.rb b/spec/ruby/core/integer/left_shift_spec.rb index a240c541c5..4b5ef9386e 100644 --- a/spec/ruby/core/integer/left_shift_spec.rb +++ b/spec/ruby/core/integer/left_shift_spec.rb @@ -79,15 +79,15 @@ describe "Integer#<< (with n << m)" do obj = mock("a string") obj.should_receive(:to_int).and_return("asdf") - lambda { 3 << obj }.should raise_error(TypeError) + -> { 3 << obj }.should raise_error(TypeError) end it "raises a TypeError when passed nil" do - lambda { 3 << nil }.should raise_error(TypeError) + -> { 3 << nil }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { 3 << "4" }.should raise_error(TypeError) + -> { 3 << "4" }.should raise_error(TypeError) end end @@ -151,15 +151,15 @@ describe "Integer#<< (with n << m)" do obj = mock("a string") obj.should_receive(:to_int).and_return("asdf") - lambda { @bignum << obj }.should raise_error(TypeError) + -> { @bignum << obj }.should raise_error(TypeError) end it "raises a TypeError when passed nil" do - lambda { @bignum << nil }.should raise_error(TypeError) + -> { @bignum << nil }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { @bignum << "4" }.should raise_error(TypeError) + -> { @bignum << "4" }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/lt_spec.rb b/spec/ruby/core/integer/lt_spec.rb index a33a297d8b..dfe2d9e369 100644 --- a/spec/ruby/core/integer/lt_spec.rb +++ b/spec/ruby/core/integer/lt_spec.rb @@ -23,8 +23,8 @@ describe "Integer#<" do end it "raises an ArgumentError when given a non-Integer" do - lambda { 5 < "4" }.should raise_error(ArgumentError) - lambda { 5 < mock('x') }.should raise_error(ArgumentError) + -> { 5 < "4" }.should raise_error(ArgumentError) + -> { 5 < mock('x') }.should raise_error(ArgumentError) end end @@ -44,8 +44,8 @@ describe "Integer#<" do end it "raises an ArgumentError when given a non-Integer" do - lambda { @bignum < "4" }.should raise_error(ArgumentError) - lambda { @bignum < mock('str') }.should raise_error(ArgumentError) + -> { @bignum < "4" }.should raise_error(ArgumentError) + -> { @bignum < mock('str') }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/integer/lte_spec.rb b/spec/ruby/core/integer/lte_spec.rb index 1d3ecea2ac..3d843a5dd9 100644 --- a/spec/ruby/core/integer/lte_spec.rb +++ b/spec/ruby/core/integer/lte_spec.rb @@ -24,8 +24,8 @@ describe "Integer#<=" do end it "raises an ArgumentError when given a non-Integer" do - lambda { 5 <= "4" }.should raise_error(ArgumentError) - lambda { 5 <= mock('x') }.should raise_error(ArgumentError) + -> { 5 <= "4" }.should raise_error(ArgumentError) + -> { 5 <= mock('x') }.should raise_error(ArgumentError) end end @@ -47,8 +47,8 @@ describe "Integer#<=" do end it "raises an ArgumentError when given a non-Integer" do - lambda { @bignum <= "4" }.should raise_error(ArgumentError) - lambda { @bignum <= mock('str') }.should raise_error(ArgumentError) + -> { @bignum <= "4" }.should raise_error(ArgumentError) + -> { @bignum <= mock('str') }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/integer/minus_spec.rb b/spec/ruby/core/integer/minus_spec.rb index 84db427172..34dd36c1a7 100644 --- a/spec/ruby/core/integer/minus_spec.rb +++ b/spec/ruby/core/integer/minus_spec.rb @@ -20,12 +20,12 @@ describe "Integer#-" do end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10) 13 - obj }.should raise_error(TypeError) - lambda { 13 - "10" }.should raise_error(TypeError) - lambda { 13 - :symbol }.should raise_error(TypeError) + -> { 13 - "10" }.should raise_error(TypeError) + -> { 13 - :symbol }.should raise_error(TypeError) end end @@ -41,9 +41,9 @@ describe "Integer#-" do end it "raises a TypeError when given a non-Integer" do - lambda { @bignum - mock('10') }.should raise_error(TypeError) - lambda { @bignum - "10" }.should raise_error(TypeError) - lambda { @bignum - :symbol }.should raise_error(TypeError) + -> { @bignum - mock('10') }.should raise_error(TypeError) + -> { @bignum - "10" }.should raise_error(TypeError) + -> { @bignum - :symbol }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/multiply_spec.rb b/spec/ruby/core/integer/multiply_spec.rb index 1683b0c96e..919786cbcc 100644 --- a/spec/ruby/core/integer/multiply_spec.rb +++ b/spec/ruby/core/integer/multiply_spec.rb @@ -21,12 +21,12 @@ describe "Integer#*" do end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10) 13 * obj }.should raise_error(TypeError) - lambda { 13 * "10" }.should raise_error(TypeError) - lambda { 13 * :symbol }.should raise_error(TypeError) + -> { 13 * "10" }.should raise_error(TypeError) + -> { 13 * :symbol }.should raise_error(TypeError) end end @@ -43,9 +43,9 @@ describe "Integer#*" do end it "raises a TypeError when given a non-Integer" do - lambda { @bignum * mock('10') }.should raise_error(TypeError) - lambda { @bignum * "10" }.should raise_error(TypeError) - lambda { @bignum * :symbol }.should raise_error(TypeError) + -> { @bignum * mock('10') }.should raise_error(TypeError) + -> { @bignum * "10" }.should raise_error(TypeError) + -> { @bignum * :symbol }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/nobits_spec.rb b/spec/ruby/core/integer/nobits_spec.rb index da689de5df..af3b9e7db0 100644 --- a/spec/ruby/core/integer/nobits_spec.rb +++ b/spec/ruby/core/integer/nobits_spec.rb @@ -27,12 +27,12 @@ ruby_version_is '2.5' do end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10]) 13.nobits?(obj) }.should raise_error(TypeError) - lambda { 13.nobits?("10") }.should raise_error(TypeError) - lambda { 13.nobits?(:symbol) }.should raise_error(TypeError) + -> { 13.nobits?("10") }.should raise_error(TypeError) + -> { 13.nobits?(:symbol) }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/plus_spec.rb b/spec/ruby/core/integer/plus_spec.rb index 2880840bc1..7e919a16db 100644 --- a/spec/ruby/core/integer/plus_spec.rb +++ b/spec/ruby/core/integer/plus_spec.rb @@ -20,12 +20,12 @@ describe "Integer#+" do end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10) 13 + obj }.should raise_error(TypeError) - lambda { 13 + "10" }.should raise_error(TypeError) - lambda { 13 + :symbol }.should raise_error(TypeError) + -> { 13 + "10" }.should raise_error(TypeError) + -> { 13 + :symbol }.should raise_error(TypeError) end end @@ -41,9 +41,9 @@ describe "Integer#+" do end it "raises a TypeError when given a non-Integer" do - lambda { @bignum + mock('10') }.should raise_error(TypeError) - lambda { @bignum + "10" }.should raise_error(TypeError) - lambda { @bignum + :symbol}.should raise_error(TypeError) + -> { @bignum + mock('10') }.should raise_error(TypeError) + -> { @bignum + "10" }.should raise_error(TypeError) + -> { @bignum + :symbol}.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/rationalize_spec.rb b/spec/ruby/core/integer/rationalize_spec.rb index 590ab40cb2..09d741af33 100644 --- a/spec/ruby/core/integer/rationalize_spec.rb +++ b/spec/ruby/core/integer/rationalize_spec.rb @@ -33,7 +33,7 @@ describe "Integer#rationalize" do end it "raises ArgumentError when passed more than one argument" do - lambda { 1.rationalize(0.1, 0.1) }.should raise_error(ArgumentError) - lambda { 1.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) + -> { 1.rationalize(0.1, 0.1) }.should raise_error(ArgumentError) + -> { 1.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/integer/remainder_spec.rb b/spec/ruby/core/integer/remainder_spec.rb index 473c59a2f0..cd10dad6f2 100644 --- a/spec/ruby/core/integer/remainder_spec.rb +++ b/spec/ruby/core/integer/remainder_spec.rb @@ -38,14 +38,14 @@ describe "Integer#remainder" do end it "raises a ZeroDivisionError if other is zero and not a Float" do - lambda { bignum_value(66).remainder(0) }.should raise_error(ZeroDivisionError) + -> { bignum_value(66).remainder(0) }.should raise_error(ZeroDivisionError) end it "does raises ZeroDivisionError if other is zero and a Float" do a = bignum_value(7) b = bignum_value(32) - lambda { a.remainder(0.0) }.should raise_error(ZeroDivisionError) - lambda { b.remainder(-0.0) }.should raise_error(ZeroDivisionError) + -> { a.remainder(0.0) }.should raise_error(ZeroDivisionError) + -> { b.remainder(-0.0) }.should raise_error(ZeroDivisionError) end end end diff --git a/spec/ruby/core/integer/right_shift_spec.rb b/spec/ruby/core/integer/right_shift_spec.rb index 641d4da662..3eeaf3eb2f 100644 --- a/spec/ruby/core/integer/right_shift_spec.rb +++ b/spec/ruby/core/integer/right_shift_spec.rb @@ -79,15 +79,15 @@ describe "Integer#>> (with n >> m)" do obj = mock("a string") obj.should_receive(:to_int).and_return("asdf") - lambda { 3 >> obj }.should raise_error(TypeError) + -> { 3 >> obj }.should raise_error(TypeError) end it "raises a TypeError when passed nil" do - lambda { 3 >> nil }.should raise_error(TypeError) + -> { 3 >> nil }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { 3 >> "4" }.should raise_error(TypeError) + -> { 3 >> "4" }.should raise_error(TypeError) end end @@ -177,15 +177,15 @@ describe "Integer#>> (with n >> m)" do obj = mock("a string") obj.should_receive(:to_int).and_return("asdf") - lambda { @bignum >> obj }.should raise_error(TypeError) + -> { @bignum >> obj }.should raise_error(TypeError) end it "raises a TypeError when passed nil" do - lambda { @bignum >> nil }.should raise_error(TypeError) + -> { @bignum >> nil }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { @bignum >> "4" }.should raise_error(TypeError) + -> { @bignum >> "4" }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/round_spec.rb b/spec/ruby/core/integer/round_spec.rb index a45a7b5fb3..feb6d475d3 100644 --- a/spec/ruby/core/integer/round_spec.rb +++ b/spec/ruby/core/integer/round_spec.rb @@ -31,24 +31,24 @@ describe "Integer#round" do platform_is_not wordsize: 32 do it "raises a RangeError when passed a big negative value" do - lambda { 42.round(fixnum_min) }.should raise_error(RangeError) + -> { 42.round(fixnum_min) }.should raise_error(RangeError) end end it "raises a RangeError when passed Float::INFINITY" do - lambda { 42.round(Float::INFINITY) }.should raise_error(RangeError) + -> { 42.round(Float::INFINITY) }.should raise_error(RangeError) end it "raises a RangeError when passed a beyond signed int" do - lambda { 42.round(1<<31) }.should raise_error(RangeError) + -> { 42.round(1<<31) }.should raise_error(RangeError) end it "raises a TypeError when passed a String" do - lambda { 42.round("4") }.should raise_error(TypeError) + -> { 42.round("4") }.should raise_error(TypeError) end it "raises a TypeError when its argument cannot be converted to an Integer" do - lambda { 42.round(nil) }.should raise_error(TypeError) + -> { 42.round(nil) }.should raise_error(TypeError) end it "calls #to_int on the argument to convert it to an Integer" do @@ -60,7 +60,7 @@ describe "Integer#round" do it "raises a TypeError when #to_int does not return an Integer" do obj = mock("Object") obj.stub!(:to_int).and_return([]) - lambda { 42.round(obj) }.should raise_error(TypeError) + -> { 42.round(obj) }.should raise_error(TypeError) end it "returns different rounded values depending on the half option" do @@ -95,7 +95,7 @@ describe "Integer#round" do end it "raises ArgumentError for an unknown rounding mode" do - lambda { 42.round(-1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/) - lambda { 42.round(1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/) + -> { 42.round(-1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/) + -> { 42.round(1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/) end end diff --git a/spec/ruby/core/integer/shared/exponent.rb b/spec/ruby/core/integer/shared/exponent.rb index 810e2a7101..f292cc2448 100644 --- a/spec/ruby/core/integer/shared/exponent.rb +++ b/spec/ruby/core/integer/shared/exponent.rb @@ -99,9 +99,9 @@ describe :integer_exponent, shared: true do end it "raises a TypeError when given a non-Integer" do - lambda { @bignum.send(@method, mock('10')) }.should raise_error(TypeError) - lambda { @bignum.send(@method, "10") }.should raise_error(TypeError) - lambda { @bignum.send(@method, :symbol) }.should raise_error(TypeError) + -> { @bignum.send(@method, mock('10')) }.should raise_error(TypeError) + -> { @bignum.send(@method, "10") }.should raise_error(TypeError) + -> { @bignum.send(@method, :symbol) }.should raise_error(TypeError) end it "switch to a Float when the values is too big" do diff --git a/spec/ruby/core/integer/shared/modulo.rb b/spec/ruby/core/integer/shared/modulo.rb index d545a9af55..b06d81e17d 100644 --- a/spec/ruby/core/integer/shared/modulo.rb +++ b/spec/ruby/core/integer/shared/modulo.rb @@ -21,24 +21,24 @@ describe :integer_modulo, shared: true do end it "raises a ZeroDivisionError when the given argument is 0" do - lambda { 13.send(@method, 0) }.should raise_error(ZeroDivisionError) - lambda { 0.send(@method, 0) }.should raise_error(ZeroDivisionError) - lambda { -10.send(@method, 0) }.should raise_error(ZeroDivisionError) + -> { 13.send(@method, 0) }.should raise_error(ZeroDivisionError) + -> { 0.send(@method, 0) }.should raise_error(ZeroDivisionError) + -> { -10.send(@method, 0) }.should raise_error(ZeroDivisionError) end it "raises a ZeroDivisionError when the given argument is 0 and a Float" do - lambda { 0.send(@method, 0.0) }.should raise_error(ZeroDivisionError) - lambda { 10.send(@method, 0.0) }.should raise_error(ZeroDivisionError) - lambda { -10.send(@method, 0.0) }.should raise_error(ZeroDivisionError) + -> { 0.send(@method, 0.0) }.should raise_error(ZeroDivisionError) + -> { 10.send(@method, 0.0) }.should raise_error(ZeroDivisionError) + -> { -10.send(@method, 0.0) }.should raise_error(ZeroDivisionError) end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10) 13.send(@method, obj) }.should raise_error(TypeError) - lambda { 13.send(@method, "10") }.should raise_error(TypeError) - lambda { 13.send(@method, :symbol) }.should raise_error(TypeError) + -> { 13.send(@method, "10") }.should raise_error(TypeError) + -> { 13.send(@method, :symbol) }.should raise_error(TypeError) end end @@ -56,19 +56,19 @@ describe :integer_modulo, shared: true do end it "raises a ZeroDivisionError when the given argument is 0" do - lambda { @bignum.send(@method, 0) }.should raise_error(ZeroDivisionError) - lambda { (-@bignum).send(@method, 0) }.should raise_error(ZeroDivisionError) + -> { @bignum.send(@method, 0) }.should raise_error(ZeroDivisionError) + -> { (-@bignum).send(@method, 0) }.should raise_error(ZeroDivisionError) end it "raises a ZeroDivisionError when the given argument is 0 and a Float" do - lambda { @bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError) - lambda { -@bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError) + -> { @bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError) + -> { -@bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError) end it "raises a TypeError when given a non-Integer" do - lambda { @bignum.send(@method, mock('10')) }.should raise_error(TypeError) - lambda { @bignum.send(@method, "10") }.should raise_error(TypeError) - lambda { @bignum.send(@method, :symbol) }.should raise_error(TypeError) + -> { @bignum.send(@method, mock('10')) }.should raise_error(TypeError) + -> { @bignum.send(@method, "10") }.should raise_error(TypeError) + -> { @bignum.send(@method, :symbol) }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/sqrt_spec.rb b/spec/ruby/core/integer/sqrt_spec.rb index e40bd12b19..e56da058a0 100644 --- a/spec/ruby/core/integer/sqrt_spec.rb +++ b/spec/ruby/core/integer/sqrt_spec.rb @@ -15,7 +15,7 @@ ruby_version_is "2.5" do end it "raises a Math::DomainError if the argument is negative" do - lambda { Integer.sqrt(-4) }.should raise_error(Math::DomainError) + -> { Integer.sqrt(-4) }.should raise_error(Math::DomainError) end it "accepts any argument that can be coerced to Integer" do @@ -27,7 +27,7 @@ ruby_version_is "2.5" do end it "raises a TypeError if the argument cannot be coerced to Integer" do - lambda { Integer.sqrt("test") }.should raise_error(TypeError) + -> { Integer.sqrt("test") }.should raise_error(TypeError) end end end diff --git a/spec/ruby/core/integer/to_r_spec.rb b/spec/ruby/core/integer/to_r_spec.rb index dbb12166f1..4a40575b7f 100644 --- a/spec/ruby/core/integer/to_r_spec.rb +++ b/spec/ruby/core/integer/to_r_spec.rb @@ -20,7 +20,7 @@ describe "Integer#to_r" do end it "raises an ArgumentError if given any arguments" do - lambda { 287.to_r(2) }.should raise_error(ArgumentError) - lambda { 9102826.to_r(309, [], 71) }.should raise_error(ArgumentError) + -> { 287.to_r(2) }.should raise_error(ArgumentError) + -> { 9102826.to_r(309, [], 71) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/integer/to_s_spec.rb b/spec/ruby/core/integer/to_s_spec.rb index 687dc9d18f..7988bfde7a 100644 --- a/spec/ruby/core/integer/to_s_spec.rb +++ b/spec/ruby/core/integer/to_s_spec.rb @@ -13,10 +13,10 @@ describe "Integer#to_s" do end it "raises an ArgumentError if the base is less than 2 or higher than 36" do - lambda { 123.to_s(-1) }.should raise_error(ArgumentError) - lambda { 123.to_s(0) }.should raise_error(ArgumentError) - lambda { 123.to_s(1) }.should raise_error(ArgumentError) - lambda { 123.to_s(37) }.should raise_error(ArgumentError) + -> { 123.to_s(-1) }.should raise_error(ArgumentError) + -> { 123.to_s(0) }.should raise_error(ArgumentError) + -> { 123.to_s(1) }.should raise_error(ArgumentError) + -> { 123.to_s(37) }.should raise_error(ArgumentError) end end @@ -59,10 +59,10 @@ describe "Integer#to_s" do end it "raises an ArgumentError if the base is less than 2 or higher than 36" do - lambda { 123.to_s(-1) }.should raise_error(ArgumentError) - lambda { 123.to_s(0) }.should raise_error(ArgumentError) - lambda { 123.to_s(1) }.should raise_error(ArgumentError) - lambda { 123.to_s(37) }.should raise_error(ArgumentError) + -> { 123.to_s(-1) }.should raise_error(ArgumentError) + -> { 123.to_s(0) }.should raise_error(ArgumentError) + -> { 123.to_s(1) }.should raise_error(ArgumentError) + -> { 123.to_s(37) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/integer/upto_spec.rb b/spec/ruby/core/integer/upto_spec.rb index 7cab834ad4..6049eb173e 100644 --- a/spec/ruby/core/integer/upto_spec.rb +++ b/spec/ruby/core/integer/upto_spec.rb @@ -27,8 +27,8 @@ describe "Integer#upto [stop] when self and stop are Fixnums" do end it "raises an ArgumentError for non-numeric endpoints" do - lambda { 1.upto("A") {|x| p x} }.should raise_error(ArgumentError) - lambda { 1.upto(nil) {|x| p x} }.should raise_error(ArgumentError) + -> { 1.upto("A") {|x| p x} }.should raise_error(ArgumentError) + -> { 1.upto(nil) {|x| p x} }.should raise_error(ArgumentError) end describe "when no block is given" do @@ -45,9 +45,9 @@ describe "Integer#upto [stop] when self and stop are Fixnums" do describe "size" do it "raises an ArgumentError for non-numeric endpoints" do enum = 1.upto("A") - lambda { enum.size }.should raise_error(ArgumentError) + -> { enum.size }.should raise_error(ArgumentError) enum = 1.upto(nil) - lambda { enum.size }.should raise_error(ArgumentError) + -> { enum.size }.should raise_error(ArgumentError) end it "returns stop - self + 1" do diff --git a/spec/ruby/core/io/advise_spec.rb b/spec/ruby/core/io/advise_spec.rb index 81d5a49849..59469fa164 100644 --- a/spec/ruby/core/io/advise_spec.rb +++ b/spec/ruby/core/io/advise_spec.rb @@ -12,37 +12,37 @@ describe "IO#advise" do end it "raises a TypeError if advise is not a Symbol" do - lambda { + -> { @io.advise("normal") }.should raise_error(TypeError) end it "raises a TypeError if offset cannot be coerced to an Integer" do - lambda { + -> { @io.advise(:normal, "wat") }.should raise_error(TypeError) end it "raises a TypeError if len cannot be coerced to an Integer" do - lambda { + -> { @io.advise(:normal, 0, "wat") }.should raise_error(TypeError) end it "raises a RangeError if offset is too big" do - lambda { + -> { @io.advise(:normal, 10 ** 32) }.should raise_error(RangeError) end it "raises a RangeError if len is too big" do - lambda { + -> { @io.advise(:normal, 0, 10 ** 32) }.should raise_error(RangeError) end it "raises a NotImplementedError if advise is not recognized" do - lambda{ + ->{ @io.advise(:foo) }.should raise_error(NotImplementedError) end @@ -92,6 +92,6 @@ describe "IO#advise" do it "raises an IOError if the stream is closed" do @io.close - lambda { @io.advise(:normal) }.should raise_error(IOError) + -> { @io.advise(:normal) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/binmode_spec.rb b/spec/ruby/core/io/binmode_spec.rb index cc10e297dd..b698777cad 100644 --- a/spec/ruby/core/io/binmode_spec.rb +++ b/spec/ruby/core/io/binmode_spec.rb @@ -17,7 +17,7 @@ describe "IO#binmode" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.binmode }.should raise_error(IOError) + -> { IOSpecs.closed_io.binmode }.should raise_error(IOError) end it "sets external encoding to binary" do diff --git a/spec/ruby/core/io/binread_spec.rb b/spec/ruby/core/io/binread_spec.rb index 961044da58..a3f752d8f9 100644 --- a/spec/ruby/core/io/binread_spec.rb +++ b/spec/ruby/core/io/binread_spec.rb @@ -38,10 +38,10 @@ describe "IO.binread" do end it "raises an ArgumentError when not passed a valid length" do - lambda { IO.binread @fname, -1 }.should raise_error(ArgumentError) + -> { IO.binread @fname, -1 }.should raise_error(ArgumentError) end it "raises an Errno::EINVAL when not passed a valid offset" do - lambda { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL) + -> { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL) end end diff --git a/spec/ruby/core/io/bytes_spec.rb b/spec/ruby/core/io/bytes_spec.rb index 2d2bd950f1..feeb493566 100644 --- a/spec/ruby/core/io/bytes_spec.rb +++ b/spec/ruby/core/io/bytes_spec.rb @@ -31,13 +31,13 @@ describe "IO#bytes" do it "raises an IOError on closed stream" do enum = IOSpecs.closed_io.bytes - lambda { enum.first }.should raise_error(IOError) + -> { enum.first }.should raise_error(IOError) end it "raises an IOError on an enumerator for a stream that has been closed" do enum = @io.bytes enum.first.should == 86 @io.close - lambda { enum.first }.should raise_error(IOError) + -> { enum.first }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/close_on_exec_spec.rb b/spec/ruby/core/io/close_on_exec_spec.rb index d6ba3c3cef..f837bb56af 100644 --- a/spec/ruby/core/io/close_on_exec_spec.rb +++ b/spec/ruby/core/io/close_on_exec_spec.rb @@ -42,7 +42,7 @@ describe "IO#close_on_exec=" do it "raises IOError if called on a closed IO" do @io.close - lambda { @io.close_on_exec = true }.should raise_error(IOError) + -> { @io.close_on_exec = true }.should raise_error(IOError) end it "returns nil" do @@ -74,7 +74,7 @@ describe "IO#close_on_exec?" do it "raises IOError if called on a closed IO" do @io.close - lambda { @io.close_on_exec? }.should raise_error(IOError) + -> { @io.close_on_exec? }.should raise_error(IOError) end end end diff --git a/spec/ruby/core/io/close_read_spec.rb b/spec/ruby/core/io/close_read_spec.rb index 9783cb252a..6fa4fc8ff8 100644 --- a/spec/ruby/core/io/close_read_spec.rb +++ b/spec/ruby/core/io/close_read_spec.rb @@ -16,7 +16,7 @@ describe "IO#close_read" do it "closes the read end of a duplex I/O stream" do @io.close_read - lambda { @io.read }.should raise_error(IOError) + -> { @io.read }.should raise_error(IOError) end it "does nothing on subsequent invocations" do @@ -28,14 +28,14 @@ describe "IO#close_read" do it "allows subsequent invocation of close" do @io.close_read - lambda { @io.close }.should_not raise_error + -> { @io.close }.should_not raise_error end it "raises an IOError if the stream is writable and not duplexed" do io = File.open @path, 'w' begin - lambda { io.close_read }.should raise_error(IOError) + -> { io.close_read }.should raise_error(IOError) ensure io.close unless io.closed? end diff --git a/spec/ruby/core/io/close_spec.rb b/spec/ruby/core/io/close_spec.rb index b7aa2276d1..21bba32cd8 100644 --- a/spec/ruby/core/io/close_spec.rb +++ b/spec/ruby/core/io/close_spec.rb @@ -23,19 +23,19 @@ describe "IO#close" do it "raises an IOError reading from a closed IO" do @io.close - lambda { @io.read }.should raise_error(IOError) + -> { @io.read }.should raise_error(IOError) end it "raises an IOError writing to a closed IO" do @io.close - lambda { @io.write "data" }.should raise_error(IOError) + -> { @io.write "data" }.should raise_error(IOError) end it 'does not close the stream if autoclose is false' do other_io = IO.new(@io.fileno) other_io.autoclose = false other_io.close - lambda { @io.write "data" }.should_not raise_error(IOError) + -> { @io.write "data" }.should_not raise_error(IOError) end it "does nothing if already closed" do @@ -49,7 +49,7 @@ describe "IO#close" do read_io, write_io = IO.pipe going_to_read = false thread = Thread.new do - lambda do + -> do going_to_read = true read_io.read end.should raise_error(IOError, 'stream closed in another thread') @@ -72,7 +72,7 @@ describe "IO#close on an IO.popen stream" do io.close - lambda { io.pid }.should raise_error(IOError) + -> { io.pid }.should raise_error(IOError) end it "sets $?" do diff --git a/spec/ruby/core/io/close_write_spec.rb b/spec/ruby/core/io/close_write_spec.rb index 8643659025..75e1577654 100644 --- a/spec/ruby/core/io/close_write_spec.rb +++ b/spec/ruby/core/io/close_write_spec.rb @@ -15,7 +15,7 @@ describe "IO#close_write" do it "closes the write end of a duplex I/O stream" do @io.close_write - lambda { @io.write "attempt to write" }.should raise_error(IOError) + -> { @io.write "attempt to write" }.should raise_error(IOError) end it "does nothing on subsequent invocations" do @@ -27,14 +27,14 @@ describe "IO#close_write" do it "allows subsequent invocation of close" do @io.close_write - lambda { @io.close }.should_not raise_error + -> { @io.close }.should_not raise_error end it "raises an IOError if the stream is readable and not duplexed" do io = File.open @path, 'w+' begin - lambda { io.close_write }.should raise_error(IOError) + -> { io.close_write }.should raise_error(IOError) ensure io.close unless io.closed? end diff --git a/spec/ruby/core/io/copy_stream_spec.rb b/spec/ruby/core/io/copy_stream_spec.rb index 622be0818b..c541e96e14 100644 --- a/spec/ruby/core/io/copy_stream_spec.rb +++ b/spec/ruby/core/io/copy_stream_spec.rb @@ -31,7 +31,7 @@ describe :io_copy_stream_to_file, shared: true do obj = mock("io_copy_stream_to") obj.should_receive(:to_path).and_return(1) - lambda { IO.copy_stream(@object.from, obj) }.should raise_error(TypeError) + -> { IO.copy_stream(@object.from, obj) }.should raise_error(TypeError) end end @@ -71,7 +71,7 @@ describe :io_copy_stream_to_io, shared: true do it "raises an IOError if the destination IO is not open for writing" do @to_io.close @to_io = new_io @to_name, "r" - lambda { IO.copy_stream @object.from, @to_io }.should raise_error(IOError) + -> { IO.copy_stream @object.from, @to_io }.should raise_error(IOError) end it "does not close the destination IO" do @@ -125,7 +125,7 @@ describe "IO.copy_stream" do it "raises an IOError if the source IO is not open for reading" do @from_io.close @from_io = new_io @from_bigfile, "a" - lambda { IO.copy_stream @from_io, @to_name }.should raise_error(IOError) + -> { IO.copy_stream @from_io, @to_name }.should raise_error(IOError) end it "does not close the source IO" do @@ -183,7 +183,7 @@ describe "IO.copy_stream" do obj = mock("io_copy_stream_from") obj.should_receive(:to_path).and_return(1) - lambda { IO.copy_stream(obj, @to_name) }.should raise_error(TypeError) + -> { IO.copy_stream(obj, @to_name) }.should raise_error(TypeError) end describe "to a file name" do @@ -222,7 +222,7 @@ describe "IO.copy_stream" do platform_is_not :windows do it "raises an error when an offset is specified" do - lambda { IO.copy_stream(@from_io, @to_name, 8, 4) }.should raise_error(Errno::ESPIPE) + -> { IO.copy_stream(@from_io, @to_name, 8, 4) }.should raise_error(Errno::ESPIPE) end end diff --git a/spec/ruby/core/io/dup_spec.rb b/spec/ruby/core/io/dup_spec.rb index c88d109ec9..de32c5e347 100644 --- a/spec/ruby/core/io/dup_spec.rb +++ b/spec/ruby/core/io/dup_spec.rb @@ -49,7 +49,7 @@ end it "allows closing the new IO without affecting the original" do @i.close - lambda { @f.gets }.should_not raise_error(Exception) + -> { @f.gets }.should_not raise_error(Exception) @i.closed?.should == true @f.closed?.should == false @@ -57,14 +57,14 @@ end it "allows closing the original IO without affecting the new one" do @f.close - lambda { @i.gets }.should_not raise_error(Exception) + -> { @i.gets }.should_not raise_error(Exception) @i.closed?.should == false @f.closed?.should == true end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.dup }.should raise_error(IOError) + -> { IOSpecs.closed_io.dup }.should raise_error(IOError) end it "always sets the close-on-exec flag for the new IO object" do diff --git a/spec/ruby/core/io/each_byte_spec.rb b/spec/ruby/core/io/each_byte_spec.rb index 9cdb1ac0c9..ea618e8c0c 100644 --- a/spec/ruby/core/io/each_byte_spec.rb +++ b/spec/ruby/core/io/each_byte_spec.rb @@ -12,7 +12,7 @@ describe "IO#each_byte" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.each_byte {} }.should raise_error(IOError) + -> { IOSpecs.closed_io.each_byte {} }.should raise_error(IOError) end it "yields each byte" do diff --git a/spec/ruby/core/io/each_codepoint_spec.rb b/spec/ruby/core/io/each_codepoint_spec.rb index 19824c38e4..cddc6b4662 100644 --- a/spec/ruby/core/io/each_codepoint_spec.rb +++ b/spec/ruby/core/io/each_codepoint_spec.rb @@ -38,6 +38,6 @@ describe "IO#each_codepoint" do end it "raises an exception at incomplete character before EOF when conversion takes place" do - lambda { @io.each_codepoint {} }.should raise_error(ArgumentError) + -> { @io.each_codepoint {} }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/io/eof_spec.rb b/spec/ruby/core/io/eof_spec.rb index 3ab389af09..8fd3c37132 100644 --- a/spec/ruby/core/io/eof_spec.rb +++ b/spec/ruby/core/io/eof_spec.rb @@ -16,7 +16,7 @@ describe "IO#eof?" do end it "raises IOError on stream not opened for reading" do - lambda do + -> do File.open(@name, "w") { |f| f.eof? } end.should raise_error(IOError) end @@ -67,12 +67,12 @@ describe "IO#eof?" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.eof? }.should raise_error(IOError) + -> { IOSpecs.closed_io.eof? }.should raise_error(IOError) end it "raises IOError on stream closed for reading by close_read" do @io.close_read - lambda { @io.eof? }.should raise_error(IOError) + -> { @io.eof? }.should raise_error(IOError) end it "returns true on one-byte stream after single-byte read" do diff --git a/spec/ruby/core/io/fcntl_spec.rb b/spec/ruby/core/io/fcntl_spec.rb index 049f92c0a2..30b4876fe3 100644 --- a/spec/ruby/core/io/fcntl_spec.rb +++ b/spec/ruby/core/io/fcntl_spec.rb @@ -3,6 +3,6 @@ require_relative 'fixtures/classes' describe "IO#fcntl" do it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.fcntl(5, 5) }.should raise_error(IOError) + -> { IOSpecs.closed_io.fcntl(5, 5) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/fileno_spec.rb b/spec/ruby/core/io/fileno_spec.rb index d7aff99e72..647609bf42 100644 --- a/spec/ruby/core/io/fileno_spec.rb +++ b/spec/ruby/core/io/fileno_spec.rb @@ -7,6 +7,6 @@ describe "IO#fileno" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.fileno }.should raise_error(IOError) + -> { IOSpecs.closed_io.fileno }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/flush_spec.rb b/spec/ruby/core/io/flush_spec.rb index c81ff74a69..34cf42c425 100644 --- a/spec/ruby/core/io/flush_spec.rb +++ b/spec/ruby/core/io/flush_spec.rb @@ -3,6 +3,35 @@ require_relative 'fixtures/classes' describe "IO#flush" do it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.flush }.should raise_error(IOError) + -> { IOSpecs.closed_io.flush }.should raise_error(IOError) + end + + describe "on a pipe" do + before :each do + @r, @w = IO.pipe + end + + after :each do + @r.close + begin + @w.close + rescue Errno::EPIPE + end + end + + # [ruby-core:90895] MJIT worker may leave fd open in a forked child. + # For instance, MJIT creates a worker before @r.close with fork(), @r.close happens, + # and the MJIT worker keeps the pipe open until the worker execve(). + # TODO: consider acquiring GVL from MJIT worker. + guard_not -> { defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? } do + it "raises Errno::EPIPE if sync=false and the read end is closed" do + @w.sync = false + @w.write "foo" + @r.close + + -> { @w.flush }.should raise_error(Errno::EPIPE, /Broken pipe/) + -> { @w.close }.should raise_error(Errno::EPIPE, /Broken pipe/) + end + end end end diff --git a/spec/ruby/core/io/fsync_spec.rb b/spec/ruby/core/io/fsync_spec.rb index 0261939631..6e6123de94 100644 --- a/spec/ruby/core/io/fsync_spec.rb +++ b/spec/ruby/core/io/fsync_spec.rb @@ -12,7 +12,7 @@ describe "IO#fsync" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.fsync }.should raise_error(IOError) + -> { IOSpecs.closed_io.fsync }.should raise_error(IOError) end it "writes the buffered data to permanent storage" do diff --git a/spec/ruby/core/io/getbyte_spec.rb b/spec/ruby/core/io/getbyte_spec.rb index 6b665029d6..6ba8f0a3e0 100644 --- a/spec/ruby/core/io/getbyte_spec.rb +++ b/spec/ruby/core/io/getbyte_spec.rb @@ -23,7 +23,7 @@ describe "IO#getbyte" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.getbyte }.should raise_error(IOError) + -> { IOSpecs.closed_io.getbyte }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/getc_spec.rb b/spec/ruby/core/io/getc_spec.rb index 7c1c18cd90..3949b5cb28 100644 --- a/spec/ruby/core/io/getc_spec.rb +++ b/spec/ruby/core/io/getc_spec.rb @@ -23,7 +23,7 @@ describe "IO#getc" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.getc }.should raise_error(IOError) + -> { IOSpecs.closed_io.getc }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb index 371c1c3d3b..8f6ec0dfc7 100644 --- a/spec/ruby/core/io/gets_spec.rb +++ b/spec/ruby/core/io/gets_spec.rb @@ -30,7 +30,7 @@ describe "IO#gets" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.gets }.should raise_error(IOError) + -> { IOSpecs.closed_io.gets }.should raise_error(IOError) end describe "with no separator" do @@ -156,11 +156,11 @@ describe "IO#gets" do end it "raises an IOError if the stream is opened for append only" do - lambda { File.open(@name, "a:utf-8") { |f| f.gets } }.should raise_error(IOError) + -> { File.open(@name, "a:utf-8") { |f| f.gets } }.should raise_error(IOError) end it "raises an IOError if the stream is opened for writing only" do - lambda { File.open(@name, "w:utf-8") { |f| f.gets } }.should raise_error(IOError) + -> { File.open(@name, "w:utf-8") { |f| f.gets } }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/initialize_spec.rb b/spec/ruby/core/io/initialize_spec.rb index 4858e0360c..c8f3faf110 100644 --- a/spec/ruby/core/io/initialize_spec.rb +++ b/spec/ruby/core/io/initialize_spec.rb @@ -28,22 +28,22 @@ describe "IO#initialize" do end it "raises a TypeError when passed an IO" do - lambda { @io.send :initialize, STDOUT, 'w' }.should raise_error(TypeError) + -> { @io.send :initialize, STDOUT, 'w' }.should raise_error(TypeError) end it "raises a TypeError when passed nil" do - lambda { @io.send :initialize, nil, 'w' }.should raise_error(TypeError) + -> { @io.send :initialize, nil, 'w' }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { @io.send :initialize, "4", 'w' }.should raise_error(TypeError) + -> { @io.send :initialize, "4", 'w' }.should raise_error(TypeError) end it "raises IOError on closed stream" do - lambda { @io.send :initialize, IOSpecs.closed_io.fileno }.should raise_error(IOError) + -> { @io.send :initialize, IOSpecs.closed_io.fileno }.should raise_error(IOError) end it "raises an Errno::EBADF when given an invalid file descriptor" do - lambda { @io.send :initialize, -1, 'w' }.should raise_error(Errno::EBADF) + -> { @io.send :initialize, -1, 'w' }.should raise_error(Errno::EBADF) end end diff --git a/spec/ruby/core/io/ioctl_spec.rb b/spec/ruby/core/io/ioctl_spec.rb index 0f2b67ac44..e819a217a8 100644 --- a/spec/ruby/core/io/ioctl_spec.rb +++ b/spec/ruby/core/io/ioctl_spec.rb @@ -4,7 +4,7 @@ require_relative 'fixtures/classes' describe "IO#ioctl" do platform_is_not :windows do it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.ioctl(5, 5) }.should raise_error(IOError) + -> { IOSpecs.closed_io.ioctl(5, 5) }.should raise_error(IOError) end end @@ -22,7 +22,7 @@ describe "IO#ioctl" do it "raises an Errno error when ioctl fails" do File.open(__FILE__, 'r') do |f| - lambda { + -> { # TIOCGWINSZ in /usr/include/asm-generic/ioctls.h f.ioctl 0x5413, nil }.should raise_error(Errno::ENOTTY) diff --git a/spec/ruby/core/io/lineno_spec.rb b/spec/ruby/core/io/lineno_spec.rb index 322e60d643..3d1b2275cc 100644 --- a/spec/ruby/core/io/lineno_spec.rb +++ b/spec/ruby/core/io/lineno_spec.rb @@ -11,7 +11,7 @@ describe "IO#lineno" do end it "raises an IOError on a closed stream" do - lambda { IOSpecs.closed_io.lineno }.should raise_error(IOError) + -> { IOSpecs.closed_io.lineno }.should raise_error(IOError) end it "returns the current line number" do @@ -37,7 +37,7 @@ describe "IO#lineno=" do end it "raises an IOError on a closed stream" do - lambda { IOSpecs.closed_io.lineno = 5 }.should raise_error(IOError) + -> { IOSpecs.closed_io.lineno = 5 }.should raise_error(IOError) end it "calls #to_int on a non-numeric argument" do @@ -57,7 +57,7 @@ describe "IO#lineno=" do end it "raises TypeError on nil argument" do - lambda { @io.lineno = nil }.should raise_error(TypeError) + -> { @io.lineno = nil }.should raise_error(TypeError) end it "sets the current line number to the given value" do diff --git a/spec/ruby/core/io/open_spec.rb b/spec/ruby/core/io/open_spec.rb index f26753cde7..94df5a5ef6 100644 --- a/spec/ruby/core/io/open_spec.rb +++ b/spec/ruby/core/io/open_spec.rb @@ -38,7 +38,7 @@ describe "IO.open" do end it "propagates an exception raised by #close that is not a StandardError" do - lambda do + -> do IO.open(@fd, "w") do |io| IOSpecs.io_mock(io, :close) do super() @@ -51,7 +51,7 @@ describe "IO.open" do end it "propagates an exception raised by #close that is a StandardError" do - lambda do + -> do IO.open(@fd, "w") do |io| IOSpecs.io_mock(io, :close) do super() diff --git a/spec/ruby/core/io/output_spec.rb b/spec/ruby/core/io/output_spec.rb index d3ec71c563..2aafb305f4 100644 --- a/spec/ruby/core/io/output_spec.rb +++ b/spec/ruby/core/io/output_spec.rb @@ -3,24 +3,24 @@ require_relative 'fixtures/classes' describe "IO#<<" do it "writes an object to the IO stream" do - lambda { + -> { $stderr << "Oh noes, an error!" }.should output_to_fd("Oh noes, an error!", $stderr) end it "calls #to_s on the object to print it" do - lambda { + -> { $stderr << 1337 }.should output_to_fd("1337", $stderr) end it "raises an error if the stream is closed" do io = IOSpecs.closed_io - lambda { io << "test" }.should raise_error(IOError) + -> { io << "test" }.should raise_error(IOError) end it "returns self" do - lambda { + -> { ($stderr << "to_stderr").should == $stderr }.should output(nil, "to_stderr") end diff --git a/spec/ruby/core/io/pid_spec.rb b/spec/ruby/core/io/pid_spec.rb index 97b8a8529d..bc09fe7c3b 100644 --- a/spec/ruby/core/io/pid_spec.rb +++ b/spec/ruby/core/io/pid_spec.rb @@ -30,6 +30,6 @@ describe "IO#pid" do it "raises an IOError on closed stream" do @io.close - lambda { @io.pid }.should raise_error(IOError) + -> { @io.pid }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/pipe_spec.rb b/spec/ruby/core/io/pipe_spec.rb index 005f60fab6..5b2f18d836 100644 --- a/spec/ruby/core/io/pipe_spec.rb +++ b/spec/ruby/core/io/pipe_spec.rb @@ -50,7 +50,7 @@ describe "IO.pipe" do it "closes both IO objects when the block raises" do r = w = nil - lambda do + -> do IO.pipe do |_r, _w| r = _r w = _w diff --git a/spec/ruby/core/io/popen_spec.rb b/spec/ruby/core/io/popen_spec.rb index 289bb076e4..622b3a9394 100644 --- a/spec/ruby/core/io/popen_spec.rb +++ b/spec/ruby/core/io/popen_spec.rb @@ -22,7 +22,7 @@ describe "IO.popen" do it "raises IOError when writing a read-only pipe" do @io = IO.popen(ruby_cmd('puts "foo"'), "r") - lambda { @io.write('bar') }.should raise_error(IOError) + -> { @io.write('bar') }.should raise_error(IOError) @io.read.should == "foo\n" end end @@ -55,7 +55,7 @@ describe "IO.popen" do it "raises IOError when reading a write-only pipe" do @io = IO.popen(ruby_cmd('IO.copy_stream(STDIN,STDOUT)'), "w") - lambda { @io.read }.should raise_error(IOError) + -> { @io.read }.should raise_error(IOError) end it "reads and writes a read/write pipe" do diff --git a/spec/ruby/core/io/pread_spec.rb b/spec/ruby/core/io/pread_spec.rb index b5b516fa53..bfe6472fef 100644 --- a/spec/ruby/core/io/pread_spec.rb +++ b/spec/ruby/core/io/pread_spec.rb @@ -33,19 +33,19 @@ ruby_version_is "2.5" do end it "raises EOFError if end-of-file is reached" do - lambda { @file.pread(1, 10) }.should raise_error(EOFError) + -> { @file.pread(1, 10) }.should raise_error(EOFError) end it "raises IOError when file is not open in read mode" do File.open(@fname, "w") do |file| - lambda { file.pread(1, 1) }.should raise_error(IOError) + -> { file.pread(1, 1) }.should raise_error(IOError) end end it "raises IOError when file is closed" do file = File.open(@fname, "r+") file.close - lambda { file.pread(1, 1) }.should raise_error(IOError) + -> { file.pread(1, 1) }.should raise_error(IOError) end end end diff --git a/spec/ruby/core/io/print_spec.rb b/spec/ruby/core/io/print_spec.rb index 0dd48344ce..2021cd5420 100644 --- a/spec/ruby/core/io/print_spec.rb +++ b/spec/ruby/core/io/print_spec.rb @@ -48,6 +48,6 @@ describe IO, "#print" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.print("stuff") }.should raise_error(IOError) + -> { IOSpecs.closed_io.print("stuff") }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/printf_spec.rb b/spec/ruby/core/io/printf_spec.rb index be4e5c339e..baa00f14ce 100644 --- a/spec/ruby/core/io/printf_spec.rb +++ b/spec/ruby/core/io/printf_spec.rb @@ -27,6 +27,6 @@ describe "IO#printf" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.printf("stuff") }.should raise_error(IOError) + -> { IOSpecs.closed_io.printf("stuff") }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/puts_spec.rb b/spec/ruby/core/io/puts_spec.rb index e8d599730f..3e4b877b7f 100644 --- a/spec/ruby/core/io/puts_spec.rb +++ b/spec/ruby/core/io/puts_spec.rb @@ -25,7 +25,7 @@ describe "IO#puts" do end it "writes just a newline when given just a newline" do - lambda { $stdout.puts "\n" }.should output_to_fd("\n", STDOUT) + -> { $stdout.puts "\n" }.should output_to_fd("\n", STDOUT) end it "writes empty string with a newline when given nil as an arg" do @@ -111,7 +111,7 @@ describe "IO#puts" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.puts("stuff") }.should raise_error(IOError) + -> { IOSpecs.closed_io.puts("stuff") }.should raise_error(IOError) end it "writes crlf when IO is opened with newline: :crlf" do diff --git a/spec/ruby/core/io/pwrite_spec.rb b/spec/ruby/core/io/pwrite_spec.rb index fd3d1b98e9..929ed08698 100644 --- a/spec/ruby/core/io/pwrite_spec.rb +++ b/spec/ruby/core/io/pwrite_spec.rb @@ -31,14 +31,14 @@ ruby_version_is "2.5" do it "raises IOError when file is not open in write mode" do File.open(@fname, "r") do |file| - lambda { file.pwrite("foo", 1) }.should raise_error(IOError) + -> { file.pwrite("foo", 1) }.should raise_error(IOError) end end it "raises IOError when file is closed" do file = File.open(@fname, "w+") file.close - lambda { file.pwrite("foo", 1) }.should raise_error(IOError) + -> { file.pwrite("foo", 1) }.should raise_error(IOError) end end end diff --git a/spec/ruby/core/io/read_nonblock_spec.rb b/spec/ruby/core/io/read_nonblock_spec.rb index 59f5064922..63ccab5a44 100644 --- a/spec/ruby/core/io/read_nonblock_spec.rb +++ b/spec/ruby/core/io/read_nonblock_spec.rb @@ -12,7 +12,7 @@ describe "IO#read_nonblock" do end it "raises an exception extending IO::WaitReadable when there is no data" do - lambda { @read.read_nonblock(5) }.should raise_error(IO::WaitReadable) { |e| + -> { @read.read_nonblock(5) }.should raise_error(IO::WaitReadable) { |e| platform_is_not :windows do e.should be_kind_of(Errno::EAGAIN) end @@ -85,7 +85,7 @@ describe "IO#read_nonblock" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.read_nonblock(5) }.should raise_error(IOError) + -> { IOSpecs.closed_io.read_nonblock(5) }.should raise_error(IOError) end it "raises EOFError when the end is reached" do @@ -94,6 +94,6 @@ describe "IO#read_nonblock" do @read.read_nonblock(5) - lambda { @read.read_nonblock(5) }.should raise_error(EOFError) + -> { @read.read_nonblock(5) }.should raise_error(EOFError) end end diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb index e005e14fdf..267d840cd3 100644 --- a/spec/ruby/core/io/read_spec.rb +++ b/spec/ruby/core/io/read_spec.rb @@ -36,11 +36,11 @@ describe "IO.read" do end it "raises an IOError if the options Hash specifies write mode" do - lambda { IO.read(@fname, 3, 0, {mode: "w"}) }.should raise_error(IOError) + -> { IO.read(@fname, 3, 0, {mode: "w"}) }.should raise_error(IOError) end it "raises an IOError if the options Hash specifies append only mode" do - lambda { IO.read(@fname, {mode: "a"}) }.should raise_error(IOError) + -> { IO.read(@fname, {mode: "a"}) }.should raise_error(IOError) end it "reads the file if the options Hash includes read mode" do @@ -79,20 +79,20 @@ describe "IO.read" do it "raises an Errno::ENOENT when the requested file does not exist" do rm_r @fname - lambda { IO.read @fname }.should raise_error(Errno::ENOENT) + -> { IO.read @fname }.should raise_error(Errno::ENOENT) end it "raises a TypeError when not passed a String type" do - lambda { IO.read nil }.should raise_error(TypeError) + -> { IO.read nil }.should raise_error(TypeError) end it "raises an ArgumentError when not passed a valid length" do - lambda { IO.read @fname, -1 }.should raise_error(ArgumentError) + -> { IO.read @fname, -1 }.should raise_error(ArgumentError) end it "raises an Errno::EINVAL when not passed a valid offset" do - lambda { IO.read @fname, 0, -1 }.should raise_error(Errno::EINVAL) - lambda { IO.read @fname, -1, -1 }.should raise_error(Errno::EINVAL) + -> { IO.read @fname, 0, -1 }.should raise_error(Errno::EINVAL) + -> { IO.read @fname, -1, -1 }.should raise_error(Errno::EINVAL) end it "uses the external encoding specified via the :external_encoding option" do @@ -137,7 +137,7 @@ describe "IO.read from a pipe" do platform_is_not :windows do it "raises Errno::ESPIPE if passed an offset" do - lambda { + -> { IO.read("|sh -c 'echo hello'", 1, 1) }.should raise_error(Errno::ESPIPE) end @@ -148,7 +148,7 @@ quarantine! do # The process tried to write to a nonexistent pipe. # TODO: It should raise Errno::ESPIPE on Windows as well # once https://bugs.ruby-lang.org/issues/12230 is fixed. it "raises Errno::EINVAL if passed an offset" do - lambda { + -> { IO.read("|cmd.exe /C echo hello", 1, 1) }.should raise_error(Errno::EINVAL) end @@ -301,7 +301,7 @@ describe "IO#read" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.read }.should raise_error(IOError) + -> { IOSpecs.closed_io.read }.should raise_error(IOError) end diff --git a/spec/ruby/core/io/readbyte_spec.rb b/spec/ruby/core/io/readbyte_spec.rb index eb25975f58..14426c28ac 100644 --- a/spec/ruby/core/io/readbyte_spec.rb +++ b/spec/ruby/core/io/readbyte_spec.rb @@ -17,7 +17,7 @@ describe "IO#readbyte" do it "raises EOFError on EOF" do @io.seek(999999) - lambda do + -> do @io.readbyte end.should raise_error EOFError end diff --git a/spec/ruby/core/io/readchar_spec.rb b/spec/ruby/core/io/readchar_spec.rb index 74f78b5a6e..b5f762a846 100644 --- a/spec/ruby/core/io/readchar_spec.rb +++ b/spec/ruby/core/io/readchar_spec.rb @@ -21,11 +21,11 @@ describe "IO#readchar" do it "raises an EOFError when invoked at the end of the stream" do @io.read - lambda { @io.readchar }.should raise_error(EOFError) + -> { @io.readchar }.should raise_error(EOFError) end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.readchar }.should raise_error(IOError) + -> { IOSpecs.closed_io.readchar }.should raise_error(IOError) end end @@ -39,6 +39,6 @@ describe "IO#readchar" do end it "raises EOFError on empty stream" do - lambda { @io.readchar }.should raise_error(EOFError) + -> { @io.readchar }.should raise_error(EOFError) end end diff --git a/spec/ruby/core/io/readline_spec.rb b/spec/ruby/core/io/readline_spec.rb index 3eae6bfa47..7cb1601816 100644 --- a/spec/ruby/core/io/readline_spec.rb +++ b/spec/ruby/core/io/readline_spec.rb @@ -29,11 +29,11 @@ describe "IO#readline" do it "raises EOFError on end of stream" do IOSpecs.lines.length.times { @io.readline } - lambda { @io.readline }.should raise_error(EOFError) + -> { @io.readline }.should raise_error(EOFError) end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.readline }.should raise_error(IOError) + -> { IOSpecs.closed_io.readline }.should raise_error(IOError) end it "assigns the returned line to $_" do diff --git a/spec/ruby/core/io/readlines_spec.rb b/spec/ruby/core/io/readlines_spec.rb index 5a7e9b5aa8..0d4f002972 100644 --- a/spec/ruby/core/io/readlines_spec.rb +++ b/spec/ruby/core/io/readlines_spec.rb @@ -17,7 +17,7 @@ describe "IO#readlines" do it "raises an IOError if the stream is closed" do @io.close - lambda { @io.readlines }.should raise_error(IOError) + -> { @io.readlines }.should raise_error(IOError) end describe "when passed no arguments" do @@ -138,13 +138,13 @@ describe "IO#readlines" do end it "raises an IOError if the stream is opened for append only" do - lambda do + -> do File.open(@name, "a:utf-8") { |f| f.readlines } end.should raise_error(IOError) end it "raises an IOError if the stream is opened for write only" do - lambda do + -> do File.open(@name, "w:utf-8") { |f| f.readlines } end.should raise_error(IOError) end diff --git a/spec/ruby/core/io/readpartial_spec.rb b/spec/ruby/core/io/readpartial_spec.rb index 1ab01dcf49..2b33a0d5b1 100644 --- a/spec/ruby/core/io/readpartial_spec.rb +++ b/spec/ruby/core/io/readpartial_spec.rb @@ -15,10 +15,10 @@ describe "IO#readpartial" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.readpartial(10) }.should raise_error(IOError) + -> { IOSpecs.closed_io.readpartial(10) }.should raise_error(IOError) @rd.close - lambda { @rd.readpartial(10) }.should raise_error(IOError) + -> { @rd.readpartial(10) }.should raise_error(IOError) end it "reads at most the specified number of bytes" do @@ -70,23 +70,23 @@ describe "IO#readpartial" do @wr.write("abc") @wr.close @rd.readpartial(10).should == 'abc' - lambda { @rd.readpartial(10) }.should raise_error(EOFError) + -> { @rd.readpartial(10) }.should raise_error(EOFError) end it "discards the existing buffer content upon error" do buffer = 'hello' @wr.close - lambda { @rd.readpartial(1, buffer) }.should raise_error(EOFError) + -> { @rd.readpartial(1, buffer) }.should raise_error(EOFError) buffer.should be_empty end it "raises IOError if the stream is closed" do @wr.close - lambda { @rd.readpartial(1) }.should raise_error(IOError) + -> { @rd.readpartial(1) }.should raise_error(IOError) end it "raises ArgumentError if the negative argument is provided" do - lambda { @rd.readpartial(-1) }.should raise_error(ArgumentError) + -> { @rd.readpartial(-1) }.should raise_error(ArgumentError) end it "immediately returns an empty string if the length argument is 0" do diff --git a/spec/ruby/core/io/reopen_spec.rb b/spec/ruby/core/io/reopen_spec.rb index 84c23472b7..133ff03ea5 100644 --- a/spec/ruby/core/io/reopen_spec.rb +++ b/spec/ruby/core/io/reopen_spec.rb @@ -33,29 +33,29 @@ describe "IO#reopen" do it "raises an IOError if the object returned by #to_io is closed" do obj = mock("io") obj.should_receive(:to_io).and_return(IOSpecs.closed_io) - lambda { @io.reopen obj }.should raise_error(IOError) + -> { @io.reopen obj }.should raise_error(IOError) end it "raises a TypeError if #to_io does not return an IO instance" do obj = mock("io") obj.should_receive(:to_io).and_return("something else") - lambda { @io.reopen obj }.should raise_error(TypeError) + -> { @io.reopen obj }.should raise_error(TypeError) end it "raises an IOError when called on a closed stream with an object" do @io.close obj = mock("io") obj.should_not_receive(:to_io) - lambda { @io.reopen(STDOUT) }.should raise_error(IOError) + -> { @io.reopen(STDOUT) }.should raise_error(IOError) end it "raises an IOError if the IO argument is closed" do - lambda { @io.reopen(IOSpecs.closed_io) }.should raise_error(IOError) + -> { @io.reopen(IOSpecs.closed_io) }.should raise_error(IOError) end it "raises an IOError when called on a closed stream with an IO" do @io.close - lambda { @io.reopen(STDOUT) }.should raise_error(IOError) + -> { @io.reopen(STDOUT) }.should raise_error(IOError) end end @@ -188,7 +188,7 @@ describe "IO#reopen with a String" do it "raises an Errno::ENOENT if the file does not exist and the IO is not opened in write mode" do @io = new_io @name, "r" - lambda { @io.reopen(@other_name) }.should raise_error(Errno::ENOENT) + -> { @io.reopen(@other_name) }.should raise_error(Errno::ENOENT) end end diff --git a/spec/ruby/core/io/rewind_spec.rb b/spec/ruby/core/io/rewind_spec.rb index d1ec7a69c7..954d56d30c 100644 --- a/spec/ruby/core/io/rewind_spec.rb +++ b/spec/ruby/core/io/rewind_spec.rb @@ -33,6 +33,6 @@ describe "IO#rewind" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.rewind }.should raise_error(IOError) + -> { IOSpecs.closed_io.rewind }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/seek_spec.rb b/spec/ruby/core/io/seek_spec.rb index 9978d7c0e7..7e9c308272 100644 --- a/spec/ruby/core/io/seek_spec.rb +++ b/spec/ruby/core/io/seek_spec.rb @@ -17,7 +17,7 @@ describe "IO#seek" do end it "moves the read position relative to the current position with SEEK_CUR" do - lambda { @io.seek(-1) }.should raise_error(Errno::EINVAL) + -> { @io.seek(-1) }.should raise_error(Errno::EINVAL) @io.seek(10, IO::SEEK_CUR) @io.readline.should == "igne une.\n" @io.seek(-5, IO::SEEK_CUR) diff --git a/spec/ruby/core/io/select_spec.rb b/spec/ruby/core/io/select_spec.rb index e69669efd2..4603c1fbbc 100644 --- a/spec/ruby/core/io/select_spec.rb +++ b/spec/ruby/core/io/select_spec.rb @@ -80,28 +80,28 @@ describe "IO.select" do end it "raises TypeError if supplied objects are not IO" do - lambda { IO.select([Object.new]) }.should raise_error(TypeError) - lambda { IO.select(nil, [Object.new]) }.should raise_error(TypeError) + -> { IO.select([Object.new]) }.should raise_error(TypeError) + -> { IO.select(nil, [Object.new]) }.should raise_error(TypeError) obj = mock("io") obj.should_receive(:to_io).any_number_of_times.and_return(nil) - lambda { IO.select([obj]) }.should raise_error(TypeError) - lambda { IO.select(nil, [obj]) }.should raise_error(TypeError) + -> { IO.select([obj]) }.should raise_error(TypeError) + -> { IO.select(nil, [obj]) }.should raise_error(TypeError) end it "raises a TypeError if the specified timeout value is not Numeric" do - lambda { IO.select([@rd], nil, nil, Object.new) }.should raise_error(TypeError) + -> { IO.select([@rd], nil, nil, Object.new) }.should raise_error(TypeError) end it "raises TypeError if the first three arguments are not Arrays" do - lambda { IO.select(Object.new)}.should raise_error(TypeError) - lambda { IO.select(nil, Object.new)}.should raise_error(TypeError) - lambda { IO.select(nil, nil, Object.new)}.should raise_error(TypeError) + -> { IO.select(Object.new)}.should raise_error(TypeError) + -> { IO.select(nil, Object.new)}.should raise_error(TypeError) + -> { IO.select(nil, nil, Object.new)}.should raise_error(TypeError) end it "raises an ArgumentError when passed a negative timeout" do - lambda { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError) + -> { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/io/shared/binwrite.rb b/spec/ruby/core/io/shared/binwrite.rb index 1a88442a3b..17682a1a93 100644 --- a/spec/ruby/core/io/shared/binwrite.rb +++ b/spec/ruby/core/io/shared/binwrite.rb @@ -68,7 +68,7 @@ describe :io_binwrite, shared: true do end it "raises an error if readonly mode is specified" do - lambda { IO.send(@method, @filename, "abcde", mode: "r") }.should raise_error(IOError) + -> { IO.send(@method, @filename, "abcde", mode: "r") }.should raise_error(IOError) end it "truncates if empty :opts provided and offset skipped" do diff --git a/spec/ruby/core/io/shared/chars.rb b/spec/ruby/core/io/shared/chars.rb index 7f2edd2b6d..266566f221 100644 --- a/spec/ruby/core/io/shared/chars.rb +++ b/spec/ruby/core/io/shared/chars.rb @@ -46,11 +46,11 @@ describe :io_chars, shared: true do end it "raises an IOError when an enumerator created on a closed stream is accessed" do - lambda { IOSpecs.closed_io.send(@method).first }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method).first }.should raise_error(IOError) end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/shared/codepoints.rb b/spec/ruby/core/io/shared/codepoints.rb index a5062e7f79..6872846c1a 100644 --- a/spec/ruby/core/io/shared/codepoints.rb +++ b/spec/ruby/core/io/shared/codepoints.rb @@ -39,7 +39,7 @@ describe :io_codepoints, shared: true do it "raises an error if reading invalid sequence" do @io.pos = 60 # inside of a multibyte sequence - lambda { @enum.first }.should raise_error(ArgumentError) + -> { @enum.first }.should raise_error(ArgumentError) end it "does not change $_" do @@ -49,6 +49,6 @@ describe :io_codepoints, shared: true do end it "raises an IOError when self is not readable" do - lambda { IOSpecs.closed_io.send(@method).to_a }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method).to_a }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/shared/each.rb b/spec/ruby/core/io/shared/each.rb index da562e03b1..0b2dfa3548 100644 --- a/spec/ruby/core/io/shared/each.rb +++ b/spec/ruby/core/io/shared/each.rb @@ -38,7 +38,7 @@ describe :io_each, shared: true do end it "raises an IOError when self is not readable" do - lambda { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError) end it "makes line count accessible via lineno" do @@ -74,7 +74,7 @@ describe :io_each, shared: true do describe "when limit is 0" do it "raises an ArgumentError" do # must pass block so Enumerator is evaluated and raises - lambda { @io.send(@method, 0){} }.should raise_error(ArgumentError) + -> { @io.send(@method, 0){} }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb index f6069a4cdc..2101958170 100644 --- a/spec/ruby/core/io/shared/new.rb +++ b/spec/ruby/core/io/shared/new.rb @@ -115,14 +115,14 @@ describe :io_new, shared: true do end it "ignores the :encoding option when the :external_encoding option is present" do - lambda { + -> { @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', encoding: 'iso-8859-1:iso-8859-1'}) }.should complain(/Ignoring encoding parameter/) @io.external_encoding.to_s.should == 'UTF-8' end it "ignores the :encoding option when the :internal_encoding option is present" do - lambda { + -> { @io = IO.send(@method, @fd, 'w', {internal_encoding: 'ibm866', encoding: 'iso-8859-1:iso-8859-1'}) }.should complain(/Ignoring encoding parameter/) @io.internal_encoding.to_s.should == 'IBM866' @@ -282,96 +282,96 @@ describe :io_new_errors, shared: true do end it "raises an Errno::EBADF if the file descriptor is not valid" do - lambda { IO.send(@method, -1, "w") }.should raise_error(Errno::EBADF) + -> { IO.send(@method, -1, "w") }.should raise_error(Errno::EBADF) end it "raises an IOError if passed a closed stream" do - lambda { IO.send(@method, IOSpecs.closed_io.fileno, 'w') }.should raise_error(IOError) + -> { IO.send(@method, IOSpecs.closed_io.fileno, 'w') }.should raise_error(IOError) end platform_is_not :windows do it "raises an Errno::EINVAL if the new mode is not compatible with the descriptor's current mode" do - lambda { IO.send(@method, @fd, "r") }.should raise_error(Errno::EINVAL) + -> { IO.send(@method, @fd, "r") }.should raise_error(Errno::EINVAL) end end it "raises ArgumentError if passed an empty mode string" do - lambda { IO.send(@method, @fd, "") }.should raise_error(ArgumentError) + -> { IO.send(@method, @fd, "") }.should raise_error(ArgumentError) end it "raises an error if passed modes two ways" do - lambda { + -> { IO.send(@method, @fd, "w", mode: "w") }.should raise_error(ArgumentError) end it "raises an error if passed encodings two ways" do - lambda { + -> { @io = IO.send(@method, @fd, 'w:ISO-8859-1', {encoding: 'ISO-8859-1'}) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, 'w:ISO-8859-1', {external_encoding: 'ISO-8859-1'}) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, 'w:ISO-8859-1:UTF-8', {internal_encoding: 'ISO-8859-1'}) }.should raise_error(ArgumentError) end it "raises an error if passed matching binary/text mode two ways" do - lambda { + -> { @io = IO.send(@method, @fd, "wb", binmode: true) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wt", textmode: true) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wb", textmode: false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wt", binmode: false) }.should raise_error(ArgumentError) end it "raises an error if passed conflicting binary/text mode two ways" do - lambda { + -> { @io = IO.send(@method, @fd, "wb", binmode: false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wt", textmode: false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wb", textmode: true) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, "wt", binmode: true) }.should raise_error(ArgumentError) end it "raises an error when trying to set both binmode and textmode" do - lambda { + -> { @io = IO.send(@method, @fd, "w", textmode: true, binmode: true) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, File::Constants::WRONLY, textmode: true, binmode: true) }.should raise_error(ArgumentError) end it "raises ArgumentError if not passed a hash or nil for options" do - lambda { + -> { @io = IO.send(@method, @fd, 'w', false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, false, false) }.should raise_error(ArgumentError) - lambda { + -> { @io = IO.send(@method, @fd, nil, false) }.should raise_error(ArgumentError) end it "raises TypeError if passed a hash for mode and nil for options" do - lambda { + -> { @io = IO.send(@method, @fd, {mode: 'w'}, nil) }.should raise_error(TypeError) end diff --git a/spec/ruby/core/io/shared/pos.rb b/spec/ruby/core/io/shared/pos.rb index fef7ab2bf7..fb6d8087bc 100644 --- a/spec/ruby/core/io/shared/pos.rb +++ b/spec/ruby/core/io/shared/pos.rb @@ -19,7 +19,7 @@ describe :io_pos, shared: true do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send(@method) }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method) }.should raise_error(IOError) end it "resets #eof?" do @@ -62,11 +62,11 @@ describe :io_set_pos, shared: true do it "does not accept Bignums that don't fit in a C long" do File.open @fname do |io| - lambda { io.send @method, 2**128 }.should raise_error(RangeError) + -> { io.send @method, 2**128 }.should raise_error(RangeError) end end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send @method, 0 }.should raise_error(IOError) + -> { IOSpecs.closed_io.send @method, 0 }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/shared/readlines.rb b/spec/ruby/core/io/shared/readlines.rb index 08d41e0a4c..9bc02da0bd 100644 --- a/spec/ruby/core/io/shared/readlines.rb +++ b/spec/ruby/core/io/shared/readlines.rb @@ -1,11 +1,11 @@ describe :io_readlines, shared: true do it "raises TypeError if the first parameter is nil" do - lambda { IO.send(@method, nil, &@object) }.should raise_error(TypeError) + -> { IO.send(@method, nil, &@object) }.should raise_error(TypeError) end it "raises an Errno::ENOENT if the file does not exist" do name = tmp("nonexistent.txt") - lambda { IO.send(@method, name, &@object) }.should raise_error(Errno::ENOENT) + -> { IO.send(@method, name, &@object) }.should raise_error(Errno::ENOENT) end it "yields a single string with entire content when the separator is nil" do @@ -98,7 +98,7 @@ describe :io_readlines_options_19, shared: true do describe "when passed name, object, object" do describe "when the first object is a Fixnum" do it "uses the second object as an options Hash" do - lambda do + -> do IO.send(@method, @filename, 10, mode: "w", &@object) end.should raise_error(IOError) end @@ -106,7 +106,7 @@ describe :io_readlines_options_19, shared: true do it "calls #to_hash to convert the second object to a Hash" do options = mock("io readlines options Hash") options.should_receive(:to_hash).and_return({ mode: "w" }) - lambda do + -> do IO.send(@method, @filename, 10, options, &@object) end.should raise_error(IOError) end @@ -126,7 +126,7 @@ describe :io_readlines_options_19, shared: true do end it "uses the second object as an options Hash" do - lambda do + -> do IO.send(@method, @filename, " ", mode: "w", &@object) end.should raise_error(IOError) end @@ -134,7 +134,7 @@ describe :io_readlines_options_19, shared: true do it "calls #to_hash to convert the second object to a Hash" do options = mock("io readlines options Hash") options.should_receive(:to_hash).and_return({ mode: "w" }) - lambda do + -> do IO.send(@method, @filename, " ", options, &@object) end.should raise_error(IOError) end @@ -161,7 +161,7 @@ describe :io_readlines_options_19, shared: true do end it "uses the second object as an options Hash" do - lambda do + -> do IO.send(@method, @filename, " ", mode: "w", &@object) end.should raise_error(IOError) end @@ -169,7 +169,7 @@ describe :io_readlines_options_19, shared: true do it "calls #to_hash to convert the second object to a Hash" do options = mock("io readlines options Hash") options.should_receive(:to_hash).and_return({ mode: "w" }) - lambda do + -> do IO.send(@method, @filename, " ", options, &@object) end.should raise_error(IOError) end @@ -201,7 +201,7 @@ describe :io_readlines_options_19, shared: true do it "calls #to_hash to convert the options object" do options = mock("io readlines options Hash") options.should_receive(:to_hash).and_return({ mode: "w" }) - lambda do + -> do IO.send(@method, @filename, " ", 10, options, &@object) end.should raise_error(IOError) end diff --git a/spec/ruby/core/io/shared/tty.rb b/spec/ruby/core/io/shared/tty.rb index 947b887f81..82a780a9f3 100644 --- a/spec/ruby/core/io/shared/tty.rb +++ b/spec/ruby/core/io/shared/tty.rb @@ -20,6 +20,6 @@ describe :io_tty, shared: true do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send @method }.should raise_error(IOError) + -> { IOSpecs.closed_io.send @method }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/shared/write.rb b/spec/ruby/core/io/shared/write.rb index aa6b3eedeb..542d20d2a4 100644 --- a/spec/ruby/core/io/shared/write.rb +++ b/spec/ruby/core/io/shared/write.rb @@ -23,7 +23,7 @@ describe :io_write, shared: true do end it "checks if the file is writable if writing more than zero bytes" do - lambda { @readonly_file.send(@method, "abcde") }.should raise_error(IOError) + -> { @readonly_file.send(@method, "abcde") }.should raise_error(IOError) end it "returns the number of bytes written" do @@ -50,7 +50,7 @@ describe :io_write, shared: true do it "does not warn if called after IO#read" do @file.read(5) - lambda { @file.send(@method, "fghij") }.should_not complain + -> { @file.send(@method, "fghij") }.should_not complain end it "writes to the current position after IO#read" do @@ -66,7 +66,17 @@ describe :io_write, shared: true do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.send(@method, "hello") }.should raise_error(IOError) + -> { IOSpecs.closed_io.send(@method, "hello") }.should raise_error(IOError) + end + + it "does not modify the passed argument" do + File.open(@filename, "w") do |f| + f.set_encoding(Encoding::IBM437) + # A character whose codepoint differs between UTF-8 and IBM437 + f.write "ƒ\n".freeze + end + + File.binread(@filename).bytes.should == [159, 10] end describe "on a pipe" do diff --git a/spec/ruby/core/io/stat_spec.rb b/spec/ruby/core/io/stat_spec.rb index d46d4105ca..58eba02b8f 100644 --- a/spec/ruby/core/io/stat_spec.rb +++ b/spec/ruby/core/io/stat_spec.rb @@ -11,7 +11,7 @@ describe "IO#stat" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.stat }.should raise_error(IOError) + -> { IOSpecs.closed_io.stat }.should raise_error(IOError) end it "returns a File::Stat object for the stream" do diff --git a/spec/ruby/core/io/sync_spec.rb b/spec/ruby/core/io/sync_spec.rb index c8c1c5a57e..993b7ee244 100644 --- a/spec/ruby/core/io/sync_spec.rb +++ b/spec/ruby/core/io/sync_spec.rb @@ -27,7 +27,7 @@ describe "IO#sync=" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.sync = true }.should raise_error(IOError) + -> { IOSpecs.closed_io.sync = true }.should raise_error(IOError) end end @@ -45,7 +45,7 @@ describe "IO#sync" do end it "raises an IOError on closed stream" do - lambda { IOSpecs.closed_io.sync }.should raise_error(IOError) + -> { IOSpecs.closed_io.sync }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/sysopen_spec.rb b/spec/ruby/core/io/sysopen_spec.rb index 91f70c3ca9..4607d13687 100644 --- a/spec/ruby/core/io/sysopen_spec.rb +++ b/spec/ruby/core/io/sysopen_spec.rb @@ -33,7 +33,7 @@ describe "IO.sysopen" do end it "accepts a mode as second argument" do - lambda { @fd = IO.sysopen(@filename, "w") }.should_not raise_error + -> { @fd = IO.sysopen(@filename, "w") }.should_not raise_error @fd.should_not equal(0) end diff --git a/spec/ruby/core/io/sysread_spec.rb b/spec/ruby/core/io/sysread_spec.rb index 4062620367..024200efea 100644 --- a/spec/ruby/core/io/sysread_spec.rb +++ b/spec/ruby/core/io/sysread_spec.rb @@ -58,13 +58,13 @@ describe "IO#sysread on a file" do it "does not raise error if called after IO#read followed by IO#write" do @file.read(5) @file.write("abcde") - lambda { @file.sysread(5) }.should_not raise_error(IOError) + -> { @file.sysread(5) }.should_not raise_error(IOError) end it "does not raise error if called after IO#read followed by IO#syswrite" do @file.read(5) @file.syswrite("abcde") - lambda { @file.sysread(5) }.should_not raise_error(IOError) + -> { @file.sysread(5) }.should_not raise_error(IOError) end it "reads updated content after the flushed buffered IO#write" do @@ -77,7 +77,7 @@ describe "IO#sysread on a file" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.sysread(5) }.should raise_error(IOError) + -> { IOSpecs.closed_io.sysread(5) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/sysseek_spec.rb b/spec/ruby/core/io/sysseek_spec.rb index 84e0a1a4ac..df894734e3 100644 --- a/spec/ruby/core/io/sysseek_spec.rb +++ b/spec/ruby/core/io/sysseek_spec.rb @@ -23,7 +23,7 @@ describe "IO#sysseek" do it "raises an error when called after buffered reads" do @io.readline - lambda { @io.sysseek(-5, IO::SEEK_CUR) }.should raise_error(IOError) + -> { @io.sysseek(-5, IO::SEEK_CUR) }.should raise_error(IOError) end it "moves the read position relative to the start with SEEK_SET" do @@ -36,7 +36,7 @@ describe "IO#sysseek" do # this is the safest way of checking the EOF when # sys-* methods are invoked - lambda { @io.sysread(1) }.should raise_error(EOFError) + -> { @io.sysread(1) }.should raise_error(EOFError) @io.sysseek(-25, IO::SEEK_END) @io.sysread(7).should == "cinco.\n" diff --git a/spec/ruby/core/io/syswrite_spec.rb b/spec/ruby/core/io/syswrite_spec.rb index a4dc8328aa..a28cc62174 100644 --- a/spec/ruby/core/io/syswrite_spec.rb +++ b/spec/ruby/core/io/syswrite_spec.rb @@ -31,13 +31,13 @@ describe "IO#syswrite on a file" do it "warns if called immediately after a buffered IO#write" do @file.write("abcde") - lambda { @file.syswrite("fghij") }.should complain(/syswrite/) + -> { @file.syswrite("fghij") }.should complain(/syswrite/) end it "does not warn if called after IO#write with intervening IO#sysread" do @file.syswrite("abcde") @file.sysread(5) - lambda { @file.syswrite("fghij") }.should_not complain + -> { @file.syswrite("fghij") }.should_not complain end it "writes to the actual file position when called after buffered IO#read" do diff --git a/spec/ruby/core/io/to_i_spec.rb b/spec/ruby/core/io/to_i_spec.rb index 7cd9e170d2..acf138c663 100644 --- a/spec/ruby/core/io/to_i_spec.rb +++ b/spec/ruby/core/io/to_i_spec.rb @@ -7,6 +7,6 @@ describe "IO#to_i" do end it "raises IOError on closed stream" do - lambda { IOSpecs.closed_io.to_i }.should raise_error(IOError) + -> { IOSpecs.closed_io.to_i }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/try_convert_spec.rb b/spec/ruby/core/io/try_convert_spec.rb index cff56ba618..5fbd10b6fa 100644 --- a/spec/ruby/core/io/try_convert_spec.rb +++ b/spec/ruby/core/io/try_convert_spec.rb @@ -38,12 +38,12 @@ describe "IO.try_convert" do it "raises a TypeError if the object does not return an IO from #to_io" do obj = mock("io") obj.should_receive(:to_io).and_return("io") - lambda { IO.try_convert(obj) }.should raise_error(TypeError) + -> { IO.try_convert(obj) }.should raise_error(TypeError) end it "propagates an exception raised by #to_io" do obj = mock("io") obj.should_receive(:to_io).and_raise(TypeError.new) - lambda{ IO.try_convert(obj) }.should raise_error(TypeError) + ->{ IO.try_convert(obj) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/io/ungetbyte_spec.rb b/spec/ruby/core/io/ungetbyte_spec.rb index f5f9a11be1..1971dee534 100644 --- a/spec/ruby/core/io/ungetbyte_spec.rb +++ b/spec/ruby/core/io/ungetbyte_spec.rb @@ -43,7 +43,7 @@ describe "IO#ungetbyte" do end it "... but not for Bignum argument (eh?)" do - lambda { + -> { @io.ungetbyte(0x4f7574206f6620636861722072616e6765) }.should raise_error(TypeError) end @@ -52,7 +52,7 @@ describe "IO#ungetbyte" do ruby_version_is '2.6'...'2.6.1' do it "is an RangeError if the integer is not in 8bit" do for i in [4095, 0x4f7574206f6620636861722072616e6765] do - lambda { @io.ungetbyte(i) }.should raise_error(RangeError) + -> { @io.ungetbyte(i) }.should raise_error(RangeError) end end end @@ -68,6 +68,6 @@ describe "IO#ungetbyte" do it "raises an IOError if the IO is closed" do @io.close - lambda { @io.ungetbyte(42) }.should raise_error(IOError) + -> { @io.ungetbyte(42) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/ungetc_spec.rb b/spec/ruby/core/io/ungetc_spec.rb index 7d090d0e5d..34d4caf745 100644 --- a/spec/ruby/core/io/ungetc_spec.rb +++ b/spec/ruby/core/io/ungetc_spec.rb @@ -100,7 +100,7 @@ describe "IO#ungetc" do it "makes subsequent unbuffered operations to raise IOError" do @io.getc @io.ungetc(100) - lambda { @io.sysread(1) }.should raise_error(IOError) + -> { @io.sysread(1) }.should raise_error(IOError) end it "does not affect the stream and returns nil when passed nil" do @@ -130,6 +130,6 @@ describe "IO#ungetc" do it "raises IOError on closed stream" do @io.getc @io.close - lambda { @io.ungetc(100) }.should raise_error(IOError) + -> { @io.ungetc(100) }.should raise_error(IOError) end end diff --git a/spec/ruby/core/io/write_nonblock_spec.rb b/spec/ruby/core/io/write_nonblock_spec.rb index 285d1af376..18adfcfc4a 100644 --- a/spec/ruby/core/io/write_nonblock_spec.rb +++ b/spec/ruby/core/io/write_nonblock_spec.rb @@ -32,7 +32,7 @@ platform_is_not :windows do end it "checks if the file is writable if writing zero bytes" do - lambda { + -> { @readonly_file.write_nonblock("") }.should raise_error(IOError) end @@ -54,7 +54,7 @@ describe 'IO#write_nonblock' do end it "raises an exception extending IO::WaitWritable when the write would block" do - lambda { + -> { loop { @write.write_nonblock('a' * 10_000) } }.should raise_error(IO::WaitWritable) { |e| platform_is_not :windows do diff --git a/spec/ruby/core/io/write_spec.rb b/spec/ruby/core/io/write_spec.rb index 5fb5cc7013..b28b582019 100644 --- a/spec/ruby/core/io/write_spec.rb +++ b/spec/ruby/core/io/write_spec.rb @@ -21,7 +21,7 @@ describe "IO#write on a file" do end it "does not check if the file is writable if writing zero bytes" do - lambda { @readonly_file.write("") }.should_not raise_error + -> { @readonly_file.write("") }.should_not raise_error end it "returns a length of 0 when writing a blank string" do @@ -59,7 +59,7 @@ describe "IO#write on a file" do # pack "\xFEhi" to avoid utf-8 conflict xFEhi = ([254].pack('C*') + 'hi').force_encoding('utf-8') File.open(@filename, "w", encoding: Encoding::US_ASCII) do |file| - lambda { file.write(xFEhi) }.should raise_error(Encoding::InvalidByteSequenceError) + -> { file.write(xFEhi) }.should raise_error(Encoding::InvalidByteSequenceError) end end diff --git a/spec/ruby/core/kernel/Array_spec.rb b/spec/ruby/core/kernel/Array_spec.rb index 5aa54cbcb6..b4a8bb7599 100644 --- a/spec/ruby/core/kernel/Array_spec.rb +++ b/spec/ruby/core/kernel/Array_spec.rb @@ -77,14 +77,14 @@ describe :kernel_Array, shared: true do obj = mock("Array() string") obj.should_receive(:to_ary).and_return("string") - lambda { @object.send(@method, obj) }.should raise_error(TypeError) + -> { @object.send(@method, obj) }.should raise_error(TypeError) end it "raises a TypeError if #to_a does not return an Array" do obj = mock("Array() string") obj.should_receive(:to_a).and_return("string") - lambda { @object.send(@method, obj) }.should raise_error(TypeError) + -> { @object.send(@method, obj) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/kernel/Complex_spec.rb b/spec/ruby/core/kernel/Complex_spec.rb index cb90718759..37f9843931 100644 --- a/spec/ruby/core/kernel/Complex_spec.rb +++ b/spec/ruby/core/kernel/Complex_spec.rb @@ -126,16 +126,16 @@ describe "Kernel.Complex()" do describe "when passed a non-Numeric second argument" do it "raises TypeError" do - lambda { Complex(:sym, :sym) }.should raise_error(TypeError) - lambda { Complex(0, :sym) }.should raise_error(TypeError) + -> { Complex(:sym, :sym) }.should raise_error(TypeError) + -> { Complex(0, :sym) }.should raise_error(TypeError) end end describe "when passed nil" do it "raises TypeError" do - lambda { Complex(nil) }.should raise_error(TypeError, "can't convert nil into Complex") - lambda { Complex(0, nil) }.should raise_error(TypeError, "can't convert nil into Complex") - lambda { Complex(nil, 0) }.should raise_error(TypeError, "can't convert nil into Complex") + -> { Complex(nil) }.should raise_error(TypeError, "can't convert nil into Complex") + -> { Complex(0, nil) }.should raise_error(TypeError, "can't convert nil into Complex") + -> { Complex(nil, 0) }.should raise_error(TypeError, "can't convert nil into Complex") end end @@ -155,7 +155,7 @@ describe "Kernel.Complex()" do describe "and [non-Numeric, Numeric] argument" do it "throws a TypeError" do - lambda { Complex(:sym, 0, exception: false) }.should raise_error(TypeError, "not a real") + -> { Complex(:sym, 0, exception: false) }.should raise_error(TypeError, "not a real") end end diff --git a/spec/ruby/core/kernel/Float_spec.rb b/spec/ruby/core/kernel/Float_spec.rb index 43daefa6aa..6580c38137 100644 --- a/spec/ruby/core/kernel/Float_spec.rb +++ b/spec/ruby/core/kernel/Float_spec.rb @@ -22,7 +22,7 @@ describe :kernel_float, shared: true do end it "raises an ArgumentError for nil" do - lambda { @object.send(:Float, nil) }.should raise_error(TypeError) + -> { @object.send(:Float, nil) }.should raise_error(TypeError) end it "returns the identical NaN for NaN" do @@ -51,24 +51,24 @@ describe :kernel_float, shared: true do end it "raises an ArgumentError for a String of word characters" do - lambda { @object.send(:Float, "float") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "float") }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are two decimal points in the String" do - lambda { @object.send(:Float, "10.0.0") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "10.0.0") }.should raise_error(ArgumentError) end it "raises an ArgumentError for a String of numbers followed by word characters" do - lambda { @object.send(:Float, "10D") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "10D") }.should raise_error(ArgumentError) end it "raises an ArgumentError for a String of word characters followed by numbers" do - lambda { @object.send(:Float, "D10") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "D10") }.should raise_error(ArgumentError) end it "is strict about the string form even across newlines" do - lambda { @object.send(:Float, "not a number\n10") }.should raise_error(ArgumentError) - lambda { @object.send(:Float, "10\nnot a number") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "not a number\n10") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "10\nnot a number") }.should raise_error(ArgumentError) end it "converts String subclasses to floats without calling #to_f" do @@ -90,17 +90,17 @@ describe :kernel_float, shared: true do end it "raises an ArgumentError if a + or - is embedded in a String" do - lambda { @object.send(:Float, "1+1") }.should raise_error(ArgumentError) - lambda { @object.send(:Float, "1-1") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "1+1") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "1-1") }.should raise_error(ArgumentError) end it "raises an ArgumentError if a String has a trailing + or -" do - lambda { @object.send(:Float, "11+") }.should raise_error(ArgumentError) - lambda { @object.send(:Float, "11-") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "11+") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "11-") }.should raise_error(ArgumentError) end it "raises an ArgumentError for a String with a leading _" do - lambda { @object.send(:Float, "_1") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "_1") }.should raise_error(ArgumentError) end it "returns a value for a String with an embedded _" do @@ -108,31 +108,31 @@ describe :kernel_float, shared: true do end it "raises an ArgumentError for a String with a trailing _" do - lambda { @object.send(:Float, "10_") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "10_") }.should raise_error(ArgumentError) end it "raises an ArgumentError for a String of \\0" do - lambda { @object.send(:Float, "\0") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "\0") }.should raise_error(ArgumentError) end it "raises an ArgumentError for a String with a leading \\0" do - lambda { @object.send(:Float, "\01") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "\01") }.should raise_error(ArgumentError) end it "raises an ArgumentError for a String with an embedded \\0" do - lambda { @object.send(:Float, "1\01") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "1\01") }.should raise_error(ArgumentError) end it "raises an ArgumentError for a String with a trailing \\0" do - lambda { @object.send(:Float, "1\0") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "1\0") }.should raise_error(ArgumentError) end it "raises an ArgumentError for a String that is just an empty space" do - lambda { @object.send(:Float, " ") }.should raise_error(ArgumentError) + -> { @object.send(:Float, " ") }.should raise_error(ArgumentError) end it "raises an ArgumentError for a String that with an embedded space" do - lambda { @object.send(:Float, "1 2") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "1 2") }.should raise_error(ArgumentError) end it "returns a value for a String with a leading space" do @@ -153,11 +153,11 @@ describe :kernel_float, shared: true do %w(e E).each do |e| it "raises an ArgumentError if #{e} is the trailing character" do - lambda { @object.send(:Float, "2#{e}") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "2#{e}") }.should raise_error(ArgumentError) end it "raises an ArgumentError if #{e} is the leading character" do - lambda { @object.send(:Float, "#{e}2") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "#{e}2") }.should raise_error(ArgumentError) end it "returns Infinity for '2#{e}1000'" do @@ -175,18 +175,18 @@ describe :kernel_float, shared: true do end it "raises an exception if a space is embedded on either side of the '#{e}'" do - lambda { @object.send(:Float, "2 0#{e}100") }.should raise_error(ArgumentError) - lambda { @object.send(:Float, "20#{e}1 00") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "2 0#{e}100") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "20#{e}1 00") }.should raise_error(ArgumentError) end it "raises an exception if there's a leading _ on either side of the '#{e}'" do - lambda { @object.send(:Float, "_20#{e}100") }.should raise_error(ArgumentError) - lambda { @object.send(:Float, "20#{e}_100") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "_20#{e}100") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "20#{e}_100") }.should raise_error(ArgumentError) end it "raises an exception if there's a trailing _ on either side of the '#{e}'" do - lambda { @object.send(:Float, "20_#{e}100") }.should raise_error(ArgumentError) - lambda { @object.send(:Float, "20#{e}100_") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "20_#{e}100") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "20#{e}100_") }.should raise_error(ArgumentError) end it "allows decimal points on the left side of the '#{e}'" do @@ -194,7 +194,7 @@ describe :kernel_float, shared: true do end it "raises an ArgumentError if there's a decimal point on the right side of the '#{e}'" do - lambda { @object.send(:Float, "20#{e}2.0") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "20#{e}2.0") }.should raise_error(ArgumentError) end end @@ -209,11 +209,11 @@ describe :kernel_float, shared: true do end it "raises an ArgumentError if #{p} is the trailing character" do - lambda { @object.send(:Float, "0x1#{p}") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "0x1#{p}") }.should raise_error(ArgumentError) end it "raises an ArgumentError if #{p} is the leading character" do - lambda { @object.send(:Float, "0x#{p}1") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "0x#{p}1") }.should raise_error(ArgumentError) end it "returns Infinity for '0x1#{p}10000'" do @@ -231,18 +231,18 @@ describe :kernel_float, shared: true do end it "raises an exception if a space is embedded on either side of the '#{p}'" do - lambda { @object.send(:Float, "0x1 0#{p}10") }.should raise_error(ArgumentError) - lambda { @object.send(:Float, "0x10#{p}1 0") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "0x1 0#{p}10") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "0x10#{p}1 0") }.should raise_error(ArgumentError) end it "raises an exception if there's a leading _ on either side of the '#{p}'" do - lambda { @object.send(:Float, "0x_10#{p}10") }.should raise_error(ArgumentError) - lambda { @object.send(:Float, "0x10#{p}_10") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "0x_10#{p}10") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "0x10#{p}_10") }.should raise_error(ArgumentError) end it "raises an exception if there's a trailing _ on either side of the '#{p}'" do - lambda { @object.send(:Float, "0x10_#{p}10") }.should raise_error(ArgumentError) - lambda { @object.send(:Float, "0x10#{p}10_") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "0x10_#{p}10") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "0x10#{p}10_") }.should raise_error(ArgumentError) end it "allows hexadecimal points on the left side of the '#{p}'" do @@ -250,7 +250,7 @@ describe :kernel_float, shared: true do end it "raises an ArgumentError if there's a decimal point on the right side of the '#{p}'" do - lambda { @object.send(:Float, "0x1#{p}1.0") }.should raise_error(ArgumentError) + -> { @object.send(:Float, "0x1#{p}1.0") }.should raise_error(ArgumentError) end end end @@ -282,22 +282,22 @@ describe :kernel_float, shared: true do end it "raises a TypeError if #to_f is not provided" do - lambda { @object.send(:Float, mock('x')) }.should raise_error(TypeError) + -> { @object.send(:Float, mock('x')) }.should raise_error(TypeError) end it "raises a TypeError if #to_f returns a String" do (obj = mock('ha!')).should_receive(:to_f).once.and_return('ha!') - lambda { @object.send(:Float, obj) }.should raise_error(TypeError) + -> { @object.send(:Float, obj) }.should raise_error(TypeError) end it "raises a TypeError if #to_f returns an Integer" do (obj = mock('123')).should_receive(:to_f).once.and_return(123) - lambda { @object.send(:Float, obj) }.should raise_error(TypeError) + -> { @object.send(:Float, obj) }.should raise_error(TypeError) end it "raises a RangeError when passed a Complex argument" do c = Complex(2, 3) - lambda { @object.send(:Float, c) }.should raise_error(RangeError) + -> { @object.send(:Float, c) }.should raise_error(RangeError) end ruby_version_is "2.6" do diff --git a/spec/ruby/core/kernel/Hash_spec.rb b/spec/ruby/core/kernel/Hash_spec.rb index 89e97fb11e..cbe098a8ac 100644 --- a/spec/ruby/core/kernel/Hash_spec.rb +++ b/spec/ruby/core/kernel/Hash_spec.rb @@ -43,14 +43,14 @@ describe :kernel_Hash, shared: true do end it "raises a TypeError if it doesn't respond to #to_hash" do - lambda { @object.send(@method, mock("")) }.should raise_error(TypeError) + -> { @object.send(@method, mock("")) }.should raise_error(TypeError) end it "raises a TypeError if #to_hash does not return an Hash" do obj = mock("Hash() string") obj.should_receive(:to_hash).and_return("string") - lambda { @object.send(@method, obj) }.should raise_error(TypeError) + -> { @object.send(@method, obj) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/kernel/Integer_spec.rb b/spec/ruby/core/kernel/Integer_spec.rb index b7e05e701b..59b41d37e6 100644 --- a/spec/ruby/core/kernel/Integer_spec.rb +++ b/spec/ruby/core/kernel/Integer_spec.rb @@ -24,7 +24,7 @@ describe :kernel_integer, shared: true do obj = mock("object") obj.should_receive(:to_int).and_return("1") obj.should_receive(:to_i).and_return(nil) - lambda { Integer(obj) }.should raise_error(TypeError) + -> { Integer(obj) }.should raise_error(TypeError) end it "return a result of to_i when to_int does not return an Integer" do @@ -36,7 +36,7 @@ describe :kernel_integer, shared: true do end it "raises a TypeError when passed nil" do - lambda { Integer(nil) }.should raise_error(TypeError) + -> { Integer(nil) }.should raise_error(TypeError) end it "returns a Fixnum or Bignum object" do @@ -78,26 +78,26 @@ describe :kernel_integer, shared: true do it "raises a TypeError if to_i returns a value that is not an Integer" do obj = mock("object") obj.should_receive(:to_i).and_return("1") - lambda { Integer(obj) }.should raise_error(TypeError) + -> { Integer(obj) }.should raise_error(TypeError) end it "raises a TypeError if no to_int or to_i methods exist" do obj = mock("object") - lambda { Integer(obj) }.should raise_error(TypeError) + -> { Integer(obj) }.should raise_error(TypeError) end it "raises a TypeError if to_int returns nil and no to_i exists" do obj = mock("object") obj.should_receive(:to_i).and_return(nil) - lambda { Integer(obj) }.should raise_error(TypeError) + -> { Integer(obj) }.should raise_error(TypeError) end it "raises a FloatDomainError when passed NaN" do - lambda { Integer(nan_value) }.should raise_error(FloatDomainError) + -> { Integer(nan_value) }.should raise_error(FloatDomainError) end it "raises a FloatDomainError when passed Infinity" do - lambda { Integer(infinity_value) }.should raise_error(FloatDomainError) + -> { Integer(infinity_value) }.should raise_error(FloatDomainError) end ruby_version_is "2.6" do @@ -160,19 +160,19 @@ end describe "Integer() given a String", shared: true do it "raises an ArgumentError if the String is a null byte" do - lambda { Integer("\0") }.should raise_error(ArgumentError) + -> { Integer("\0") }.should raise_error(ArgumentError) end it "raises an ArgumentError if the String starts with a null byte" do - lambda { Integer("\01") }.should raise_error(ArgumentError) + -> { Integer("\01") }.should raise_error(ArgumentError) end it "raises an ArgumentError if the String ends with a null byte" do - lambda { Integer("1\0") }.should raise_error(ArgumentError) + -> { Integer("1\0") }.should raise_error(ArgumentError) end it "raises an ArgumentError if the String contains a null byte" do - lambda { Integer("1\01") }.should raise_error(ArgumentError) + -> { Integer("1\01") }.should raise_error(ArgumentError) end it "ignores leading whitespace" do @@ -188,13 +188,13 @@ describe "Integer() given a String", shared: true do end it "raises an ArgumentError if there are leading _s" do - lambda { Integer("_1") }.should raise_error(ArgumentError) - lambda { Integer("___1") }.should raise_error(ArgumentError) + -> { Integer("_1") }.should raise_error(ArgumentError) + -> { Integer("___1") }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are trailing _s" do - lambda { Integer("1_") }.should raise_error(ArgumentError) - lambda { Integer("1___") }.should raise_error(ArgumentError) + -> { Integer("1_") }.should raise_error(ArgumentError) + -> { Integer("1___") }.should raise_error(ArgumentError) end it "ignores an embedded _" do @@ -202,8 +202,8 @@ describe "Integer() given a String", shared: true do end it "raises an ArgumentError if there are multiple embedded _s" do - lambda { Integer("1__1") }.should raise_error(ArgumentError) - lambda { Integer("1___1") }.should raise_error(ArgumentError) + -> { Integer("1__1") }.should raise_error(ArgumentError) + -> { Integer("1___1") }.should raise_error(ArgumentError) end it "ignores a single leading +" do @@ -211,17 +211,17 @@ describe "Integer() given a String", shared: true do end it "raises an ArgumentError if there is a space between the + and number" do - lambda { Integer("+ 1") }.should raise_error(ArgumentError) + -> { Integer("+ 1") }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are multiple leading +s" do - lambda { Integer("++1") }.should raise_error(ArgumentError) - lambda { Integer("+++1") }.should raise_error(ArgumentError) + -> { Integer("++1") }.should raise_error(ArgumentError) + -> { Integer("+++1") }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are trailing +s" do - lambda { Integer("1+") }.should raise_error(ArgumentError) - lambda { Integer("1+++") }.should raise_error(ArgumentError) + -> { Integer("1+") }.should raise_error(ArgumentError) + -> { Integer("1+++") }.should raise_error(ArgumentError) end it "makes the number negative if there's a leading -" do @@ -229,21 +229,21 @@ describe "Integer() given a String", shared: true do end it "raises an ArgumentError if there are multiple leading -s" do - lambda { Integer("--1") }.should raise_error(ArgumentError) - lambda { Integer("---1") }.should raise_error(ArgumentError) + -> { Integer("--1") }.should raise_error(ArgumentError) + -> { Integer("---1") }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are trailing -s" do - lambda { Integer("1-") }.should raise_error(ArgumentError) - lambda { Integer("1---") }.should raise_error(ArgumentError) + -> { Integer("1-") }.should raise_error(ArgumentError) + -> { Integer("1---") }.should raise_error(ArgumentError) end it "raises an ArgumentError if there is a period" do - lambda { Integer("0.0") }.should raise_error(ArgumentError) + -> { Integer("0.0") }.should raise_error(ArgumentError) end it "raises an ArgumentError for an empty String" do - lambda { Integer("") }.should raise_error(ArgumentError) + -> { Integer("") }.should raise_error(ArgumentError) end ruby_version_is "2.6" do @@ -295,7 +295,7 @@ describe "Integer() given a String", shared: true do end it "raises an ArgumentError if the number cannot be parsed as hex" do - lambda { Integer("0#{x}g") }.should raise_error(ArgumentError) + -> { Integer("0#{x}g") }.should raise_error(ArgumentError) end end @@ -316,7 +316,7 @@ describe "Integer() given a String", shared: true do end it "raises an ArgumentError if the number cannot be parsed as binary" do - lambda { Integer("0#{b}2") }.should raise_error(ArgumentError) + -> { Integer("0#{b}2") }.should raise_error(ArgumentError) end end @@ -337,7 +337,7 @@ describe "Integer() given a String", shared: true do end it "raises an ArgumentError if the number cannot be parsed as octal" do - lambda { Integer("0#{o}9") }.should raise_error(ArgumentError) + -> { Integer("0#{o}9") }.should raise_error(ArgumentError) end end @@ -358,26 +358,26 @@ describe "Integer() given a String", shared: true do end it "raises an ArgumentError if the number cannot be parsed as decimal" do - lambda { Integer("0#{d}a") }.should raise_error(ArgumentError) + -> { Integer("0#{d}a") }.should raise_error(ArgumentError) end end end describe "Integer() given a String and base", shared: true do it "raises an ArgumentError if the String is a null byte" do - lambda { Integer("\0", 2) }.should raise_error(ArgumentError) + -> { Integer("\0", 2) }.should raise_error(ArgumentError) end it "raises an ArgumentError if the String starts with a null byte" do - lambda { Integer("\01", 3) }.should raise_error(ArgumentError) + -> { Integer("\01", 3) }.should raise_error(ArgumentError) end it "raises an ArgumentError if the String ends with a null byte" do - lambda { Integer("1\0", 4) }.should raise_error(ArgumentError) + -> { Integer("1\0", 4) }.should raise_error(ArgumentError) end it "raises an ArgumentError if the String contains a null byte" do - lambda { Integer("1\01", 5) }.should raise_error(ArgumentError) + -> { Integer("1\01", 5) }.should raise_error(ArgumentError) end it "ignores leading whitespace" do @@ -393,13 +393,13 @@ describe "Integer() given a String and base", shared: true do end it "raises an ArgumentError if there are leading _s" do - lambda { Integer("_1", 7) }.should raise_error(ArgumentError) - lambda { Integer("___1", 7) }.should raise_error(ArgumentError) + -> { Integer("_1", 7) }.should raise_error(ArgumentError) + -> { Integer("___1", 7) }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are trailing _s" do - lambda { Integer("1_", 12) }.should raise_error(ArgumentError) - lambda { Integer("1___", 12) }.should raise_error(ArgumentError) + -> { Integer("1_", 12) }.should raise_error(ArgumentError) + -> { Integer("1___", 12) }.should raise_error(ArgumentError) end it "ignores an embedded _" do @@ -407,8 +407,8 @@ describe "Integer() given a String and base", shared: true do end it "raises an ArgumentError if there are multiple embedded _s" do - lambda { Integer("1__1", 4) }.should raise_error(ArgumentError) - lambda { Integer("1___1", 4) }.should raise_error(ArgumentError) + -> { Integer("1__1", 4) }.should raise_error(ArgumentError) + -> { Integer("1___1", 4) }.should raise_error(ArgumentError) end it "ignores a single leading +" do @@ -416,17 +416,17 @@ describe "Integer() given a String and base", shared: true do end it "raises an ArgumentError if there is a space between the + and number" do - lambda { Integer("+ 1", 3) }.should raise_error(ArgumentError) + -> { Integer("+ 1", 3) }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are multiple leading +s" do - lambda { Integer("++1", 3) }.should raise_error(ArgumentError) - lambda { Integer("+++1", 3) }.should raise_error(ArgumentError) + -> { Integer("++1", 3) }.should raise_error(ArgumentError) + -> { Integer("+++1", 3) }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are trailing +s" do - lambda { Integer("1+", 3) }.should raise_error(ArgumentError) - lambda { Integer("1+++", 12) }.should raise_error(ArgumentError) + -> { Integer("1+", 3) }.should raise_error(ArgumentError) + -> { Integer("1+++", 12) }.should raise_error(ArgumentError) end it "makes the number negative if there's a leading -" do @@ -434,29 +434,29 @@ describe "Integer() given a String and base", shared: true do end it "raises an ArgumentError if there are multiple leading -s" do - lambda { Integer("--1", 9) }.should raise_error(ArgumentError) - lambda { Integer("---1", 9) }.should raise_error(ArgumentError) + -> { Integer("--1", 9) }.should raise_error(ArgumentError) + -> { Integer("---1", 9) }.should raise_error(ArgumentError) end it "raises an ArgumentError if there are trailing -s" do - lambda { Integer("1-", 12) }.should raise_error(ArgumentError) - lambda { Integer("1---", 12) }.should raise_error(ArgumentError) + -> { Integer("1-", 12) }.should raise_error(ArgumentError) + -> { Integer("1---", 12) }.should raise_error(ArgumentError) end it "raises an ArgumentError if there is a period" do - lambda { Integer("0.0", 3) }.should raise_error(ArgumentError) + -> { Integer("0.0", 3) }.should raise_error(ArgumentError) end it "raises an ArgumentError for an empty String" do - lambda { Integer("", 12) }.should raise_error(ArgumentError) + -> { Integer("", 12) }.should raise_error(ArgumentError) end it "raises an ArgumentError for a base of 1" do - lambda { Integer("1", 1) }.should raise_error(ArgumentError) + -> { Integer("1", 1) }.should raise_error(ArgumentError) end it "raises an ArgumentError for a base of 37" do - lambda { Integer("1", 37) }.should raise_error(ArgumentError) + -> { Integer("1", 37) }.should raise_error(ArgumentError) end it "accepts wholly lowercase alphabetic strings for bases > 10" do @@ -484,8 +484,8 @@ describe "Integer() given a String and base", shared: true do end it "raises an ArgumentError for letters invalid in the given base" do - lambda { Integer('z',19) }.should raise_error(ArgumentError) - lambda { Integer('c00o',2) }.should raise_error(ArgumentError) + -> { Integer('z',19) }.should raise_error(ArgumentError) + -> { Integer('c00o',2) }.should raise_error(ArgumentError) end %w(x X).each do |x| @@ -506,12 +506,12 @@ describe "Integer() given a String and base", shared: true do 2.upto(15) do |base| it "raises an ArgumentError if the number begins with 0#{x} and the base is #{base}" do - lambda { Integer("0#{x}1", base) }.should raise_error(ArgumentError) + -> { Integer("0#{x}1", base) }.should raise_error(ArgumentError) end end it "raises an ArgumentError if the number cannot be parsed as hex and the base is 16" do - lambda { Integer("0#{x}g", 16) }.should raise_error(ArgumentError) + -> { Integer("0#{x}g", 16) }.should raise_error(ArgumentError) end end @@ -532,7 +532,7 @@ describe "Integer() given a String and base", shared: true do end it "raises an ArgumentError if the number cannot be parsed as binary and the base is 2" do - lambda { Integer("0#{b}2", 2) }.should raise_error(ArgumentError) + -> { Integer("0#{b}2", 2) }.should raise_error(ArgumentError) end end @@ -553,12 +553,12 @@ describe "Integer() given a String and base", shared: true do end it "raises an ArgumentError if the number cannot be parsed as octal and the base is 8" do - lambda { Integer("0#{o}9", 8) }.should raise_error(ArgumentError) + -> { Integer("0#{o}9", 8) }.should raise_error(ArgumentError) end 2.upto(7) do |base| it "raises an ArgumentError if the number begins with 0#{o} and the base is #{base}" do - lambda { Integer("0#{o}1", base) }.should raise_error(ArgumentError) + -> { Integer("0#{o}1", base) }.should raise_error(ArgumentError) end end end @@ -580,17 +580,17 @@ describe "Integer() given a String and base", shared: true do end it "raises an ArgumentError if the number cannot be parsed as decimal and the base is 10" do - lambda { Integer("0#{d}a", 10) }.should raise_error(ArgumentError) + -> { Integer("0#{d}a", 10) }.should raise_error(ArgumentError) end 2.upto(9) do |base| it "raises an ArgumentError if the number begins with 0#{d} and the base is #{base}" do - lambda { Integer("0#{d}1", base) }.should raise_error(ArgumentError) + -> { Integer("0#{d}1", base) }.should raise_error(ArgumentError) end end it "raises an ArgumentError if a base is given for a non-String value" do - lambda { Integer(98, 15) }.should raise_error(ArgumentError) + -> { Integer(98, 15) }.should raise_error(ArgumentError) end end @@ -616,176 +616,176 @@ end describe :kernel_Integer, shared: true do it "raises an ArgumentError when the String contains digits out of range of radix 2" do str = "23456789abcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 2) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 2) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 3" do str = "3456789abcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 3) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 3) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 4" do str = "456789abcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 4) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 4) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 5" do str = "56789abcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 5) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 5) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 6" do str = "6789abcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 6) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 6) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 7" do str = "789abcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 7) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 7) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 8" do str = "89abcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 8) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 8) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 9" do str = "9abcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 9) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 9) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 10" do str = "abcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 10) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 10) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 11" do str = "bcdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 11) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 11) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 12" do str = "cdefghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 12) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 12) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 13" do str = "defghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 13) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 13) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 14" do str = "efghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 14) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 14) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 15" do str = "fghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 15) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 15) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 16" do str = "ghijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 16) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 16) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 17" do str = "hijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 17) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 17) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 18" do str = "ijklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 18) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 18) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 19" do str = "jklmnopqrstuvwxyz" - lambda { @object.send(@method, str, 19) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 19) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 20" do str = "klmnopqrstuvwxyz" - lambda { @object.send(@method, str, 20) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 20) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 21" do str = "lmnopqrstuvwxyz" - lambda { @object.send(@method, str, 21) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 21) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 22" do str = "mnopqrstuvwxyz" - lambda { @object.send(@method, str, 22) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 22) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 23" do str = "nopqrstuvwxyz" - lambda { @object.send(@method, str, 23) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 23) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 24" do str = "opqrstuvwxyz" - lambda { @object.send(@method, str, 24) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 24) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 25" do str = "pqrstuvwxyz" - lambda { @object.send(@method, str, 25) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 25) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 26" do str = "qrstuvwxyz" - lambda { @object.send(@method, str, 26) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 26) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 27" do str = "rstuvwxyz" - lambda { @object.send(@method, str, 27) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 27) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 28" do str = "stuvwxyz" - lambda { @object.send(@method, str, 28) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 28) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 29" do str = "tuvwxyz" - lambda { @object.send(@method, str, 29) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 29) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 30" do str = "uvwxyz" - lambda { @object.send(@method, str, 30) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 30) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 31" do str = "vwxyz" - lambda { @object.send(@method, str, 31) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 31) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 32" do str = "wxyz" - lambda { @object.send(@method, str, 32) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 32) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 33" do str = "xyz" - lambda { @object.send(@method, str, 33) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 33) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 34" do str = "yz" - lambda { @object.send(@method, str, 34) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 34) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 35" do str = "z" - lambda { @object.send(@method, str, 35) }.should raise_error(ArgumentError) + -> { @object.send(@method, str, 35) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the String contains digits out of range of radix 36" do - lambda { @object.send(@method, "{", 36) }.should raise_error(ArgumentError) + -> { @object.send(@method, "{", 36) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/kernel/String_spec.rb b/spec/ruby/core/kernel/String_spec.rb index 81489875c8..47ee797be5 100644 --- a/spec/ruby/core/kernel/String_spec.rb +++ b/spec/ruby/core/kernel/String_spec.rb @@ -32,7 +32,7 @@ describe :kernel_String, shared: true do undef_method :to_s end - lambda { @object.send(@method, obj) }.should raise_error(TypeError) + -> { @object.send(@method, obj) }.should raise_error(TypeError) end # #5158 @@ -44,7 +44,7 @@ describe :kernel_String, shared: true do end end - lambda { @object.send(@method, obj) }.should raise_error(TypeError) + -> { @object.send(@method, obj) }.should raise_error(TypeError) end it "raises a TypeError if #to_s is not defined, even though #respond_to?(:to_s) returns true" do @@ -57,7 +57,7 @@ describe :kernel_String, shared: true do end end - lambda { @object.send(@method, obj) }.should raise_error(TypeError) + -> { @object.send(@method, obj) }.should raise_error(TypeError) end it "calls #to_s if #respond_to?(:to_s) returns true" do @@ -74,7 +74,7 @@ describe :kernel_String, shared: true do it "raises a TypeError if #to_s does not return a String" do (obj = mock('123')).should_receive(:to_s).and_return(123) - lambda { @object.send(@method, obj) }.should raise_error(TypeError) + -> { @object.send(@method, obj) }.should raise_error(TypeError) end it "returns the same object if it is already a String" do diff --git a/spec/ruby/core/kernel/backtick_spec.rb b/spec/ruby/core/kernel/backtick_spec.rb index dcba218f61..5ab0fb0eea 100644 --- a/spec/ruby/core/kernel/backtick_spec.rb +++ b/spec/ruby/core/kernel/backtick_spec.rb @@ -21,7 +21,7 @@ describe "Kernel#`" do it "lets the standard error stream pass through to the inherited stderr" do cmd = ruby_cmd('STDERR.print "error stream"') - lambda { + -> { `#{cmd}`.should == "" }.should output_to_fd("error stream", STDERR) end @@ -32,7 +32,7 @@ describe "Kernel#`" do end it "raises an Errno::ENOENT if the command is not executable" do - lambda { `nonexistent_command` }.should raise_error(Errno::ENOENT) + -> { `nonexistent_command` }.should raise_error(Errno::ENOENT) end platform_is_not :windows do diff --git a/spec/ruby/core/kernel/binding_spec.rb b/spec/ruby/core/kernel/binding_spec.rb index e9fca6e3ab..f1c9c6ec9f 100644 --- a/spec/ruby/core/kernel/binding_spec.rb +++ b/spec/ruby/core/kernel/binding_spec.rb @@ -35,7 +35,7 @@ describe "Kernel#binding" do end it "raises a NameError on undefined variable" do - lambda { eval("a_fake_variable", @b1) }.should raise_error(NameError) + -> { eval("a_fake_variable", @b1) }.should raise_error(NameError) end it "uses the closure's self as self in the binding" do diff --git a/spec/ruby/core/kernel/catch_spec.rb b/spec/ruby/core/kernel/catch_spec.rb index 092fb4968a..4060172429 100644 --- a/spec/ruby/core/kernel/catch_spec.rb +++ b/spec/ruby/core/kernel/catch_spec.rb @@ -31,11 +31,11 @@ describe "Kernel.catch" do end it "raises an ArgumentError if a Symbol is thrown for a String catch value" do - lambda { catch("exit") { throw :exit } }.should raise_error(ArgumentError) + -> { catch("exit") { throw :exit } }.should raise_error(ArgumentError) end it "raises an ArgumentError if a String with different identity is thrown" do - lambda { catch("exit") { throw "exit" } }.should raise_error(ArgumentError) + -> { catch("exit") { throw "exit" } }.should raise_error(ArgumentError) end it "catches a Symbol when thrown a matching Symbol" do @@ -116,7 +116,7 @@ describe "Kernel.catch" do end it "raises LocalJumpError if no block is given" do - lambda { catch :blah }.should raise_error(LocalJumpError) + -> { catch :blah }.should raise_error(LocalJumpError) end end diff --git a/spec/ruby/core/kernel/define_singleton_method_spec.rb b/spec/ruby/core/kernel/define_singleton_method_spec.rb index c2f2da7c79..dc77c3e6f8 100644 --- a/spec/ruby/core/kernel/define_singleton_method_spec.rb +++ b/spec/ruby/core/kernel/define_singleton_method_spec.rb @@ -21,7 +21,7 @@ describe "Kernel#define_singleton_method" do um = KernelSpecs::Parent.method(:parent_class_method).unbind KernelSpecs::Child.send :define_singleton_method, :child_class_method, um KernelSpecs::Child.child_class_method.should == :foo - lambda{KernelSpecs::Parent.child_class_method}.should raise_error(NoMethodError) + ->{KernelSpecs::Parent.child_class_method}.should raise_error(NoMethodError) end it "will raise when attempting to define an object's singleton method from another object's singleton method" do @@ -33,7 +33,7 @@ describe "Kernel#define_singleton_method" do end end um = p.method(:singleton_method).unbind - lambda{ other.send :define_singleton_method, :other_singleton_method, um }.should raise_error(TypeError) + ->{ other.send :define_singleton_method, :other_singleton_method, um }.should raise_error(TypeError) end end @@ -41,7 +41,7 @@ describe "Kernel#define_singleton_method" do it "defines a new method with the given name and the given block as body in self" do class DefineSingletonMethodSpecClass define_singleton_method(:block_test1) { self } - define_singleton_method(:block_test2, &lambda { self }) + define_singleton_method(:block_test2, &-> { self }) end o = DefineSingletonMethodSpecClass @@ -50,11 +50,11 @@ describe "Kernel#define_singleton_method" do end it "raises a TypeError when the given method is no Method/Proc" do - lambda { + -> { Class.new { define_singleton_method(:test, "self") } }.should raise_error(TypeError) - lambda { + -> { Class.new { define_singleton_method(:test, 1234) } }.should raise_error(TypeError) end @@ -63,7 +63,7 @@ describe "Kernel#define_singleton_method" do obj = Object.new obj.define_singleton_method(:test) { "world!" } obj.test.should == "world!" - lambda { + -> { Object.new.test }.should raise_error(NoMethodError) end @@ -81,7 +81,7 @@ describe "Kernel#define_singleton_method" do it "raises an ArgumentError when no block is given" do obj = Object.new - lambda { + -> { obj.define_singleton_method(:test) }.should raise_error(ArgumentError) end @@ -92,7 +92,7 @@ describe "Kernel#define_singleton_method" do define_singleton_method(name) end - lambda { + -> { o.define(:foo) { raise "not used" } }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/kernel/dup_spec.rb b/spec/ruby/core/kernel/dup_spec.rb index ce81f7018a..fe0a269d69 100644 --- a/spec/ruby/core/kernel/dup_spec.rb +++ b/spec/ruby/core/kernel/dup_spec.rb @@ -44,7 +44,7 @@ describe "Kernel#dup" do it "does not copy singleton methods" do def @obj.special() :the_one end dup = @obj.dup - lambda { dup.special }.should raise_error(NameError) + -> { dup.special }.should raise_error(NameError) end it "does not copy modules included in the singleton class" do @@ -53,7 +53,7 @@ describe "Kernel#dup" do end dup = @obj.dup - lambda { dup.repr }.should raise_error(NameError) + -> { dup.repr }.should raise_error(NameError) end it "does not copy constants defined in the singleton class" do @@ -62,6 +62,6 @@ describe "Kernel#dup" do end dup = @obj.dup - lambda { class << dup; CLONE; end }.should raise_error(NameError) + -> { class << dup; CLONE; end }.should raise_error(NameError) end end diff --git a/spec/ruby/core/kernel/eval_spec.rb b/spec/ruby/core/kernel/eval_spec.rb index 696c55a3ba..9442725eac 100644 --- a/spec/ruby/core/kernel/eval_spec.rb +++ b/spec/ruby/core/kernel/eval_spec.rb @@ -76,12 +76,12 @@ describe "Kernel#eval" do x = 1 bind = proc {} - lambda { eval("x", bind) }.should raise_error(TypeError) + -> { eval("x", bind) }.should raise_error(TypeError) end it "does not make Proc locals visible to evaluated code" do bind = proc { inner = 4 } - lambda { eval("inner", bind.binding) }.should raise_error(NameError) + -> { eval("inner", bind.binding) }.should raise_error(NameError) end # REWRITE ME: This obscures the real behavior of where locals are stored @@ -134,7 +134,7 @@ describe "Kernel#eval" do it "includes file and line information in syntax error" do expected = 'speccing.rb' - lambda { + -> { eval('if true',TOPLEVEL_BINDING, expected) }.should raise_error(SyntaxError) { |e| e.message.should =~ /#{expected}:1:.+/ @@ -143,7 +143,7 @@ describe "Kernel#eval" do it "evaluates string with given filename and negative linenumber" do expected_file = 'speccing.rb' - lambda { + -> { eval('if true',TOPLEVEL_BINDING, expected_file, -100) }.should raise_error(SyntaxError) { |e| e.message.should =~ /#{expected_file}:-100:.+/ @@ -195,13 +195,13 @@ describe "Kernel#eval" do end it "does not pass the block to the method being eval'ed" do - lambda { + -> { eval('KernelSpecs::EvalTest.call_yield') { "content" } }.should raise_error(LocalJumpError) end it "returns from the scope calling #eval when evaluating 'return'" do - lambda { eval("return :eval") }.call.should == :eval + -> { eval("return :eval") }.call.should == :eval end it "unwinds through a Proc-style closure and returns from a lambda-style closure in the closure chain" do diff --git a/spec/ruby/core/kernel/extend_spec.rb b/spec/ruby/core/kernel/extend_spec.rb index f4f9dde098..9f98b3681f 100644 --- a/spec/ruby/core/kernel/extend_spec.rb +++ b/spec/ruby/core/kernel/extend_spec.rb @@ -53,13 +53,13 @@ describe "Kernel#extend" do end it "raises an ArgumentError when no arguments given" do - lambda { Object.new.extend }.should raise_error(ArgumentError) + -> { Object.new.extend }.should raise_error(ArgumentError) end it "raises a TypeError when the argument is not a Module" do o = mock('o') klass = Class.new - lambda { o.extend(klass) }.should raise_error(TypeError) + -> { o.extend(klass) }.should raise_error(TypeError) end describe "on frozen instance" do @@ -69,11 +69,11 @@ describe "Kernel#extend" do end it "raises an ArgumentError when no arguments given" do - lambda { @frozen.extend }.should raise_error(ArgumentError) + -> { @frozen.extend }.should raise_error(ArgumentError) end it "raises a #{frozen_error_class}" do - lambda { @frozen.extend @module }.should raise_error(frozen_error_class) + -> { @frozen.extend @module }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/kernel/fail_spec.rb b/spec/ruby/core/kernel/fail_spec.rb index a5948cefae..fab622037e 100644 --- a/spec/ruby/core/kernel/fail_spec.rb +++ b/spec/ruby/core/kernel/fail_spec.rb @@ -7,7 +7,7 @@ describe "Kernel#fail" do end it "raises a RuntimeError" do - lambda { fail }.should raise_error(RuntimeError) + -> { fail }.should raise_error(RuntimeError) end it "accepts an Object with an exception method returning an Exception" do @@ -15,16 +15,16 @@ describe "Kernel#fail" do def obj.exception(msg) StandardError.new msg end - lambda { fail obj, "..." }.should raise_error(StandardError, "...") + -> { fail obj, "..." }.should raise_error(StandardError, "...") end it "instantiates the specified exception class" do error_class = Class.new(RuntimeError) - lambda { fail error_class }.should raise_error(error_class) + -> { fail error_class }.should raise_error(error_class) end it "uses the specified message" do - lambda { + -> { begin fail "the duck is not irish." rescue => e diff --git a/spec/ruby/core/kernel/fixtures/classes.rb b/spec/ruby/core/kernel/fixtures/classes.rb index 1f45bbb083..2909a621a9 100644 --- a/spec/ruby/core/kernel/fixtures/classes.rb +++ b/spec/ruby/core/kernel/fixtures/classes.rb @@ -328,7 +328,7 @@ module KernelSpecs def inner b = mp { return :good } - pr = lambda { |x| x.call } + pr = -> x { x.call } pr.call(b) @@ -424,6 +424,20 @@ module KernelSpecs def f2_call_lineno; method(:f3).source_location[1] + 1; end def f3_call_lineno; method(:f4).source_location[1] + 1; end end + + CustomRangeInteger = Struct.new(:value) do + def to_int; value; end + def <=>(other); to_int <=> other.to_int; end + def -(other); self.class.new(to_int - other.to_int); end + def +(other); self.class.new(to_int + other.to_int); end + end + + CustomRangeFloat = Struct.new(:value) do + def to_f; value; end + def <=>(other); to_f <=> other.to_f; end + def -(other); to_f - other.to_f; end + def +(other); self.class.new(to_f + other.to_f); end + end end class EvalSpecs @@ -454,12 +468,3 @@ class EvalSpecs return f end end - -# for Kernel#sleep to have Channel in it's specs -# TODO: switch directly to queue for both Kernel#sleep and Thread specs? -unless defined? Channel - require 'thread' - class Channel < Queue - alias receive shift - end -end diff --git a/spec/ruby/core/kernel/fixtures/eval_return_with_lambda.rb b/spec/ruby/core/kernel/fixtures/eval_return_with_lambda.rb index a48b5685f3..9e2d045bf3 100644 --- a/spec/ruby/core/kernel/fixtures/eval_return_with_lambda.rb +++ b/spec/ruby/core/kernel/fixtures/eval_return_with_lambda.rb @@ -1,5 +1,5 @@ print "a," -x = lambda do +x = -> do print "b," Proc.new do print "c," diff --git a/spec/ruby/core/kernel/freeze_spec.rb b/spec/ruby/core/kernel/freeze_spec.rb index 018784a4f5..214b619f9f 100644 --- a/spec/ruby/core/kernel/freeze_spec.rb +++ b/spec/ruby/core/kernel/freeze_spec.rb @@ -74,12 +74,12 @@ describe "Kernel#freeze" do def mutate; @foo = 1; end end.new o.freeze - lambda {o.mutate}.should raise_error(RuntimeError) + -> {o.mutate}.should raise_error(RuntimeError) end it "causes instance_variable_set to raise RuntimeError" do o = Object.new o.freeze - lambda {o.instance_variable_set(:@foo, 1)}.should raise_error(RuntimeError) + -> {o.instance_variable_set(:@foo, 1)}.should raise_error(RuntimeError) end end diff --git a/spec/ruby/core/kernel/gsub_spec.rb b/spec/ruby/core/kernel/gsub_spec.rb index 2bcb29f60e..a0cb9f2a70 100644 --- a/spec/ruby/core/kernel/gsub_spec.rb +++ b/spec/ruby/core/kernel/gsub_spec.rb @@ -10,7 +10,7 @@ ruby_version_is ""..."1.9" do end it "raises a TypeError if $_ is not a String" do - lambda { + -> { $_ = 123 gsub(/./, "!") }.should raise_error(TypeError) diff --git a/spec/ruby/core/kernel/instance_of_spec.rb b/spec/ruby/core/kernel/instance_of_spec.rb index 78cddb443f..40e856b0d9 100644 --- a/spec/ruby/core/kernel/instance_of_spec.rb +++ b/spec/ruby/core/kernel/instance_of_spec.rb @@ -33,8 +33,8 @@ describe Kernel, "#instance_of?" do end it "raises a TypeError if given an object that is not a Class nor a Module" do - lambda { @o.instance_of?(Object.new) }.should raise_error(TypeError) - lambda { @o.instance_of?('KernelSpecs::InstanceClass') }.should raise_error(TypeError) - lambda { @o.instance_of?(1) }.should raise_error(TypeError) + -> { @o.instance_of?(Object.new) }.should raise_error(TypeError) + -> { @o.instance_of?('KernelSpecs::InstanceClass') }.should raise_error(TypeError) + -> { @o.instance_of?(1) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/kernel/instance_variable_defined_spec.rb b/spec/ruby/core/kernel/instance_variable_defined_spec.rb index 99f5e90b4d..2ebb582b43 100644 --- a/spec/ruby/core/kernel/instance_variable_defined_spec.rb +++ b/spec/ruby/core/kernel/instance_variable_defined_spec.rb @@ -27,7 +27,7 @@ describe "Kernel#instance_variable_defined?" do end it "raises a TypeError if passed an Object not defining #to_str" do - lambda do + -> do obj = mock("kernel instance_variable_defined?") @instance.instance_variable_defined? obj end.should raise_error(TypeError) diff --git a/spec/ruby/core/kernel/instance_variable_get_spec.rb b/spec/ruby/core/kernel/instance_variable_get_spec.rb index 918abd8f5c..84d3188f07 100644 --- a/spec/ruby/core/kernel/instance_variable_get_spec.rb +++ b/spec/ruby/core/kernel/instance_variable_get_spec.rb @@ -24,25 +24,25 @@ describe "Kernel#instance_variable_get" do end it "raises a TypeError when the passed argument does not respond to #to_str" do - lambda { @obj.instance_variable_get(Object.new) }.should raise_error(TypeError) + -> { @obj.instance_variable_get(Object.new) }.should raise_error(TypeError) end it "raises a TypeError when the passed argument can't be converted to a String" do obj = mock("to_str") obj.stub!(:to_str).and_return(123) - lambda { @obj.instance_variable_get(obj) }.should raise_error(TypeError) + -> { @obj.instance_variable_get(obj) }.should raise_error(TypeError) end it "raises a NameError when the conversion result does not start with an '@'" do obj = mock("to_str") obj.stub!(:to_str).and_return("test") - lambda { @obj.instance_variable_get(obj) }.should raise_error(NameError) + -> { @obj.instance_variable_get(obj) }.should raise_error(NameError) end it "raises a NameError when passed just '@'" do obj = mock("to_str") obj.stub!(:to_str).and_return('@') - lambda { @obj.instance_variable_get(obj) }.should raise_error(NameError) + -> { @obj.instance_variable_get(obj) }.should raise_error(NameError) end end @@ -57,15 +57,15 @@ describe "Kernel#instance_variable_get when passed Symbol" do end it "raises a NameError when passed :@ as an instance variable name" do - lambda { @obj.instance_variable_get(:"@") }.should raise_error(NameError) + -> { @obj.instance_variable_get(:"@") }.should raise_error(NameError) end it "raises a NameError when the passed Symbol does not start with an '@'" do - lambda { @obj.instance_variable_get(:test) }.should raise_error(NameError) + -> { @obj.instance_variable_get(:test) }.should raise_error(NameError) end it "raises a NameError when the passed Symbol is an invalid instance variable name" do - lambda { @obj.instance_variable_get(:"@0") }.should raise_error(NameError) + -> { @obj.instance_variable_get(:"@0") }.should raise_error(NameError) end end @@ -80,15 +80,15 @@ describe "Kernel#instance_variable_get when passed String" do end it "raises a NameError when the passed String does not start with an '@'" do - lambda { @obj.instance_variable_get("test") }.should raise_error(NameError) + -> { @obj.instance_variable_get("test") }.should raise_error(NameError) end it "raises a NameError when the passed String is an invalid instance variable name" do - lambda { @obj.instance_variable_get("@0") }.should raise_error(NameError) + -> { @obj.instance_variable_get("@0") }.should raise_error(NameError) end it "raises a NameError when passed '@' as an instance variable name" do - lambda { @obj.instance_variable_get("@") }.should raise_error(NameError) + -> { @obj.instance_variable_get("@") }.should raise_error(NameError) end end @@ -99,7 +99,7 @@ describe "Kernel#instance_variable_get when passed Fixnum" do end it "raises a TypeError" do - lambda { @obj.instance_variable_get(10) }.should raise_error(TypeError) - lambda { @obj.instance_variable_get(-10) }.should raise_error(TypeError) + -> { @obj.instance_variable_get(10) }.should raise_error(TypeError) + -> { @obj.instance_variable_get(-10) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/kernel/instance_variable_set_spec.rb b/spec/ruby/core/kernel/instance_variable_set_spec.rb index 6d84015f50..c5a4085530 100644 --- a/spec/ruby/core/kernel/instance_variable_set_spec.rb +++ b/spec/ruby/core/kernel/instance_variable_set_spec.rb @@ -18,26 +18,26 @@ describe "Kernel#instance_variable_set" do it "raises a NameError exception if the argument is not of form '@x'" do no_dog = Class.new - lambda { no_dog.new.instance_variable_set(:c, "cat") }.should raise_error(NameError) + -> { no_dog.new.instance_variable_set(:c, "cat") }.should raise_error(NameError) end it "raises a NameError exception if the argument is an invalid instance variable name" do digit_dog = Class.new - lambda { digit_dog.new.instance_variable_set(:"@0", "cat") }.should raise_error(NameError) + -> { digit_dog.new.instance_variable_set(:"@0", "cat") }.should raise_error(NameError) end it "raises a NameError when the argument is '@'" do dog_at = Class.new - lambda { dog_at.new.instance_variable_set(:"@", "cat") }.should raise_error(NameError) + -> { dog_at.new.instance_variable_set(:"@", "cat") }.should raise_error(NameError) end it "raises a TypeError if the instance variable name is a Fixnum" do - lambda { "".instance_variable_set(1, 2) }.should raise_error(TypeError) + -> { "".instance_variable_set(1, 2) }.should raise_error(TypeError) end it "raises a TypeError if the instance variable name is an object that does not respond to to_str" do class KernelSpecs::A; end - lambda { "".instance_variable_set(KernelSpecs::A.new, 3) }.should raise_error(TypeError) + -> { "".instance_variable_set(KernelSpecs::A.new, 3) }.should raise_error(TypeError) end it "raises a NameError if the passed object, when coerced with to_str, does not start with @" do @@ -46,11 +46,11 @@ describe "Kernel#instance_variable_set" do ":c" end end - lambda { "".instance_variable_set(KernelSpecs::B.new, 4) }.should raise_error(NameError) + -> { "".instance_variable_set(KernelSpecs::B.new, 4) }.should raise_error(NameError) end it "raises a NameError if pass an object that cannot be a symbol" do - lambda { "".instance_variable_set(:c, 1) }.should raise_error(NameError) + -> { "".instance_variable_set(:c, 1) }.should raise_error(NameError) end it "accepts as instance variable name any instance of a class that responds to to_str" do @@ -78,16 +78,16 @@ describe "Kernel#instance_variable_set" do end it "keeps stored object after any exceptions" do - lambda { @frozen.instance_variable_set(:@ivar, :replacement) }.should raise_error(Exception) + -> { @frozen.instance_variable_set(:@ivar, :replacement) }.should raise_error(Exception) @frozen.ivar.should equal(:origin) end it "raises a #{frozen_error_class} when passed replacement is identical to stored object" do - lambda { @frozen.instance_variable_set(:@ivar, :origin) }.should raise_error(frozen_error_class) + -> { @frozen.instance_variable_set(:@ivar, :origin) }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} when passed replacement is different from stored object" do - lambda { @frozen.instance_variable_set(:@ivar, :replacement) }.should raise_error(frozen_error_class) + -> { @frozen.instance_variable_set(:@ivar, :replacement) }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/kernel/instance_variables_spec.rb b/spec/ruby/core/kernel/instance_variables_spec.rb index bf17b88c2f..b6d6e27772 100644 --- a/spec/ruby/core/kernel/instance_variables_spec.rb +++ b/spec/ruby/core/kernel/instance_variables_spec.rb @@ -9,7 +9,7 @@ describe "Kernel#instance_variables" do it "returns the correct array if an instance variable is added" do a = 0 - lambda{ a.instance_variable_set("@test", 1) }.should raise_error(RuntimeError) + ->{ a.instance_variable_set("@test", 1) }.should raise_error(RuntimeError) end end diff --git a/spec/ruby/core/kernel/loop_spec.rb b/spec/ruby/core/kernel/loop_spec.rb index 3386326a13..7c76c7d28e 100644 --- a/spec/ruby/core/kernel/loop_spec.rb +++ b/spec/ruby/core/kernel/loop_spec.rb @@ -55,7 +55,7 @@ describe "Kernel.loop" do end it "does not rescue other errors" do - lambda{ loop do raise StandardError end }.should raise_error( StandardError ) + ->{ loop do raise StandardError end }.should raise_error( StandardError ) end it "returns StopIteration#result, the result value of a finished iterator" do diff --git a/spec/ruby/core/kernel/open_spec.rb b/spec/ruby/core/kernel/open_spec.rb index 3a9f5ea2d5..981b5291b3 100644 --- a/spec/ruby/core/kernel/open_spec.rb +++ b/spec/ruby/core/kernel/open_spec.rb @@ -70,7 +70,7 @@ describe "Kernel#open" do end it "raises an ArgumentError if not passed one argument" do - lambda { open }.should raise_error(ArgumentError) + -> { open }.should raise_error(ArgumentError) end describe "when given an object that responds to to_open" do @@ -129,9 +129,9 @@ describe "Kernel#open" do it "raises a TypeError if passed a non-String that does not respond to #to_open" do obj = mock('non-fileish') - lambda { open(obj) }.should raise_error(TypeError) - lambda { open(nil) }.should raise_error(TypeError) - lambda { open(7) }.should raise_error(TypeError) + -> { open(obj) }.should raise_error(TypeError) + -> { open(nil) }.should raise_error(TypeError) + -> { open(7) }.should raise_error(TypeError) end it "accepts nil for mode and permission" do diff --git a/spec/ruby/core/kernel/p_spec.rb b/spec/ruby/core/kernel/p_spec.rb index 1221465243..798bd47b34 100644 --- a/spec/ruby/core/kernel/p_spec.rb +++ b/spec/ruby/core/kernel/p_spec.rb @@ -42,10 +42,10 @@ describe "Kernel#p" do o = mock("Inspector Gadget") o.should_receive(:inspect).any_number_of_times.and_return "Next time, Gadget, NEXT TIME!" - lambda { p(o) }.should output("Next time, Gadget, NEXT TIME!\n") - lambda { p(*[o]) }.should output("Next time, Gadget, NEXT TIME!\n") - lambda { p(*[o, o]) }.should output("Next time, Gadget, NEXT TIME!\nNext time, Gadget, NEXT TIME!\n") - lambda { p([o])}.should output("[#{o.inspect}]\n") + -> { p(o) }.should output("Next time, Gadget, NEXT TIME!\n") + -> { p(*[o]) }.should output("Next time, Gadget, NEXT TIME!\n") + -> { p(*[o, o]) }.should output("Next time, Gadget, NEXT TIME!\nNext time, Gadget, NEXT TIME!\n") + -> { p([o])}.should output("[#{o.inspect}]\n") end it "is not affected by setting $\\, $/ or $," do @@ -55,21 +55,21 @@ describe "Kernel#p" do suppress_warning { $, = " *helicopter sound*\n" } - lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n") + -> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n") $\ = " *helicopter sound*\n" - lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n") + -> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n") $/ = " *helicopter sound*\n" - lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n") + -> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n") end it "prints nothing if no argument is given" do - lambda { p }.should output("") + -> { p }.should output("") end it "prints nothing if called splatting an empty Array" do - lambda { p(*[]) }.should output("") + -> { p(*[]) }.should output("") end =begin Not sure how to spec this, but wanted to note the behavior here diff --git a/spec/ruby/core/kernel/printf_spec.rb b/spec/ruby/core/kernel/printf_spec.rb index ca88082694..5d68c0a13c 100644 --- a/spec/ruby/core/kernel/printf_spec.rb +++ b/spec/ruby/core/kernel/printf_spec.rb @@ -36,7 +36,7 @@ describe "Kernel.printf" do describe "formatting" do context "io is specified" do - it_behaves_like :kernel_sprintf, -> (format, *args) { + it_behaves_like :kernel_sprintf, -> format, *args { io = StringIO.new printf(io, format, *args) io.string @@ -44,7 +44,7 @@ describe "Kernel.printf" do end context "io is not specified" do - it_behaves_like :kernel_sprintf, -> (format, *args) { + it_behaves_like :kernel_sprintf, -> format, *args { stdout = $stdout begin diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb index e3acfa8dfd..ded2cec3fd 100644 --- a/spec/ruby/core/kernel/proc_spec.rb +++ b/spec/ruby/core/kernel/proc_spec.rb @@ -15,7 +15,7 @@ describe "Kernel.proc" do end it "returned the passed Proc if given an existing Proc" do - some_lambda = lambda {} + some_lambda = -> {} some_lambda.lambda?.should be_true l = proc(&some_lambda) l.should equal(some_lambda) diff --git a/spec/ruby/core/kernel/public_method_spec.rb b/spec/ruby/core/kernel/public_method_spec.rb index 72d0c62720..c5d54c777e 100644 --- a/spec/ruby/core/kernel/public_method_spec.rb +++ b/spec/ruby/core/kernel/public_method_spec.rb @@ -11,21 +11,21 @@ describe "Kernel#public_method" do it "raises a NameError when called on a private method" do @obj.send(:private_method).should == :private_method - lambda do + -> do @obj.public_method(:private_method) end.should raise_error(NameError) end it "raises a NameError when called on a protected method" do @obj.send(:protected_method).should == :protected_method - lambda { + -> { @obj.public_method(:protected_method) }.should raise_error(NameError) end it "raises a NameError if we only repond_to_missing? method, true" do obj = KernelSpecs::RespondViaMissing.new - lambda do + -> do obj.public_method(:handled_privately) end.should raise_error(NameError) end diff --git a/spec/ruby/core/kernel/public_send_spec.rb b/spec/ruby/core/kernel/public_send_spec.rb index 984ab41802..6b942a2e4b 100644 --- a/spec/ruby/core/kernel/public_send_spec.rb +++ b/spec/ruby/core/kernel/public_send_spec.rb @@ -29,7 +29,7 @@ describe "Kernel#public_send" do 'done' end end - lambda { KernelSpecs::Foo.new.public_send(:bar)}.should raise_error(NoMethodError) + -> { KernelSpecs::Foo.new.public_send(:bar)}.should raise_error(NoMethodError) end it "raises a NoMethodError if the named method is private" do @@ -39,7 +39,7 @@ describe "Kernel#public_send" do 'done2' end end - lambda { + -> { KernelSpecs::Foo.new.public_send(:bar) }.should raise_error(NoMethodError) end @@ -70,11 +70,11 @@ describe "Kernel#public_send" do end it "raises a NoMethodError if the method is protected" do - lambda { @receiver.call_protected_method }.should raise_error(NoMethodError) + -> { @receiver.call_protected_method }.should raise_error(NoMethodError) end it "raises a NoMethodError if the method is private" do - lambda { @receiver.call_private_method }.should raise_error(NoMethodError) + -> { @receiver.call_private_method }.should raise_error(NoMethodError) end end @@ -86,7 +86,7 @@ describe "Kernel#public_send" do end alias :aka :bar end - lambda { + -> { KernelSpecs::Foo.new.public_send(:aka) }.should raise_error(NoMethodError) end @@ -99,7 +99,7 @@ describe "Kernel#public_send" do end alias :aka :bar end - lambda { + -> { KernelSpecs::Foo.new.public_send(:aka) }.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/kernel/rand_spec.rb b/spec/ruby/core/kernel/rand_spec.rb index bdf5842f1a..843b5d10a2 100644 --- a/spec/ruby/core/kernel/rand_spec.rb +++ b/spec/ruby/core/kernel/rand_spec.rb @@ -132,6 +132,12 @@ describe "Kernel.rand" do it "returns the range start/end when Integer range is 0" do rand(42..42).should eql(42) end + + it "supports custom object types" do + rand(KernelSpecs::CustomRangeInteger.new(1)..KernelSpecs::CustomRangeInteger.new(42)).should be_an_instance_of(KernelSpecs::CustomRangeInteger) + rand(KernelSpecs::CustomRangeFloat.new(1.0)..KernelSpecs::CustomRangeFloat.new(42.0)).should be_an_instance_of(KernelSpecs::CustomRangeFloat) + rand(Time.now..Time.now).should be_an_instance_of(Time) + end end describe "Kernel#rand" do diff --git a/spec/ruby/core/kernel/remove_instance_variable_spec.rb b/spec/ruby/core/kernel/remove_instance_variable_spec.rb index 5022a70c1d..e90efc8aed 100644 --- a/spec/ruby/core/kernel/remove_instance_variable_spec.rb +++ b/spec/ruby/core/kernel/remove_instance_variable_spec.rb @@ -23,19 +23,19 @@ describe "Kernel#remove_instance_variable" do end it "raises a NameError if the instance variable is not defined" do - lambda do + -> do @instance.send :remove_instance_variable, :@unknown end.should raise_error(NameError) end it "raises a NameError if the argument is not a valid instance variable name" do - lambda do + -> do @instance.send :remove_instance_variable, :"@0" end.should raise_error(NameError) end it "raises a TypeError if passed an Object not defining #to_str" do - lambda do + -> do obj = mock("kernel remove_instance_variable") @instance.send :remove_instance_variable, obj end.should raise_error(TypeError) diff --git a/spec/ruby/core/kernel/require_relative_spec.rb b/spec/ruby/core/kernel/require_relative_spec.rb index 6604d30ab1..b292a46c63 100644 --- a/spec/ruby/core/kernel/require_relative_spec.rb +++ b/spec/ruby/core/kernel/require_relative_spec.rb @@ -86,18 +86,18 @@ describe "Kernel#require_relative with a relative path" do end it "raises a LoadError if the file does not exist" do - lambda { require_relative("#{@dir}/nonexistent.rb") }.should raise_error(LoadError) + -> { require_relative("#{@dir}/nonexistent.rb") }.should raise_error(LoadError) ScratchPad.recorded.should == [] end it "raises a LoadError if basepath does not exist" do - lambda { eval("require_relative('#{@dir}/nonexistent.rb')") }.should raise_error(LoadError) + -> { eval("require_relative('#{@dir}/nonexistent.rb')") }.should raise_error(LoadError) end it "stores the missing path in a LoadError object" do path = "#{@dir}/nonexistent.rb" - lambda { + -> { require_relative(path) }.should(raise_error(LoadError) { |e| e.path.should == File.expand_path(path, @abs_dir) @@ -112,9 +112,9 @@ describe "Kernel#require_relative with a relative path" do end it "raises a TypeError if argument does not respond to #to_str" do - lambda { require_relative(nil) }.should raise_error(TypeError) - lambda { require_relative(42) }.should raise_error(TypeError) - lambda { + -> { require_relative(nil) }.should raise_error(TypeError) + -> { require_relative(42) }.should raise_error(TypeError) + -> { require_relative([@path,@path]) }.should raise_error(TypeError) end @@ -122,13 +122,13 @@ describe "Kernel#require_relative with a relative path" do it "raises a TypeError if passed an object that has #to_s but not #to_str" do name = mock("load_fixture.rb mock") name.stub!(:to_s).and_return(@path) - lambda { require_relative(name) }.should raise_error(TypeError) + -> { require_relative(name) }.should raise_error(TypeError) end it "raises a TypeError if #to_str does not return a String" do name = mock("#to_str returns nil") name.should_receive(:to_str).at_least(1).times.and_return(nil) - lambda { require_relative(name) }.should raise_error(TypeError) + -> { require_relative(name) }.should raise_error(TypeError) end it "calls #to_path on non-String objects" do @@ -239,7 +239,7 @@ describe "Kernel#require_relative with a relative path" do it "does not store the path if the load fails" do saved_loaded_features = $LOADED_FEATURES.dup - lambda { require_relative("#{@dir}/raise_fixture.rb") }.should raise_error(RuntimeError) + -> { require_relative("#{@dir}/raise_fixture.rb") }.should raise_error(RuntimeError) $LOADED_FEATURES.should == saved_loaded_features end @@ -288,18 +288,18 @@ describe "Kernel#require_relative with an absolute path" do end it "raises a LoadError if the file does not exist" do - lambda { require_relative("#{@dir}/nonexistent.rb") }.should raise_error(LoadError) + -> { require_relative("#{@dir}/nonexistent.rb") }.should raise_error(LoadError) ScratchPad.recorded.should == [] end it "raises a LoadError if basepath does not exist" do - lambda { eval("require_relative('#{@dir}/nonexistent.rb')") }.should raise_error(LoadError) + -> { eval("require_relative('#{@dir}/nonexistent.rb')") }.should raise_error(LoadError) end it "stores the missing path in a LoadError object" do path = "#{@dir}/nonexistent.rb" - lambda { + -> { require_relative(path) }.should(raise_error(LoadError) { |e| e.path.should == File.expand_path(path, @abs_dir) @@ -314,9 +314,9 @@ describe "Kernel#require_relative with an absolute path" do end it "raises a TypeError if argument does not respond to #to_str" do - lambda { require_relative(nil) }.should raise_error(TypeError) - lambda { require_relative(42) }.should raise_error(TypeError) - lambda { + -> { require_relative(nil) }.should raise_error(TypeError) + -> { require_relative(42) }.should raise_error(TypeError) + -> { require_relative([@path,@path]) }.should raise_error(TypeError) end @@ -324,13 +324,13 @@ describe "Kernel#require_relative with an absolute path" do it "raises a TypeError if passed an object that has #to_s but not #to_str" do name = mock("load_fixture.rb mock") name.stub!(:to_s).and_return(@path) - lambda { require_relative(name) }.should raise_error(TypeError) + -> { require_relative(name) }.should raise_error(TypeError) end it "raises a TypeError if #to_str does not return a String" do name = mock("#to_str returns nil") name.should_receive(:to_str).at_least(1).times.and_return(nil) - lambda { require_relative(name) }.should raise_error(TypeError) + -> { require_relative(name) }.should raise_error(TypeError) end it "calls #to_path on non-String objects" do @@ -401,7 +401,7 @@ describe "Kernel#require_relative with an absolute path" do it "does not store the path if the load fails" do saved_loaded_features = $LOADED_FEATURES.dup - lambda { require_relative("#{@dir}/raise_fixture.rb") }.should raise_error(RuntimeError) + -> { require_relative("#{@dir}/raise_fixture.rb") }.should raise_error(RuntimeError) $LOADED_FEATURES.should == saved_loaded_features end diff --git a/spec/ruby/core/kernel/respond_to_spec.rb b/spec/ruby/core/kernel/respond_to_spec.rb index 80487421d7..e7efc9f275 100644 --- a/spec/ruby/core/kernel/respond_to_spec.rb +++ b/spec/ruby/core/kernel/respond_to_spec.rb @@ -25,7 +25,7 @@ describe "Kernel#respond_to?" do end it "throws a type error if argument can't be coerced into a Symbol" do - lambda { @a.respond_to?(Object.new) }.should raise_error(TypeError) + -> { @a.respond_to?(Object.new) }.should raise_error(TypeError) end it "returns false if obj responds to the given protected method" do @@ -61,7 +61,7 @@ describe "Kernel#respond_to?" do it "does not change method visibility when finding private method" do KernelSpecs::VisibilityChange.respond_to?(:new, false).should == false KernelSpecs::VisibilityChange.respond_to?(:new, true).should == true - lambda { KernelSpecs::VisibilityChange.new }.should raise_error(NoMethodError) + -> { KernelSpecs::VisibilityChange.new }.should raise_error(NoMethodError) end it "indicates if an object responds to a particular message" do diff --git a/spec/ruby/core/kernel/shared/dup_clone.rb b/spec/ruby/core/kernel/shared/dup_clone.rb index 37890f2981..d1ee64bd09 100644 --- a/spec/ruby/core/kernel/shared/dup_clone.rb +++ b/spec/ruby/core/kernel/shared/dup_clone.rb @@ -102,12 +102,12 @@ describe :kernel_dup_clone, shared: true do ruby_version_is ''...'2.5' do it "raises a TypeError for Complex" do c = Complex(1.3, 3.1) - lambda { c.send(@method) }.should raise_error(TypeError) + -> { c.send(@method) }.should raise_error(TypeError) end it "raises a TypeError for Rational" do r = Rational(1, 3) - lambda { r.send(@method) }.should raise_error(TypeError) + -> { r.send(@method) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/kernel/shared/kind_of.rb b/spec/ruby/core/kernel/shared/kind_of.rb index 0614c02214..aef6f1c1d8 100644 --- a/spec/ruby/core/kernel/shared/kind_of.rb +++ b/spec/ruby/core/kernel/shared/kind_of.rb @@ -40,10 +40,10 @@ describe :kernel_kind_of, shared: true do end it "raises a TypeError if given an object that is not a Class nor a Module" do - lambda { @o.send(@method, 1) }.should raise_error(TypeError) - lambda { @o.send(@method, 'KindaClass') }.should raise_error(TypeError) - lambda { @o.send(@method, :KindaClass) }.should raise_error(TypeError) - lambda { @o.send(@method, Object.new) }.should raise_error(TypeError) + -> { @o.send(@method, 1) }.should raise_error(TypeError) + -> { @o.send(@method, 'KindaClass') }.should raise_error(TypeError) + -> { @o.send(@method, :KindaClass) }.should raise_error(TypeError) + -> { @o.send(@method, Object.new) }.should raise_error(TypeError) end it "does not take into account `class` method overriding" do diff --git a/spec/ruby/core/kernel/shared/lambda.rb b/spec/ruby/core/kernel/shared/lambda.rb index bebb111c43..c7180e1442 100644 --- a/spec/ruby/core/kernel/shared/lambda.rb +++ b/spec/ruby/core/kernel/shared/lambda.rb @@ -4,6 +4,6 @@ describe :kernel_lambda, shared: true do end it "raises an ArgumentError when no block is given" do - lambda { send(@method) }.should raise_error(ArgumentError) + -> { send(@method) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/kernel/shared/load.rb b/spec/ruby/core/kernel/shared/load.rb index b479b29399..14bf5f27da 100644 --- a/spec/ruby/core/kernel/shared/load.rb +++ b/spec/ruby/core/kernel/shared/load.rb @@ -81,7 +81,7 @@ describe :kernel_load, shared: true do it "raises a LoadError if passed a non-extensioned path that does not exist but a .rb extensioned path does exist" do path = File.expand_path "load_ext_fixture", CODE_LOADING_DIR - lambda { @object.load(path) }.should raise_error(LoadError) + -> { @object.load(path) }.should raise_error(LoadError) end describe "when passed true for 'wrap'" do @@ -115,7 +115,7 @@ describe :kernel_load, shared: true do end it "does not pollute the receiver" do - lambda { @object.send(:top_level_method) }.should raise_error(NameError) + -> { @object.send(:top_level_method) }.should raise_error(NameError) end end end diff --git a/spec/ruby/core/kernel/shared/method.rb b/spec/ruby/core/kernel/shared/method.rb index 006ebbffb8..3418966b1b 100644 --- a/spec/ruby/core/kernel/shared/method.rb +++ b/spec/ruby/core/kernel/shared/method.rb @@ -23,14 +23,14 @@ describe :kernel_method, shared: true do it "raises a NameError for an invalid method name" do class KernelSpecs::Foo; def bar; 'done'; end; end - lambda { + -> { KernelSpecs::Foo.new.send(@method, :invalid_and_silly_method_name) }.should raise_error(NameError) end it "raises a NameError for an invalid singleton method name" do class KernelSpecs::Foo; def self.bar; 'done'; end; end - lambda { KernelSpecs::Foo.send(@method, :baz) }.should raise_error(NameError) + -> { KernelSpecs::Foo.send(@method, :baz) }.should raise_error(NameError) end it "changes the method called for super on a target aliased method" do diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb index 56377684fb..af0d50db4f 100644 --- a/spec/ruby/core/kernel/shared/require.rb +++ b/spec/ruby/core/kernel/shared/require.rb @@ -21,7 +21,7 @@ describe :kernel_require_basic, shared: true do it "raises a LoadError if the file does not exist" do path = File.expand_path "nonexistent.rb", CODE_LOADING_DIR File.exist?(path).should be_false - lambda { @object.send(@method, path) }.should raise_error(LoadError) + -> { @object.send(@method, path) }.should raise_error(LoadError) ScratchPad.recorded.should == [] end @@ -42,7 +42,7 @@ describe :kernel_require_basic, shared: true do it "raises a LoadError" do File.exist?(@path).should be_true - lambda { @object.send(@method, @path) }.should raise_error(LoadError) + -> { @object.send(@method, @path) }.should raise_error(LoadError) end end end @@ -57,19 +57,19 @@ describe :kernel_require_basic, shared: true do end it "raises a TypeError if passed nil" do - lambda { @object.send(@method, nil) }.should raise_error(TypeError) + -> { @object.send(@method, nil) }.should raise_error(TypeError) end it "raises a TypeError if passed a Fixnum" do - lambda { @object.send(@method, 42) }.should raise_error(TypeError) + -> { @object.send(@method, 42) }.should raise_error(TypeError) end it "raises a TypeError if passed an Array" do - lambda { @object.send(@method, []) }.should raise_error(TypeError) + -> { @object.send(@method, []) }.should raise_error(TypeError) end it "raises a TypeError if passed an object that does not provide #to_str" do - lambda { @object.send(@method, mock("not a filename")) }.should raise_error(TypeError) + -> { @object.send(@method, mock("not a filename")) }.should raise_error(TypeError) end it "raises a TypeError if passed an object that has #to_s but not #to_str" do @@ -77,14 +77,14 @@ describe :kernel_require_basic, shared: true do name.stub!(:to_s).and_return("load_fixture.rb") $LOAD_PATH << "." Dir.chdir CODE_LOADING_DIR do - lambda { @object.send(@method, name) }.should raise_error(TypeError) + -> { @object.send(@method, name) }.should raise_error(TypeError) end end it "raises a TypeError if #to_str does not return a String" do name = mock("#to_str returns nil") name.should_receive(:to_str).at_least(1).times.and_return(nil) - lambda { @object.send(@method, name) }.should raise_error(TypeError) + -> { @object.send(@method, name) }.should raise_error(TypeError) end it "calls #to_path on non-String objects" do @@ -170,7 +170,7 @@ describe :kernel_require_basic, shared: true do it "does not resolve a ./ relative path against $LOAD_PATH entries" do $LOAD_PATH << CODE_LOADING_DIR - lambda do + -> do @object.send(@method, "./load_fixture.rb") end.should raise_error(LoadError) ScratchPad.recorded.should == [] @@ -178,7 +178,7 @@ describe :kernel_require_basic, shared: true do it "does not resolve a ../ relative path against $LOAD_PATH entries" do $LOAD_PATH << CODE_LOADING_DIR - lambda do + -> do @object.send(@method, "../code/load_fixture.rb") end.should raise_error(LoadError) ScratchPad.recorded.should == [] @@ -208,14 +208,14 @@ describe :kernel_require, shared: true do # intentional for security reasons. it "does not load a bare filename unless the current working directory is in $LOAD_PATH" do Dir.chdir CODE_LOADING_DIR do - lambda { @object.require("load_fixture.rb") }.should raise_error(LoadError) + -> { @object.require("load_fixture.rb") }.should raise_error(LoadError) ScratchPad.recorded.should == [] end end it "does not load a relative path unless the current working directory is in $LOAD_PATH" do Dir.chdir File.dirname(CODE_LOADING_DIR) do - lambda do + -> do @object.require("code/load_fixture.rb") end.should raise_error(LoadError) ScratchPad.recorded.should == [] @@ -381,7 +381,7 @@ describe :kernel_require, shared: true do it "does not store the path if the load fails" do $LOAD_PATH << CODE_LOADING_DIR saved_loaded_features = $LOADED_FEATURES.dup - lambda { @object.require("raise_fixture.rb") }.should raise_error(RuntimeError) + -> { @object.require("raise_fixture.rb") }.should raise_error(RuntimeError) $LOADED_FEATURES.should == saved_loaded_features end @@ -683,7 +683,7 @@ describe :kernel_require, shared: true do Thread.current[:wait_for] = t2 Thread.current[:con_raise] = true - lambda { + -> { @object.require(@path) }.should raise_error(RuntimeError) @@ -724,7 +724,7 @@ describe :kernel_require, shared: true do t1 = Thread.new do Thread.current[:con_raise] = true - lambda { + -> { @object.require(@path) }.should raise_error(RuntimeError) @@ -764,7 +764,7 @@ describe :kernel_require, shared: true do it "stores the missing path in a LoadError object" do path = "abcd1234" - lambda { + -> { @object.send(@method, path) }.should raise_error(LoadError) { |e| e.path.should == path diff --git a/spec/ruby/core/kernel/shared/sprintf.rb b/spec/ruby/core/kernel/shared/sprintf.rb index 925c79e82b..9899684284 100644 --- a/spec/ruby/core/kernel/shared/sprintf.rb +++ b/spec/ruby/core/kernel/shared/sprintf.rb @@ -31,7 +31,7 @@ describe :kernel_sprintf, shared: true do end it "raises TypeError exception if cannot convert to Integer" do - -> () { + -> { format("%b", Object.new) }.should raise_error(TypeError) end @@ -120,7 +120,7 @@ describe :kernel_sprintf, shared: true do end it "raises TypeError exception if cannot convert to Float" do - -> () { + -> { format("%f", Object.new) }.should raise_error(TypeError) end @@ -296,13 +296,13 @@ describe :kernel_sprintf, shared: true do end it "raises ArgumentError if argument is a string of several characters" do - -> () { + -> { format("%c", "abc") }.should raise_error(ArgumentError) end it "raises ArgumentError if argument is an empty string" do - -> () { + -> { format("%c", "") }.should raise_error(ArgumentError) end @@ -338,7 +338,7 @@ describe :kernel_sprintf, shared: true do "abc" end - -> () { + -> { format("%s", obj) }.should raise_error(NoMethodError) end @@ -461,7 +461,7 @@ describe :kernel_sprintf, shared: true do end it "raises exception if argument number is bigger than actual arguments list" do - -> () { + -> { format("%4$d", 1, 2, 3) }.should raise_error(ArgumentError) end @@ -472,7 +472,7 @@ describe :kernel_sprintf, shared: true do end it "raises ArgumentError exception when absolute and relative argument numbers are mixed" do - -> () { + -> { format("%1$d %d", 1, 2) }.should raise_error(ArgumentError) end @@ -722,7 +722,7 @@ describe :kernel_sprintf, shared: true do end it "raises ArgumentError when is mixed with width" do - -> () { + -> { format("%*10d", 10, 112) }.should raise_error(ArgumentError) end @@ -821,7 +821,7 @@ describe :kernel_sprintf, shared: true do end it "cannot be mixed with unnamed style" do - -> () { + -> { format("%d %<foo>d", 1, foo: "123") }.should raise_error(ArgumentError) end @@ -841,13 +841,13 @@ describe :kernel_sprintf, shared: true do end it "cannot be mixed with unnamed style" do - -> () { + -> { format("%d %{foo}", 1, foo: "123") }.should raise_error(ArgumentError) end it "raises KeyError when there is no matching key" do - -> () { + -> { format("%{foo}", {}) }.should raise_error(KeyError) end @@ -870,7 +870,7 @@ describe :kernel_sprintf, shared: true do @base_method = @method end - it_behaves_like :key_error, -> (obj, key) { + it_behaves_like :key_error, -> obj, key { @base_method.call("%<#{key}>s", obj) }, { foooo: 1 } end diff --git a/spec/ruby/core/kernel/shared/sprintf_encoding.rb b/spec/ruby/core/kernel/shared/sprintf_encoding.rb index a92f3c10cd..c3d62bf3bb 100644 --- a/spec/ruby/core/kernel/shared/sprintf_encoding.rb +++ b/spec/ruby/core/kernel/shared/sprintf_encoding.rb @@ -21,7 +21,7 @@ describe :kernel_sprintf_encoding, shared: true do string = "Ä %s".encode('windows-1252') argument = "Ђ".encode('windows-1251') - -> () { + -> { format(string, argument) }.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/core/kernel/singleton_class_spec.rb b/spec/ruby/core/kernel/singleton_class_spec.rb index b5e0703905..5dbb4f8c05 100644 --- a/spec/ruby/core/kernel/singleton_class_spec.rb +++ b/spec/ruby/core/kernel/singleton_class_spec.rb @@ -18,10 +18,10 @@ describe "Kernel#singleton_class" do end it "raises TypeError for Fixnum" do - lambda { 123.singleton_class }.should raise_error(TypeError) + -> { 123.singleton_class }.should raise_error(TypeError) end it "raises TypeError for Symbol" do - lambda { :foo.singleton_class }.should raise_error(TypeError) + -> { :foo.singleton_class }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/kernel/sleep_spec.rb b/spec/ruby/core/kernel/sleep_spec.rb index a510ae3dc1..387dc4787b 100644 --- a/spec/ruby/core/kernel/sleep_spec.rb +++ b/spec/ruby/core/kernel/sleep_spec.rb @@ -23,16 +23,16 @@ describe "Kernel#sleep" do end it "raises an ArgumentError when passed a negative duration" do - lambda { sleep(-0.1) }.should raise_error(ArgumentError) - lambda { sleep(-1) }.should raise_error(ArgumentError) + -> { sleep(-0.1) }.should raise_error(ArgumentError) + -> { sleep(-1) }.should raise_error(ArgumentError) end it "raises a TypeError when passed nil" do - lambda { sleep(nil) }.should raise_error(TypeError) + -> { sleep(nil) }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { sleep('2') }.should raise_error(TypeError) + -> { sleep('2') }.should raise_error(TypeError) end it "pauses execution indefinitely if not given a duration" do diff --git a/spec/ruby/core/kernel/spawn_spec.rb b/spec/ruby/core/kernel/spawn_spec.rb index da3cf39021..ba05b629d5 100644 --- a/spec/ruby/core/kernel/spawn_spec.rb +++ b/spec/ruby/core/kernel/spawn_spec.rb @@ -10,7 +10,7 @@ describe "Kernel#spawn" do end it "executes the given command" do - lambda { + -> { Process.wait spawn("echo spawn") }.should output_to_fd("spawn\n") end @@ -18,7 +18,7 @@ end describe "Kernel.spawn" do it "executes the given command" do - lambda { + -> { Process.wait Kernel.spawn("echo spawn") }.should output_to_fd("spawn\n") end diff --git a/spec/ruby/core/kernel/sprintf_spec.rb b/spec/ruby/core/kernel/sprintf_spec.rb index 4aa8c2351f..7adf71be76 100644 --- a/spec/ruby/core/kernel/sprintf_spec.rb +++ b/spec/ruby/core/kernel/sprintf_spec.rb @@ -4,21 +4,21 @@ require_relative 'shared/sprintf' require_relative 'shared/sprintf_encoding' describe "Kernel#sprintf" do - it_behaves_like :kernel_sprintf, -> (format, *args) { + it_behaves_like :kernel_sprintf, -> format, *args { sprintf(format, *args) } - it_behaves_like :kernel_sprintf_encoding, -> (format, *args) { + it_behaves_like :kernel_sprintf_encoding, -> format, *args { sprintf(format, *args) } end describe "Kernel.sprintf" do - it_behaves_like :kernel_sprintf, -> (format, *args) { + it_behaves_like :kernel_sprintf, -> format, *args { Kernel.sprintf(format, *args) } - it_behaves_like :kernel_sprintf_encoding, -> (format, *args) { + it_behaves_like :kernel_sprintf_encoding, -> format, *args { Kernel.sprintf(format, *args) } end diff --git a/spec/ruby/core/kernel/srand_spec.rb b/spec/ruby/core/kernel/srand_spec.rb index 053fb521ef..5454aae8cf 100644 --- a/spec/ruby/core/kernel/srand_spec.rb +++ b/spec/ruby/core/kernel/srand_spec.rb @@ -19,7 +19,7 @@ describe "Kernel.srand" do end it "defaults number to a random value" do - lambda { srand }.should_not raise_error + -> { srand }.should_not raise_error srand.should_not == 0 end @@ -48,11 +48,11 @@ describe "Kernel.srand" do end it "raises a TypeError when passed nil" do - lambda { srand(nil) }.should raise_error(TypeError) + -> { srand(nil) }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { srand("7") }.should raise_error(TypeError) + -> { srand("7") }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/kernel/system_spec.rb b/spec/ruby/core/kernel/system_spec.rb index 6a4ba6283d..96c0496dd6 100644 --- a/spec/ruby/core/kernel/system_spec.rb +++ b/spec/ruby/core/kernel/system_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/classes' describe :kernel_system, shared: true do it "executes the specified command in a subprocess" do - lambda { @object.system("echo a") }.should output_to_fd("a\n") + -> { @object.system("echo a") }.should output_to_fd("a\n") $?.should be_an_instance_of Process::Status $?.success?.should == true @@ -27,11 +27,11 @@ describe :kernel_system, shared: true do ruby_version_is "2.6" do it "raises RuntimeError when `exception: true` is given and the command exits with a non-zero exit status" do - lambda { @object.system(ruby_cmd('exit 1'), exception: true) }.should raise_error(RuntimeError) + -> { @object.system(ruby_cmd('exit 1'), exception: true) }.should raise_error(RuntimeError) end it "raises Errno::ENOENT when `exception: true` is given and the specified command does not exist" do - lambda { @object.system('feature_14386', exception: true) }.should raise_error(Errno::ENOENT) + -> { @object.system('feature_14386', exception: true) }.should raise_error(Errno::ENOENT) end end @@ -44,7 +44,7 @@ describe :kernel_system, shared: true do end it "does not write to stderr when command execution fails" do - lambda { @object.system("sad") }.should output_to_fd("", STDERR) + -> { @object.system("sad") }.should output_to_fd("", STDERR) end platform_is_not :windows do @@ -57,12 +57,12 @@ describe :kernel_system, shared: true do end it "executes with `sh` if the command contains shell characters" do - lambda { @object.system("echo $0") }.should output_to_fd("sh\n") + -> { @object.system("echo $0") }.should output_to_fd("sh\n") end it "ignores SHELL env var and always uses `sh`" do ENV['SHELL'] = "/bin/fakeshell" - lambda { @object.system("echo $0") }.should output_to_fd("sh\n") + -> { @object.system("echo $0") }.should output_to_fd("sh\n") end end @@ -79,19 +79,19 @@ describe :kernel_system, shared: true do end it "expands shell variables when given a single string argument" do - lambda { @object.system("echo #{@shell_var}") }.should output_to_fd("foo\n") + -> { @object.system("echo #{@shell_var}") }.should output_to_fd("foo\n") end platform_is_not :windows do it "does not expand shell variables when given multiples arguments" do - lambda { @object.system("echo", @shell_var) }.should output_to_fd("#{@shell_var}\n") + -> { @object.system("echo", @shell_var) }.should output_to_fd("#{@shell_var}\n") end end platform_is :windows do it "does expand shell variables when given multiples arguments" do # See https://bugs.ruby-lang.org/issues/12231 - lambda { @object.system("echo", @shell_var) }.should output_to_fd("foo\n") + -> { @object.system("echo", @shell_var) }.should output_to_fd("foo\n") end end diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb index ff1b20f9ca..000295f6d2 100644 --- a/spec/ruby/core/kernel/taint_spec.rb +++ b/spec/ruby/core/kernel/taint_spec.rb @@ -15,7 +15,7 @@ describe "Kernel#taint" do it "raises #{frozen_error_class} on an untainted, frozen object" do o = Object.new.freeze - lambda { o.taint }.should raise_error(frozen_error_class) + -> { o.taint }.should raise_error(frozen_error_class) end it "does not raise an error on a tainted, frozen object" do @@ -32,13 +32,13 @@ describe "Kernel#taint" do it "no raises a RuntimeError on symbols" do v = :sym - lambda { v.taint }.should_not raise_error(RuntimeError) + -> { v.taint }.should_not raise_error(RuntimeError) v.tainted?.should == false end it "no raises error on fixnum values" do [1].each do |v| - lambda { v.taint }.should_not raise_error(RuntimeError) + -> { v.taint }.should_not raise_error(RuntimeError) v.tainted?.should == false end end diff --git a/spec/ruby/core/kernel/tap_spec.rb b/spec/ruby/core/kernel/tap_spec.rb index a7d548847c..f7720a6dc7 100644 --- a/spec/ruby/core/kernel/tap_spec.rb +++ b/spec/ruby/core/kernel/tap_spec.rb @@ -8,6 +8,6 @@ describe "Kernel#tap" do end it "raises a LocalJumpError when no block given" do - lambda { 3.tap }.should raise_error(LocalJumpError) + -> { 3.tap }.should raise_error(LocalJumpError) end end diff --git a/spec/ruby/core/kernel/throw_spec.rb b/spec/ruby/core/kernel/throw_spec.rb index 1e56376529..64bfccb413 100644 --- a/spec/ruby/core/kernel/throw_spec.rb +++ b/spec/ruby/core/kernel/throw_spec.rb @@ -42,21 +42,21 @@ describe "Kernel.throw" do end it "raises an ArgumentError if there is no catch block for the symbol" do - lambda { throw :blah }.should raise_error(ArgumentError) + -> { throw :blah }.should raise_error(ArgumentError) end it "raises an UncaughtThrowError if there is no catch block for the symbol" do - lambda { throw :blah }.should raise_error(UncaughtThrowError) + -> { throw :blah }.should raise_error(UncaughtThrowError) end it "raises ArgumentError if 3 or more arguments provided" do - lambda { + -> { catch :blah do throw :blah, :return_value, 2 end }.should raise_error(ArgumentError) - lambda { + -> { catch :blah do throw :blah, :return_value, 2, 3, 4, 5 end @@ -64,7 +64,7 @@ describe "Kernel.throw" do end it "can throw an object" do - lambda { + -> { obj = Object.new catch obj do throw obj diff --git a/spec/ruby/core/kernel/trace_var_spec.rb b/spec/ruby/core/kernel/trace_var_spec.rb index 019902a230..3c84aa5e60 100644 --- a/spec/ruby/core/kernel/trace_var_spec.rb +++ b/spec/ruby/core/kernel/trace_var_spec.rb @@ -47,7 +47,7 @@ describe "Kernel#trace_var" do end it "raises ArgumentError if no block or proc is provided" do - lambda do + -> do trace_var :$Kernel_trace_var_global end.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb index c258c4fce7..d34aa293ec 100644 --- a/spec/ruby/core/kernel/trust_spec.rb +++ b/spec/ruby/core/kernel/trust_spec.rb @@ -15,7 +15,7 @@ describe "Kernel#trust" do it "raises #{frozen_error_class} on an untrusted, frozen object" do o = Object.new.untrust.freeze - lambda { o.trust }.should raise_error(frozen_error_class) + -> { o.trust }.should raise_error(frozen_error_class) end it "does not raise an error on a trusted, frozen object" do diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb index 73f7942124..94e4a8fd44 100644 --- a/spec/ruby/core/kernel/untaint_spec.rb +++ b/spec/ruby/core/kernel/untaint_spec.rb @@ -15,7 +15,7 @@ describe "Kernel#untaint" do it "raises #{frozen_error_class} on a tainted, frozen object" do o = Object.new.taint.freeze - lambda { o.untaint }.should raise_error(frozen_error_class) + -> { o.untaint }.should raise_error(frozen_error_class) end it "does not raise an error on an untainted, frozen object" do diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb index f70e4356ff..2ee3dbb170 100644 --- a/spec/ruby/core/kernel/untrust_spec.rb +++ b/spec/ruby/core/kernel/untrust_spec.rb @@ -15,7 +15,7 @@ describe "Kernel#untrust" do it "raises #{frozen_error_class} on a trusted, frozen object" do o = Object.new.freeze - lambda { o.untrust }.should raise_error(frozen_error_class) + -> { o.untrust }.should raise_error(frozen_error_class) end it "does not raise an error on an untrusted, frozen object" do diff --git a/spec/ruby/core/kernel/untrusted_spec.rb b/spec/ruby/core/kernel/untrusted_spec.rb index 55638a5dd3..3f894b0bab 100644 --- a/spec/ruby/core/kernel/untrusted_spec.rb +++ b/spec/ruby/core/kernel/untrusted_spec.rb @@ -23,6 +23,6 @@ describe "Kernel#untrusted?" do it "has effect on immediate values" do d = 1 - lambda { d.untrust }.should_not raise_error(RuntimeError) + -> { d.untrust }.should_not raise_error(RuntimeError) end end diff --git a/spec/ruby/core/kernel/warn_spec.rb b/spec/ruby/core/kernel/warn_spec.rb index 7e0a57fa9a..d05a37958d 100644 --- a/spec/ruby/core/kernel/warn_spec.rb +++ b/spec/ruby/core/kernel/warn_spec.rb @@ -21,56 +21,56 @@ describe "Kernel#warn" do end it "does not append line-end if last character is line-end" do - lambda { + -> { $VERBOSE = true warn("this is some simple text with line-end\n") }.should output(nil, "this is some simple text with line-end\n") end it "calls #write on $stderr if $VERBOSE is true" do - lambda { + -> { $VERBOSE = true warn("this is some simple text") }.should output(nil, "this is some simple text\n") end it "calls #write on $stderr if $VERBOSE is false" do - lambda { + -> { $VERBOSE = false warn("this is some simple text") }.should output(nil, "this is some simple text\n") end it "does not call #write on $stderr if $VERBOSE is nil" do - lambda { + -> { $VERBOSE = nil warn("this is some simple text") }.should output(nil, "") end it "writes each argument on a line when passed multiple arguments" do - lambda { + -> { $VERBOSE = true warn("line 1", "line 2") }.should output(nil, "line 1\nline 2\n") end it "writes each array element on a line when passes an array" do - lambda { + -> { $VERBOSE = true warn(["line 1", "line 2"]) }.should output(nil, "line 1\nline 2\n") end it "does not write strings when passed no arguments" do - lambda { + -> { $VERBOSE = true warn }.should output("", "") end it "writes the default record separator and NOT $/ to $stderr after the warning message" do - lambda { + -> { $VERBOSE = true $/ = 'rs' warn("") @@ -80,7 +80,7 @@ describe "Kernel#warn" do it "writes to_s representation if passed a non-string" do obj = mock("obj") obj.should_receive(:to_s).and_return("to_s called") - lambda { + -> { $VERBOSE = true warn(obj) }.should output(nil, "to_s called\n") diff --git a/spec/ruby/core/main/private_spec.rb b/spec/ruby/core/main/private_spec.rb index eef826ad81..e34e0c7b7b 100644 --- a/spec/ruby/core/main/private_spec.rb +++ b/spec/ruby/core/main/private_spec.rb @@ -16,7 +16,7 @@ describe "main#private" do end it "raises a NameError when given an undefined name" do - lambda do + -> do eval "private :main_undefined_method", TOPLEVEL_BINDING end.should raise_error(NameError) end diff --git a/spec/ruby/core/main/public_spec.rb b/spec/ruby/core/main/public_spec.rb index 259a8f9418..afe25c705a 100644 --- a/spec/ruby/core/main/public_spec.rb +++ b/spec/ruby/core/main/public_spec.rb @@ -16,7 +16,7 @@ describe "main#public" do end it "raises a NameError when given an undefined name" do - lambda do + -> do eval "public :main_undefined_method", TOPLEVEL_BINDING end.should raise_error(NameError) end diff --git a/spec/ruby/core/main/using_spec.rb b/spec/ruby/core/main/using_spec.rb index 1fb812f5cc..f9f709f7dc 100644 --- a/spec/ruby/core/main/using_spec.rb +++ b/spec/ruby/core/main/using_spec.rb @@ -3,11 +3,11 @@ require_relative 'fixtures/classes' describe "main.using" do it "requires one Module argument" do - lambda do + -> do eval('using', TOPLEVEL_BINDING) end.should raise_error(ArgumentError) - lambda do + -> do eval('using "foo"', TOPLEVEL_BINDING) end.should raise_error(TypeError) end @@ -17,7 +17,7 @@ describe "main.using" do load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__) MainSpecs::DATA[:in_module].should == 'foo' MainSpecs::DATA[:toplevel].should == 'foo' - lambda do + -> do 'hello'.foo end.should raise_error(NoMethodError) end @@ -25,7 +25,7 @@ describe "main.using" do it "uses refinements from the given module for method calls in the target file" do require_relative 'fixtures/string_refinement' load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__) - lambda do + -> do 'hello'.foo end.should raise_error(NoMethodError) MainSpecs.call_foo('hello').should == 'foo' diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb index 53a0b3197d..700f090a2f 100644 --- a/spec/ruby/core/marshal/dump_spec.rb +++ b/spec/ruby/core/marshal/dump_spec.rb @@ -99,7 +99,7 @@ describe "Marshal.dump" do it "raises a TypeError if _dump returns a non-string" do m = mock("marshaled") m.should_receive(:_dump).and_return(0) - lambda { Marshal.dump(m) }.should raise_error(TypeError) + -> { Marshal.dump(m) }.should raise_error(TypeError) end it "favors marshal_dump over _dump" do @@ -124,11 +124,11 @@ describe "Marshal.dump" do end it "raises TypeError with an anonymous Class" do - lambda { Marshal.dump(Class.new) }.should raise_error(TypeError) + -> { Marshal.dump(Class.new) }.should raise_error(TypeError) end it "raises TypeError with a singleton Class" do - lambda { Marshal.dump(class << self; self end) }.should raise_error(TypeError) + -> { Marshal.dump(class << self; self end) }.should raise_error(TypeError) end end @@ -138,7 +138,7 @@ describe "Marshal.dump" do end it "raises TypeError with an anonymous Module" do - lambda { Marshal.dump(Module.new) }.should raise_error(TypeError) + -> { Marshal.dump(Module.new) }.should raise_error(TypeError) end end @@ -308,7 +308,7 @@ describe "Marshal.dump" do end it "raises a TypeError with hash having default proc" do - lambda { Marshal.dump(Hash.new {}) }.should raise_error(TypeError) + -> { Marshal.dump(Hash.new {}) }.should raise_error(TypeError) end it "dumps a Hash with instance variables" do @@ -387,7 +387,7 @@ describe "Marshal.dump" do it "raises if an Object has a singleton class and singleton methods" do obj = Object.new def obj.foo; end - lambda { + -> { Marshal.dump(obj) }.should raise_error(TypeError, "singleton can't be dumped") end @@ -509,10 +509,10 @@ describe "Marshal.dump" do it "raises an ArgumentError when the recursion limit is exceeded" do h = {'one' => {'two' => {'three' => 0}}} - lambda { Marshal.dump(h, 3) }.should raise_error(ArgumentError) - lambda { Marshal.dump([h], 4) }.should raise_error(ArgumentError) - lambda { Marshal.dump([], 0) }.should raise_error(ArgumentError) - lambda { Marshal.dump([[[]]], 1) }.should raise_error(ArgumentError) + -> { Marshal.dump(h, 3) }.should raise_error(ArgumentError) + -> { Marshal.dump([h], 4) }.should raise_error(ArgumentError) + -> { Marshal.dump([], 0) }.should raise_error(ArgumentError) + -> { Marshal.dump([[[]]], 1) }.should raise_error(ArgumentError) end it "ignores the recursion limit if the limit is negative" do @@ -535,7 +535,7 @@ describe "Marshal.dump" do it "raises an Error when the IO-Object does not respond to #write" do obj = mock('test') - lambda { Marshal.dump("test", obj) }.should raise_error(TypeError) + -> { Marshal.dump("test", obj) }.should raise_error(TypeError) end @@ -554,31 +554,31 @@ describe "Marshal.dump" do it "should raise an error" do require "stringio" - lambda { Marshal.dump(StringIO.new) }.should raise_error(TypeError) + -> { Marshal.dump(StringIO.new) }.should raise_error(TypeError) end end it "raises a TypeError if marshalling a Method instance" do - lambda { Marshal.dump(Marshal.method(:dump)) }.should raise_error(TypeError) + -> { Marshal.dump(Marshal.method(:dump)) }.should raise_error(TypeError) end it "raises a TypeError if marshalling a Proc" do - lambda { Marshal.dump(proc {}) }.should raise_error(TypeError) + -> { Marshal.dump(proc {}) }.should raise_error(TypeError) end it "raises a TypeError if dumping a IO/File instance" do - lambda { Marshal.dump(STDIN) }.should raise_error(TypeError) - lambda { File.open(__FILE__) { |f| Marshal.dump(f) } }.should raise_error(TypeError) + -> { Marshal.dump(STDIN) }.should raise_error(TypeError) + -> { File.open(__FILE__) { |f| Marshal.dump(f) } }.should raise_error(TypeError) end it "raises a TypeError if dumping a MatchData instance" do - lambda { Marshal.dump(/(.)/.match("foo")) }.should raise_error(TypeError) + -> { Marshal.dump(/(.)/.match("foo")) }.should raise_error(TypeError) end it "raises a TypeError if dumping a Mutex instance" do m = Mutex.new - lambda { Marshal.dump(m) }.should raise_error(TypeError) + -> { Marshal.dump(m) }.should raise_error(TypeError) end it "returns an untainted string if object is untainted" do diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb index cb041ec25c..f92d49c68c 100644 --- a/spec/ruby/core/marshal/shared/load.rb +++ b/spec/ruby/core/marshal/shared/load.rb @@ -9,7 +9,7 @@ describe :marshal_load, shared: true do it "raises an ArgumentError when the dumped data is truncated" do obj = {first: 1, second: 2, third: 3} - lambda { Marshal.send(@method, Marshal.dump(obj)[0, 5]) }.should raise_error(ArgumentError) + -> { Marshal.send(@method, Marshal.dump(obj)[0, 5]) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the dumped class is missing" do @@ -17,7 +17,7 @@ describe :marshal_load, shared: true do kaboom = Marshal.dump(KaBoom.new) Object.send(:remove_const, :KaBoom) - lambda { Marshal.send(@method, kaboom) }.should raise_error(ArgumentError) + -> { Marshal.send(@method, kaboom) }.should raise_error(ArgumentError) end describe "when called with a proc" do @@ -162,20 +162,20 @@ describe :marshal_load, shared: true do marshal_data[0] = (Marshal::MAJOR_VERSION).chr marshal_data[1] = (Marshal::MINOR_VERSION + 1).chr - lambda { Marshal.send(@method, marshal_data) }.should raise_error(TypeError) + -> { Marshal.send(@method, marshal_data) }.should raise_error(TypeError) marshal_data = '\xff\xff' marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr marshal_data[1] = (Marshal::MINOR_VERSION).chr - lambda { Marshal.send(@method, marshal_data) }.should raise_error(TypeError) + -> { Marshal.send(@method, marshal_data) }.should raise_error(TypeError) end it "raises EOFError on loading an empty file" do temp_file = tmp("marshal.rubyspec.tmp.#{Process.pid}") file = File.new(temp_file, "w+") begin - lambda { Marshal.send(@method, file) }.should raise_error(EOFError) + -> { Marshal.send(@method, file) }.should raise_error(EOFError) ensure file.close rm_r temp_file @@ -567,7 +567,7 @@ describe :marshal_load, shared: true do end it "raises ArgumentError if the object from an 'o' stream is not dumpable as 'o' type user class" do - lambda do + -> do Marshal.send(@method, "\x04\bo:\tFile\001\001:\001\005@path\"\x10/etc/passwd") end.should raise_error(ArgumentError) end @@ -598,10 +598,10 @@ describe :marshal_load, shared: true do data = Marshal.dump(MarshalSpec::SwappedClass.new) MarshalSpec.set_swapped_class(Class.new(Array)) - lambda { Marshal.send(@method, data) }.should raise_error(ArgumentError) + -> { Marshal.send(@method, data) }.should raise_error(ArgumentError) MarshalSpec.set_swapped_class(Class.new) - lambda { Marshal.send(@method, data) }.should raise_error(ArgumentError) + -> { Marshal.send(@method, data) }.should raise_error(ArgumentError) end end end @@ -702,7 +702,7 @@ describe :marshal_load, shared: true do "\004\bi\004\0", "\004\bi\004\0\0", "\004\bi\004\0\0\0"].each do |invalid| - lambda { Marshal.send(@method, invalid) }.should raise_error(ArgumentError) + -> { Marshal.send(@method, invalid) }.should raise_error(ArgumentError) end end @@ -799,11 +799,11 @@ describe :marshal_load, shared: true do end it "raises ArgumentError if given the name of a non-Module" do - lambda { Marshal.send(@method, "\x04\bc\vKernel") }.should raise_error(ArgumentError) + -> { Marshal.send(@method, "\x04\bc\vKernel") }.should raise_error(ArgumentError) end it "raises ArgumentError if given a nonexistent class" do - lambda { Marshal.send(@method, "\x04\bc\vStrung") }.should raise_error(ArgumentError) + -> { Marshal.send(@method, "\x04\bc\vStrung") }.should raise_error(ArgumentError) end end @@ -813,7 +813,7 @@ describe :marshal_load, shared: true do end it "raises ArgumentError if given the name of a non-Class" do - lambda { Marshal.send(@method, "\x04\bm\vString") }.should raise_error(ArgumentError) + -> { Marshal.send(@method, "\x04\bm\vString") }.should raise_error(ArgumentError) end it "loads an old module" do @@ -852,13 +852,13 @@ describe :marshal_load, shared: true do data = "\x04\bd:\x1AUnloadableDumpableDirI\"\x06.\x06:\x06ET" - lambda { Marshal.send(@method, data) }.should raise_error(TypeError) + -> { Marshal.send(@method, data) }.should raise_error(TypeError) end it "raises ArgumentError when the local class is a regular object" do data = "\004\bd:\020UserDefined\0" - lambda { Marshal.send(@method, data) }.should raise_error(ArgumentError) + -> { Marshal.send(@method, data) }.should raise_error(ArgumentError) end end @@ -871,7 +871,7 @@ describe :marshal_load, shared: true do it "raises an ArgumentError" do message = "undefined class/module NamespaceTest::SameName" - lambda { Marshal.send(@method, @data) }.should raise_error(ArgumentError, message) + -> { Marshal.send(@method, @data) }.should raise_error(ArgumentError, message) end end @@ -880,6 +880,6 @@ describe :marshal_load, shared: true do @data = Marshal.dump(NamespaceTest::KaBoom.new) NamespaceTest.send(:remove_const, :KaBoom) - lambda { Marshal.send(@method, @data) }.should raise_error(ArgumentError, /NamespaceTest::KaBoom/) + -> { Marshal.send(@method, @data) }.should raise_error(ArgumentError, /NamespaceTest::KaBoom/) end end diff --git a/spec/ruby/core/matchdata/element_reference_spec.rb b/spec/ruby/core/matchdata/element_reference_spec.rb index 1f02ef235b..26550ac94d 100644 --- a/spec/ruby/core/matchdata/element_reference_spec.rb +++ b/spec/ruby/core/matchdata/element_reference_spec.rb @@ -71,12 +71,12 @@ describe "MatchData#[Symbol]" do it "raises an IndexError if there is no named match corresponding to the Symbol" do md = 'haystack'.match(/(?<t>t(?<a>ack))/) - lambda { md[:baz] }.should raise_error(IndexError, /baz/) + -> { md[:baz] }.should raise_error(IndexError, /baz/) end it "raises an IndexError if there is no named match corresponding to the String" do md = 'haystack'.match(/(?<t>t(?<a>ack))/) - lambda { md['baz'] }.should raise_error(IndexError, /baz/) + -> { md['baz'] }.should raise_error(IndexError, /baz/) end it "returns matches in the String's encoding" do diff --git a/spec/ruby/core/math/acos_spec.rb b/spec/ruby/core/math/acos_spec.rb index 0f104b8efc..8b321ab29b 100644 --- a/spec/ruby/core/math/acos_spec.rb +++ b/spec/ruby/core/math/acos_spec.rb @@ -21,15 +21,15 @@ describe "Math.acos" do end it "raises an Math::DomainError if the argument is greater than 1.0" do - lambda { Math.acos(1.0001) }.should raise_error(Math::DomainError) + -> { Math.acos(1.0001) }.should raise_error(Math::DomainError) end it "raises an Math::DomainError if the argument is less than -1.0" do - lambda { Math.acos(-1.0001) }.should raise_error(Math::DomainError) + -> { Math.acos(-1.0001) }.should raise_error(Math::DomainError) end it "raises a TypeError if the string argument cannot be coerced with Float()" do - lambda { Math.acos("test") }.should raise_error(TypeError) + -> { Math.acos("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -37,11 +37,11 @@ describe "Math.acos" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.acos(MathSpecs::UserClass.new) }.should raise_error(TypeError) + -> { Math.acos(MathSpecs::UserClass.new) }.should raise_error(TypeError) end it "raises a TypeError if the argument is nil" do - lambda { Math.acos(nil) }.should raise_error(TypeError) + -> { Math.acos(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/acosh_spec.rb b/spec/ruby/core/math/acosh_spec.rb index 26c18a530f..6707de95d3 100644 --- a/spec/ruby/core/math/acosh_spec.rb +++ b/spec/ruby/core/math/acosh_spec.rb @@ -12,13 +12,13 @@ describe "Math.acosh" do end it "raises Math::DomainError if the passed argument is less than -1.0 or greater than 1.0" do - lambda { Math.acosh(1.0 - TOLERANCE) }.should raise_error(Math::DomainError) - lambda { Math.acosh(0) }.should raise_error(Math::DomainError) - lambda { Math.acosh(-1.0) }.should raise_error(Math::DomainError) + -> { Math.acosh(1.0 - TOLERANCE) }.should raise_error(Math::DomainError) + -> { Math.acosh(0) }.should raise_error(Math::DomainError) + -> { Math.acosh(-1.0) }.should raise_error(Math::DomainError) end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.acosh("test") }.should raise_error(TypeError) + -> { Math.acosh("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -26,7 +26,7 @@ describe "Math.acosh" do end it "raises a TypeError if the argument is nil" do - lambda { Math.acosh(nil) }.should raise_error(TypeError) + -> { Math.acosh(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/asin_spec.rb b/spec/ruby/core/math/asin_spec.rb index 8591ea80ea..3a674a1147 100644 --- a/spec/ruby/core/math/asin_spec.rb +++ b/spec/ruby/core/math/asin_spec.rb @@ -17,15 +17,15 @@ describe "Math.asin" do end it "raises an Math::DomainError if the argument is greater than 1.0" do - lambda { Math.asin(1.0001) }.should raise_error( Math::DomainError) + -> { Math.asin(1.0001) }.should raise_error( Math::DomainError) end it "raises an Math::DomainError if the argument is less than -1.0" do - lambda { Math.asin(-1.0001) }.should raise_error( Math::DomainError) + -> { Math.asin(-1.0001) }.should raise_error( Math::DomainError) end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.asin("test") }.should raise_error(TypeError) + -> { Math.asin("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -33,7 +33,7 @@ describe "Math.asin" do end it "raises a TypeError if the argument is nil" do - lambda { Math.asin(nil) }.should raise_error(TypeError) + -> { Math.asin(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/asinh_spec.rb b/spec/ruby/core/math/asinh_spec.rb index 66a2beaa36..ff8210df0a 100644 --- a/spec/ruby/core/math/asinh_spec.rb +++ b/spec/ruby/core/math/asinh_spec.rb @@ -19,7 +19,7 @@ describe "Math.asinh" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.asinh("test") }.should raise_error(TypeError) + -> { Math.asinh("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -27,7 +27,7 @@ describe "Math.asinh" do end it "raises a TypeError if the argument is nil" do - lambda { Math.asinh(nil) }.should raise_error(TypeError) + -> { Math.asinh(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/atan2_spec.rb b/spec/ruby/core/math/atan2_spec.rb index da1b3476cc..d4ef369d2a 100644 --- a/spec/ruby/core/math/atan2_spec.rb +++ b/spec/ruby/core/math/atan2_spec.rb @@ -14,15 +14,15 @@ describe "Math.atan2" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.atan2(1.0, "test") }.should raise_error(TypeError) - lambda { Math.atan2("test", 0.0) }.should raise_error(TypeError) - lambda { Math.atan2("test", "this") }.should raise_error(TypeError) + -> { Math.atan2(1.0, "test") }.should raise_error(TypeError) + -> { Math.atan2("test", 0.0) }.should raise_error(TypeError) + -> { Math.atan2("test", "this") }.should raise_error(TypeError) end it "raises a TypeError if the argument is nil" do - lambda { Math.atan2(nil, 1.0) }.should raise_error(TypeError) - lambda { Math.atan2(-1.0, nil) }.should raise_error(TypeError) - lambda { Math.atan2(nil, nil) }.should raise_error(TypeError) + -> { Math.atan2(nil, 1.0) }.should raise_error(TypeError) + -> { Math.atan2(-1.0, nil) }.should raise_error(TypeError) + -> { Math.atan2(nil, nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/atan_spec.rb b/spec/ruby/core/math/atan_spec.rb index 9a9791266b..15edf68c05 100644 --- a/spec/ruby/core/math/atan_spec.rb +++ b/spec/ruby/core/math/atan_spec.rb @@ -17,7 +17,7 @@ describe "Math.atan" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.atan("test") }.should raise_error(TypeError) + -> { Math.atan("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -25,7 +25,7 @@ describe "Math.atan" do end it "raises a TypeError if the argument is nil" do - lambda { Math.atan(nil) }.should raise_error(TypeError) + -> { Math.atan(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/cbrt_spec.rb b/spec/ruby/core/math/cbrt_spec.rb index 8c96243658..01cf923c71 100644 --- a/spec/ruby/core/math/cbrt_spec.rb +++ b/spec/ruby/core/math/cbrt_spec.rb @@ -14,11 +14,11 @@ describe "Math.cbrt" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.cbrt("foobar") }.should raise_error(TypeError) + -> { Math.cbrt("foobar") }.should raise_error(TypeError) end it "raises a TypeError if the argument is nil" do - lambda { Math.cbrt(nil) }.should raise_error(TypeError) + -> { Math.cbrt(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/cos_spec.rb b/spec/ruby/core/math/cos_spec.rb index cd27b99794..3ba7a54c38 100644 --- a/spec/ruby/core/math/cos_spec.rb +++ b/spec/ruby/core/math/cos_spec.rb @@ -17,7 +17,7 @@ describe "Math.cos" do it "raises a TypeError unless the argument is Numeric and has #to_f" do - lambda { Math.cos("test") }.should raise_error(TypeError) + -> { Math.cos("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -25,7 +25,7 @@ describe "Math.cos" do end it "raises a TypeError if the argument is nil" do - lambda { Math.cos(nil) }.should raise_error(TypeError) + -> { Math.cos(nil) }.should raise_error(TypeError) end it "coerces its argument with #to_f" do diff --git a/spec/ruby/core/math/cosh_spec.rb b/spec/ruby/core/math/cosh_spec.rb index 14d4c2fe0f..049e117e56 100644 --- a/spec/ruby/core/math/cosh_spec.rb +++ b/spec/ruby/core/math/cosh_spec.rb @@ -14,7 +14,7 @@ describe "Math.cosh" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.cosh("test") }.should raise_error(TypeError) + -> { Math.cosh("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -22,7 +22,7 @@ describe "Math.cosh" do end it "raises a TypeError if the argument is nil" do - lambda { Math.cosh(nil) }.should raise_error(TypeError) + -> { Math.cosh(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/erf_spec.rb b/spec/ruby/core/math/erf_spec.rb index 96757e412d..b4e6248e43 100644 --- a/spec/ruby/core/math/erf_spec.rb +++ b/spec/ruby/core/math/erf_spec.rb @@ -21,7 +21,7 @@ describe "Math.erf" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.erf("test") }.should raise_error(TypeError) + -> { Math.erf("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -29,7 +29,7 @@ describe "Math.erf" do end it "raises a TypeError if the argument is nil" do - lambda { Math.erf(nil) }.should raise_error(TypeError) + -> { Math.erf(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/erfc_spec.rb b/spec/ruby/core/math/erfc_spec.rb index eca23eaf7c..e465f5cf58 100644 --- a/spec/ruby/core/math/erfc_spec.rb +++ b/spec/ruby/core/math/erfc_spec.rb @@ -20,7 +20,7 @@ describe "Math.erfc" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.erfc("test") }.should raise_error(TypeError) + -> { Math.erfc("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -28,7 +28,7 @@ describe "Math.erfc" do end it "raises a TypeError if the argument is nil" do - lambda { Math.erfc(nil) }.should raise_error(TypeError) + -> { Math.erfc(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/exp_spec.rb b/spec/ruby/core/math/exp_spec.rb index d97550dc4e..36eb49a8c7 100644 --- a/spec/ruby/core/math/exp_spec.rb +++ b/spec/ruby/core/math/exp_spec.rb @@ -14,7 +14,7 @@ describe "Math.exp" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.exp("test") }.should raise_error(TypeError) + -> { Math.exp("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -22,7 +22,7 @@ describe "Math.exp" do end it "raises a TypeError if the argument is nil" do - lambda { Math.exp(nil) }.should raise_error(TypeError) + -> { Math.exp(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/frexp_spec.rb b/spec/ruby/core/math/frexp_spec.rb index 31b5b4079f..7dfb493d20 100644 --- a/spec/ruby/core/math/frexp_spec.rb +++ b/spec/ruby/core/math/frexp_spec.rb @@ -9,7 +9,7 @@ describe "Math.frexp" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.frexp("test") }.should raise_error(TypeError) + -> { Math.frexp("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -18,7 +18,7 @@ describe "Math.frexp" do end it "raises a TypeError if the argument is nil" do - lambda { Math.frexp(nil) }.should raise_error(TypeError) + -> { Math.frexp(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/gamma_spec.rb b/spec/ruby/core/math/gamma_spec.rb index ce7f82421f..386162a087 100644 --- a/spec/ruby/core/math/gamma_spec.rb +++ b/spec/ruby/core/math/gamma_spec.rb @@ -51,7 +51,7 @@ describe "Math.gamma" do end it "raises Math::DomainError given -1" do - lambda { Math.gamma(-1) }.should raise_error(Math::DomainError) + -> { Math.gamma(-1) }.should raise_error(Math::DomainError) end # See https://bugs.ruby-lang.org/issues/10642 @@ -60,7 +60,7 @@ describe "Math.gamma" do end it "raises Math::DomainError given negative infinity" do - lambda { Math.gamma(-Float::INFINITY) }.should raise_error(Math::DomainError) + -> { Math.gamma(-Float::INFINITY) }.should raise_error(Math::DomainError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/hypot_spec.rb b/spec/ruby/core/math/hypot_spec.rb index 20badb2840..3e0ce74597 100644 --- a/spec/ruby/core/math/hypot_spec.rb +++ b/spec/ruby/core/math/hypot_spec.rb @@ -16,7 +16,7 @@ describe "Math.hypot" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.hypot("test", "this") }.should raise_error(TypeError) + -> { Math.hypot("test", "this") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -26,7 +26,7 @@ describe "Math.hypot" do end it "raises a TypeError if the argument is nil" do - lambda { Math.hypot(nil, nil) }.should raise_error(TypeError) + -> { Math.hypot(nil, nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/ldexp_spec.rb b/spec/ruby/core/math/ldexp_spec.rb index 8602b33d43..fb7799cf26 100644 --- a/spec/ruby/core/math/ldexp_spec.rb +++ b/spec/ruby/core/math/ldexp_spec.rb @@ -15,7 +15,7 @@ describe "Math.ldexp" do end it "raises a TypeError if the first argument cannot be coerced with Float()" do - lambda { Math.ldexp("test", 2) }.should raise_error(TypeError) + -> { Math.ldexp("test", 2) }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -23,19 +23,19 @@ describe "Math.ldexp" do end it "raises RangeError if NaN is given as the second arg" do - lambda { Math.ldexp(0, nan_value) }.should raise_error(RangeError) + -> { Math.ldexp(0, nan_value) }.should raise_error(RangeError) end it "raises a TypeError if the second argument cannot be coerced with Integer()" do - lambda { Math.ldexp(3.2, "this") }.should raise_error(TypeError) + -> { Math.ldexp(3.2, "this") }.should raise_error(TypeError) end it "raises a TypeError if the first argument is nil" do - lambda { Math.ldexp(nil, 2) }.should raise_error(TypeError) + -> { Math.ldexp(nil, 2) }.should raise_error(TypeError) end it "raises a TypeError if the second argument is nil" do - lambda { Math.ldexp(3.1, nil) }.should raise_error(TypeError) + -> { Math.ldexp(3.1, nil) }.should raise_error(TypeError) end it "accepts any first argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/lgamma_spec.rb b/spec/ruby/core/math/lgamma_spec.rb index a20d0a4f2f..33e7836448 100644 --- a/spec/ruby/core/math/lgamma_spec.rb +++ b/spec/ruby/core/math/lgamma_spec.rb @@ -40,7 +40,7 @@ describe "Math.lgamma" do end it "raises Math::DomainError when passed -Infinity" do - lambda { Math.lgamma(-infinity_value) }.should raise_error(Math::DomainError) + -> { Math.lgamma(-infinity_value) }.should raise_error(Math::DomainError) end it "returns [Infinity, 1] when passed Infinity" do diff --git a/spec/ruby/core/math/log10_spec.rb b/spec/ruby/core/math/log10_spec.rb index 2c594999b7..c4daedcd5c 100644 --- a/spec/ruby/core/math/log10_spec.rb +++ b/spec/ruby/core/math/log10_spec.rb @@ -16,11 +16,11 @@ describe "Math.log10" do end it "raises an Math::DomainError if the argument is less than 0" do - lambda { Math.log10(-1e-15) }.should raise_error(Math::DomainError) + -> { Math.log10(-1e-15) }.should raise_error(Math::DomainError) end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.log10("test") }.should raise_error(TypeError) + -> { Math.log10("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -28,7 +28,7 @@ describe "Math.log10" do end it "raises a TypeError if the argument is nil" do - lambda { Math.log10(nil) }.should raise_error(TypeError) + -> { Math.log10(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/log2_spec.rb b/spec/ruby/core/math/log2_spec.rb index 8a7c582f92..1594f2d7af 100644 --- a/spec/ruby/core/math/log2_spec.rb +++ b/spec/ruby/core/math/log2_spec.rb @@ -16,15 +16,15 @@ describe "Math.log2" do end it "raises an Errno::EDOM if the argument is less than 0" do - lambda { Math.log2(-1e-15) }.should raise_error( Math::DomainError) + -> { Math.log2(-1e-15) }.should raise_error( Math::DomainError) end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.log2("test") }.should raise_error(TypeError) + -> { Math.log2("test") }.should raise_error(TypeError) end it "raises a TypeError if passed a numerical argument as a string" do - lambda { Math.log2("1.0") }.should raise_error(TypeError) + -> { Math.log2("1.0") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -32,7 +32,7 @@ describe "Math.log2" do end it "raises a TypeError if the argument is nil" do - lambda { Math.log2(nil) }.should raise_error(TypeError) + -> { Math.log2(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/log_spec.rb b/spec/ruby/core/math/log_spec.rb index c09e270c06..6c5036ba81 100644 --- a/spec/ruby/core/math/log_spec.rb +++ b/spec/ruby/core/math/log_spec.rb @@ -16,15 +16,15 @@ describe "Math.log" do end it "raises an Math::DomainError if the argument is less than 0" do - lambda { Math.log(-1e-15) }.should raise_error(Math::DomainError) + -> { Math.log(-1e-15) }.should raise_error(Math::DomainError) end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.log("test") }.should raise_error(TypeError) + -> { Math.log("test") }.should raise_error(TypeError) end it "raises a TypeError for numerical values passed as string" do - lambda { Math.log("10") }.should raise_error(TypeError) + -> { Math.log("10") }.should raise_error(TypeError) end it "accepts a second argument for the base" do @@ -33,8 +33,8 @@ describe "Math.log" do end it "raises a TypeError when the numerical base cannot be coerced to a float" do - lambda { Math.log(10, "2") }.should raise_error(TypeError) - lambda { Math.log(10, nil) }.should raise_error(TypeError) + -> { Math.log(10, "2") }.should raise_error(TypeError) + -> { Math.log(10, nil) }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -42,7 +42,7 @@ describe "Math.log" do end it "raises a TypeError if the argument is nil" do - lambda { Math.log(nil) }.should raise_error(TypeError) + -> { Math.log(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/sin_spec.rb b/spec/ruby/core/math/sin_spec.rb index 96bef5fed1..8e944bc95f 100644 --- a/spec/ruby/core/math/sin_spec.rb +++ b/spec/ruby/core/math/sin_spec.rb @@ -16,7 +16,7 @@ describe "Math.sin" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.sin("test") }.should raise_error(TypeError) + -> { Math.sin("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -24,7 +24,7 @@ describe "Math.sin" do end it "raises a TypeError if the argument is nil" do - lambda { Math.sin(nil) }.should raise_error(TypeError) + -> { Math.sin(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/sinh_spec.rb b/spec/ruby/core/math/sinh_spec.rb index e0fa0c99e9..027c2395a7 100644 --- a/spec/ruby/core/math/sinh_spec.rb +++ b/spec/ruby/core/math/sinh_spec.rb @@ -14,7 +14,7 @@ describe "Math.sinh" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.sinh("test") }.should raise_error(TypeError) + -> { Math.sinh("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -22,7 +22,7 @@ describe "Math.sinh" do end it "raises a TypeError if the argument is nil" do - lambda { Math.sinh(nil) }.should raise_error(TypeError) + -> { Math.sinh(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/sqrt_spec.rb b/spec/ruby/core/math/sqrt_spec.rb index 50fd132b2a..779aea2a0a 100644 --- a/spec/ruby/core/math/sqrt_spec.rb +++ b/spec/ruby/core/math/sqrt_spec.rb @@ -13,7 +13,7 @@ describe "Math.sqrt" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.sqrt("test") }.should raise_error(TypeError) + -> { Math.sqrt("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -21,7 +21,7 @@ describe "Math.sqrt" do end it "raises a TypeError if the argument is nil" do - lambda { Math.sqrt(nil) }.should raise_error(TypeError) + -> { Math.sqrt(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/tan_spec.rb b/spec/ruby/core/math/tan_spec.rb index 031fe75085..c7b188cd81 100644 --- a/spec/ruby/core/math/tan_spec.rb +++ b/spec/ruby/core/math/tan_spec.rb @@ -19,7 +19,7 @@ describe "Math.tan" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.tan("test") }.should raise_error(TypeError) + -> { Math.tan("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -27,7 +27,7 @@ describe "Math.tan" do end it "raises a TypeError if the argument is nil" do - lambda { Math.tan(nil) }.should raise_error(TypeError) + -> { Math.tan(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/math/tanh_spec.rb b/spec/ruby/core/math/tanh_spec.rb index 699d882ee8..568f8dfa77 100644 --- a/spec/ruby/core/math/tanh_spec.rb +++ b/spec/ruby/core/math/tanh_spec.rb @@ -16,7 +16,7 @@ describe "Math.tanh" do end it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.tanh("test") }.should raise_error(TypeError) + -> { Math.tanh("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do @@ -24,7 +24,7 @@ describe "Math.tanh" do end it "raises a TypeError if the argument is nil" do - lambda { Math.tanh(nil) }.should raise_error(TypeError) + -> { Math.tanh(nil) }.should raise_error(TypeError) end it "accepts any argument that can be coerced with Float()" do diff --git a/spec/ruby/core/method/curry_spec.rb b/spec/ruby/core/method/curry_spec.rb index 36449f7512..219de0f6b5 100644 --- a/spec/ruby/core/method/curry_spec.rb +++ b/spec/ruby/core/method/curry_spec.rb @@ -23,14 +23,14 @@ describe "Method#curry" do end it "raises ArgumentError when the method requires less arguments than the given arity" do - lambda { @obj.method(:zero).curry(1) }.should raise_error(ArgumentError) - lambda { @obj.method(:one_req_one_opt).curry(3) }.should raise_error(ArgumentError) - lambda { @obj.method(:two_req_one_opt_with_block).curry(4) }.should raise_error(ArgumentError) + -> { @obj.method(:zero).curry(1) }.should raise_error(ArgumentError) + -> { @obj.method(:one_req_one_opt).curry(3) }.should raise_error(ArgumentError) + -> { @obj.method(:two_req_one_opt_with_block).curry(4) }.should raise_error(ArgumentError) end it "raises ArgumentError when the method requires more arguments than the given arity" do - lambda { @obj.method(:two_req_with_splat).curry(1) }.should raise_error(ArgumentError) - lambda { @obj.method(:one_req).curry(0) }.should raise_error(ArgumentError) + -> { @obj.method(:two_req_with_splat).curry(1) }.should raise_error(ArgumentError) + -> { @obj.method(:one_req).curry(0) }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/method/parameters_spec.rb b/spec/ruby/core/method/parameters_spec.rb index 1de3901040..3fdaf9ce6f 100644 --- a/spec/ruby/core/method/parameters_spec.rb +++ b/spec/ruby/core/method/parameters_spec.rb @@ -12,7 +12,7 @@ describe "Method#parameters" do def one_splat_two_req(*a,b,c); end def one_splat_one_req_with_block(*a,b,&blk); end - def one_opt_with_stabby(a=->(b){true}); end + def one_opt_with_stabby(a=-> b { true }); end def one_unnamed_splat(*); end diff --git a/spec/ruby/core/method/shared/call.rb b/spec/ruby/core/method/shared/call.rb index f178b9da7d..f26e373695 100644 --- a/spec/ruby/core/method/shared/call.rb +++ b/spec/ruby/core/method/shared/call.rb @@ -9,10 +9,10 @@ describe :method_call, shared: true do end it "raises an ArgumentError when given incorrect number of arguments" do - lambda { + -> { MethodSpecs::Methods.new.method(:two_req).send(@method, 1, 2, 3) }.should raise_error(ArgumentError) - lambda { + -> { MethodSpecs::Methods.new.method(:two_req).send(@method, 1) }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/module/alias_method_spec.rb b/spec/ruby/core/module/alias_method_spec.rb index 8a2ddafda1..b14f5430a8 100644 --- a/spec/ruby/core/module/alias_method_spec.rb +++ b/spec/ruby/core/module/alias_method_spec.rb @@ -28,12 +28,12 @@ describe "Module#alias_method" do it "retains method visibility" do @class.make_alias :private_ichi, :private_one - lambda { @object.private_one }.should raise_error(NameError) - lambda { @object.private_ichi }.should raise_error(NameError) + -> { @object.private_one }.should raise_error(NameError) + -> { @object.private_ichi }.should raise_error(NameError) @class.make_alias :public_ichi, :public_one @object.public_ichi.should == @object.public_one @class.make_alias :protected_ichi, :protected_one - lambda { @object.protected_ichi }.should raise_error(NameError) + -> { @object.protected_ichi }.should raise_error(NameError) end it "handles aliasing a stub that changes visibility" do @@ -43,7 +43,7 @@ describe "Module#alias_method" do end it "fails if origin method not found" do - lambda { @class.make_alias :ni, :san }.should raise_error(NameError) { |e| + -> { @class.make_alias :ni, :san }.should raise_error(NameError) { |e| # a NameError and not a NoMethodError e.class.should == NameError } @@ -51,7 +51,7 @@ describe "Module#alias_method" do it "raises #{frozen_error_class} if frozen" do @class.freeze - lambda { @class.make_alias :uno, :public_one }.should raise_error(frozen_error_class) + -> { @class.make_alias :uno, :public_one }.should raise_error(frozen_error_class) end it "converts the names using #to_str" do @@ -66,12 +66,12 @@ describe "Module#alias_method" do end it "raises a TypeError when the given name can't be converted using to_str" do - lambda { @class.make_alias mock('x'), :public_one }.should raise_error(TypeError) + -> { @class.make_alias mock('x'), :public_one }.should raise_error(TypeError) end ruby_version_is ''...'2.5' do it "is a private method" do - lambda { @class.alias_method :ichi, :public_one }.should raise_error(NoMethodError) + -> { @class.alias_method :ichi, :public_one }.should raise_error(NoMethodError) end end ruby_version_is '2.5' do @@ -90,7 +90,7 @@ describe "Module#alias_method" do it "works on private module methods in a module that has been reopened" do ModuleSpecs::ReopeningModule.foo.should == true - lambda { ModuleSpecs::ReopeningModule.foo2 }.should_not raise_error(NoMethodError) + -> { ModuleSpecs::ReopeningModule.foo2 }.should_not raise_error(NoMethodError) end it "accesses a method defined on Object from Kernel" do diff --git a/spec/ruby/core/module/append_features_spec.rb b/spec/ruby/core/module/append_features_spec.rb index c5dd64aa6f..584aa11dfa 100644 --- a/spec/ruby/core/module/append_features_spec.rb +++ b/spec/ruby/core/module/append_features_spec.rb @@ -12,7 +12,7 @@ describe "Module#append_features" do end it "raises a TypeError if calling after rebinded to Class" do - lambda { + -> { Module.instance_method(:append_features).bind(Class.new).call Module.new }.should raise_error(TypeError) end @@ -37,11 +37,11 @@ describe "Module#append_features" do end it "raises an ArgumentError on a cyclic include" do - lambda { + -> { ModuleSpecs::CyclicAppendA.send(:append_features, ModuleSpecs::CyclicAppendA) }.should raise_error(ArgumentError) - lambda { + -> { ModuleSpecs::CyclicAppendB.send(:append_features, ModuleSpecs::CyclicAppendA) }.should raise_error(ArgumentError) @@ -66,7 +66,7 @@ describe "Module#append_features" do end it "raises a #{frozen_error_class} before appending self" do - lambda { @receiver.send(:append_features, @other) }.should raise_error(frozen_error_class) + -> { @receiver.send(:append_features, @other) }.should raise_error(frozen_error_class) @other.ancestors.should_not include(@receiver) end end diff --git a/spec/ruby/core/module/attr_accessor_spec.rb b/spec/ruby/core/module/attr_accessor_spec.rb index b5e3d72524..ce95ccd487 100644 --- a/spec/ruby/core/module/attr_accessor_spec.rb +++ b/spec/ruby/core/module/attr_accessor_spec.rb @@ -33,7 +33,7 @@ describe "Module#attr_accessor" do attr_accessor :spec_attr_accessor end - lambda { true.spec_attr_accessor = "a" }.should raise_error(RuntimeError) + -> { true.spec_attr_accessor = "a" }.should raise_error(RuntimeError) end it "converts non string/symbol/fixnum names to strings using to_str" do @@ -48,9 +48,9 @@ describe "Module#attr_accessor" do it "raises a TypeError when the given names can't be converted to strings using to_str" do o = mock('o') - lambda { Class.new { attr_accessor o } }.should raise_error(TypeError) + -> { Class.new { attr_accessor o } }.should raise_error(TypeError) (o = mock('123')).should_receive(:to_str).and_return(123) - lambda { Class.new { attr_accessor o } }.should raise_error(TypeError) + -> { Class.new { attr_accessor o } }.should raise_error(TypeError) end it "applies current visibility to methods created" do @@ -59,8 +59,8 @@ describe "Module#attr_accessor" do attr_accessor :foo end - lambda { c.new.foo }.should raise_error(NoMethodError) - lambda { c.new.foo=1 }.should raise_error(NoMethodError) + -> { c.new.foo }.should raise_error(NoMethodError) + -> { c.new.foo=1 }.should raise_error(NoMethodError) end ruby_version_is ''...'2.5' do diff --git a/spec/ruby/core/module/attr_reader_spec.rb b/spec/ruby/core/module/attr_reader_spec.rb index f537b5f1c6..082bc03b60 100644 --- a/spec/ruby/core/module/attr_reader_spec.rb +++ b/spec/ruby/core/module/attr_reader_spec.rb @@ -29,7 +29,7 @@ describe "Module#attr_reader" do attr_reader :spec_attr_reader end - lambda { true.instance_variable_set("@spec_attr_reader", "a") }.should raise_error(RuntimeError) + -> { true.instance_variable_set("@spec_attr_reader", "a") }.should raise_error(RuntimeError) end it "converts non string/symbol/fixnum names to strings using to_str" do @@ -44,9 +44,9 @@ describe "Module#attr_reader" do it "raises a TypeError when the given names can't be converted to strings using to_str" do o = mock('o') - lambda { Class.new { attr_reader o } }.should raise_error(TypeError) + -> { Class.new { attr_reader o } }.should raise_error(TypeError) (o = mock('123')).should_receive(:to_str).and_return(123) - lambda { Class.new { attr_reader o } }.should raise_error(TypeError) + -> { Class.new { attr_reader o } }.should raise_error(TypeError) end it "applies current visibility to methods created" do @@ -55,7 +55,7 @@ describe "Module#attr_reader" do attr_reader :foo end - lambda { c.new.foo }.should raise_error(NoMethodError) + -> { c.new.foo }.should raise_error(NoMethodError) end ruby_version_is ''...'2.5' do diff --git a/spec/ruby/core/module/attr_spec.rb b/spec/ruby/core/module/attr_spec.rb index 16680730d5..20316a3d39 100644 --- a/spec/ruby/core/module/attr_spec.rb +++ b/spec/ruby/core/module/attr_spec.rb @@ -89,8 +89,8 @@ describe "Module#attr" do attr :foo, true end - lambda { c.new.foo }.should raise_error(NoMethodError) - lambda { c.new.foo=1 }.should raise_error(NoMethodError) + -> { c.new.foo }.should raise_error(NoMethodError) + -> { c.new.foo=1 }.should raise_error(NoMethodError) end it "creates a getter but no setter for all given attribute names" do @@ -120,8 +120,8 @@ describe "Module#attr" do attr :foo, :bar end - lambda { c.new.foo }.should raise_error(NoMethodError) - lambda { c.new.bar }.should raise_error(NoMethodError) + -> { c.new.foo }.should raise_error(NoMethodError) + -> { c.new.bar }.should raise_error(NoMethodError) end it "converts non string/symbol/fixnum names to strings using to_str" do @@ -131,13 +131,13 @@ describe "Module#attr" do it "raises a TypeError when the given names can't be converted to strings using to_str" do o = mock('o') - lambda { Class.new { attr o } }.should raise_error(TypeError) + -> { Class.new { attr o } }.should raise_error(TypeError) (o = mock('123')).should_receive(:to_str).and_return(123) - lambda { Class.new { attr o } }.should raise_error(TypeError) + -> { Class.new { attr o } }.should raise_error(TypeError) end it "with a boolean argument emits a warning when $VERBOSE is true" do - lambda { + -> { Class.new { attr :foo, true } }.should complain(/boolean argument is obsoleted/, verbose: true) end diff --git a/spec/ruby/core/module/attr_writer_spec.rb b/spec/ruby/core/module/attr_writer_spec.rb index ea77f81f28..3b110cecf7 100644 --- a/spec/ruby/core/module/attr_writer_spec.rb +++ b/spec/ruby/core/module/attr_writer_spec.rb @@ -29,7 +29,7 @@ describe "Module#attr_writer" do attr_writer :spec_attr_writer end - lambda { true.spec_attr_writer = "a" }.should raise_error(RuntimeError) + -> { true.spec_attr_writer = "a" }.should raise_error(RuntimeError) end it "converts non string/symbol/fixnum names to strings using to_str" do @@ -44,9 +44,9 @@ describe "Module#attr_writer" do it "raises a TypeError when the given names can't be converted to strings using to_str" do o = mock('test1') - lambda { Class.new { attr_writer o } }.should raise_error(TypeError) + -> { Class.new { attr_writer o } }.should raise_error(TypeError) (o = mock('123')).should_receive(:to_str).and_return(123) - lambda { Class.new { attr_writer o } }.should raise_error(TypeError) + -> { Class.new { attr_writer o } }.should raise_error(TypeError) end it "applies current visibility to methods created" do @@ -55,7 +55,7 @@ describe "Module#attr_writer" do attr_writer :foo end - lambda { c.new.foo=1 }.should raise_error(NoMethodError) + -> { c.new.foo=1 }.should raise_error(NoMethodError) end ruby_version_is ''...'2.5' do diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index ca4c63838c..6a1efa1ec2 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -189,7 +189,7 @@ describe "Module#autoload" do ModuleSpecs::Autoload.autoload :NotThere, filename ModuleSpecs::Autoload.autoload?(:NotThere).should == filename - lambda { + -> { require filename }.should raise_error(LoadError) @@ -385,13 +385,13 @@ describe "Module#autoload" do ModuleSpecs::Autoload.should have_constant(:Fail) ModuleSpecs::Autoload.autoload?(:Fail).should == @non_existent - lambda { ModuleSpecs::Autoload::Fail }.should raise_error(LoadError) + -> { ModuleSpecs::Autoload::Fail }.should raise_error(LoadError) ModuleSpecs::Autoload.should have_constant(:Fail) ModuleSpecs::Autoload.const_defined?(:Fail).should == true ModuleSpecs::Autoload.autoload?(:Fail).should == @non_existent - lambda { ModuleSpecs::Autoload::Fail }.should raise_error(LoadError) + -> { ModuleSpecs::Autoload::Fail }.should raise_error(LoadError) end it "does not remove the constant from Module#constants if load raises a RuntimeError and keeps it as an autoload" do @@ -403,14 +403,14 @@ describe "Module#autoload" do ModuleSpecs::Autoload.should have_constant(:Raise) ModuleSpecs::Autoload.autoload?(:Raise).should == path - lambda { ModuleSpecs::Autoload::Raise }.should raise_error(RuntimeError) + -> { ModuleSpecs::Autoload::Raise }.should raise_error(RuntimeError) ScratchPad.recorded.should == [:raise] ModuleSpecs::Autoload.should have_constant(:Raise) ModuleSpecs::Autoload.const_defined?(:Raise).should == true ModuleSpecs::Autoload.autoload?(:Raise).should == path - lambda { ModuleSpecs::Autoload::Raise }.should raise_error(RuntimeError) + -> { ModuleSpecs::Autoload::Raise }.should raise_error(RuntimeError) ScratchPad.recorded.should == [:raise, :raise] end @@ -423,7 +423,7 @@ describe "Module#autoload" do ModuleSpecs::Autoload.should have_constant(:O) ModuleSpecs::Autoload.autoload?(:O).should == path - lambda { ModuleSpecs::Autoload::O }.should raise_error(NameError) + -> { ModuleSpecs::Autoload::O }.should raise_error(NameError) ModuleSpecs::Autoload.should have_constant(:O) ModuleSpecs::Autoload.const_defined?(:O).should == false @@ -659,19 +659,19 @@ describe "Module#autoload" do end it "raises an ArgumentError when an empty filename is given" do - lambda { ModuleSpecs.autoload :A, "" }.should raise_error(ArgumentError) + -> { ModuleSpecs.autoload :A, "" }.should raise_error(ArgumentError) end it "raises a NameError when the constant name starts with a lower case letter" do - lambda { ModuleSpecs.autoload "a", @non_existent }.should raise_error(NameError) + -> { ModuleSpecs.autoload "a", @non_existent }.should raise_error(NameError) end it "raises a NameError when the constant name starts with a number" do - lambda { ModuleSpecs.autoload "1two", @non_existent }.should raise_error(NameError) + -> { ModuleSpecs.autoload "1two", @non_existent }.should raise_error(NameError) end it "raises a NameError when the constant name has a space in it" do - lambda { ModuleSpecs.autoload "a name", @non_existent }.should raise_error(NameError) + -> { ModuleSpecs.autoload "a name", @non_existent }.should raise_error(NameError) end it "shares the autoload request across dup'ed copies of modules" do @@ -679,7 +679,7 @@ describe "Module#autoload" do @remove << :S filename = fixture(__FILE__, "autoload_t.rb") mod1 = Module.new { autoload :T, filename } - lambda { + -> { ModuleSpecs::Autoload::S = mod1 }.should complain(/already initialized constant/) mod2 = mod1.dup @@ -688,7 +688,7 @@ describe "Module#autoload" do mod2.autoload?(:T).should == filename mod1::T.should == :autoload_t - lambda { mod2::T }.should raise_error(NameError) + -> { mod2::T }.should raise_error(NameError) end it "raises a TypeError if opening a class with a different superclass than the class defined in the autoload file" do @@ -696,7 +696,7 @@ describe "Module#autoload" do class ModuleSpecs::Autoload::ZZ end - lambda do + -> do class ModuleSpecs::Autoload::Z < ModuleSpecs::Autoload::ZZ end end.should raise_error(TypeError) @@ -705,20 +705,20 @@ describe "Module#autoload" do it "raises a TypeError if not passed a String or object responding to #to_path for the filename" do name = mock("autoload_name.rb") - lambda { ModuleSpecs::Autoload.autoload :Str, name }.should raise_error(TypeError) + -> { ModuleSpecs::Autoload.autoload :Str, name }.should raise_error(TypeError) end it "calls #to_path on non-String filename arguments" do name = mock("autoload_name.rb") name.should_receive(:to_path).and_return("autoload_name.rb") - lambda { ModuleSpecs::Autoload.autoload :Str, name }.should_not raise_error + -> { ModuleSpecs::Autoload.autoload :Str, name }.should_not raise_error end describe "on a frozen module" do it "raises a #{frozen_error_class} before setting the name" do frozen_module = Module.new.freeze - lambda { frozen_module.autoload :Foo, @non_existent }.should raise_error(frozen_error_class) + -> { frozen_module.autoload :Foo, @non_existent }.should raise_error(frozen_error_class) frozen_module.should_not have_constant(:Foo) end end diff --git a/spec/ruby/core/module/class_variable_defined_spec.rb b/spec/ruby/core/module/class_variable_defined_spec.rb index 25fd73a136..f867d383c3 100644 --- a/spec/ruby/core/module/class_variable_defined_spec.rb +++ b/spec/ruby/core/module/class_variable_defined_spec.rb @@ -42,11 +42,11 @@ describe "Module#class_variable_defined?" do it "raises a NameError when the given name is not allowed" do c = Class.new - lambda { + -> { c.class_variable_defined?(:invalid_name) }.should raise_error(NameError) - lambda { + -> { c.class_variable_defined?("@invalid_name") }.should raise_error(NameError) end @@ -60,12 +60,12 @@ describe "Module#class_variable_defined?" do it "raises a TypeError when the given names can't be converted to strings using to_str" do c = Class.new { class_variable_set :@@class_var, "test" } o = mock('123') - lambda { + -> { c.class_variable_defined?(o) }.should raise_error(TypeError) o.should_receive(:to_str).and_return(123) - lambda { + -> { c.class_variable_defined?(o) }.should raise_error(TypeError) end diff --git a/spec/ruby/core/module/class_variable_get_spec.rb b/spec/ruby/core/module/class_variable_get_spec.rb index 7619c135ab..79d22a506b 100644 --- a/spec/ruby/core/module/class_variable_get_spec.rb +++ b/spec/ruby/core/module/class_variable_get_spec.rb @@ -15,14 +15,14 @@ describe "Module#class_variable_get" do it "raises a NameError for a class variable named '@@'" do c = Class.new - lambda { c.send(:class_variable_get, "@@") }.should raise_error(NameError) - lambda { c.send(:class_variable_get, :"@@") }.should raise_error(NameError) + -> { c.send(:class_variable_get, "@@") }.should raise_error(NameError) + -> { c.send(:class_variable_get, :"@@") }.should raise_error(NameError) end it "raises a NameError for a class variables with the given name defined in an extended module" do c = Class.new c.extend ModuleSpecs::MVars - lambda { + -> { c.send(:class_variable_get, "@@mvar") }.should raise_error(NameError) end @@ -49,15 +49,15 @@ describe "Module#class_variable_get" do it "raises a NameError when an uninitialized class variable is accessed" do c = Class.new [:@@no_class_var, "@@no_class_var"].each do |cvar| - lambda { c.send(:class_variable_get, cvar) }.should raise_error(NameError) + -> { c.send(:class_variable_get, cvar) }.should raise_error(NameError) end end it "raises a NameError when the given name is not allowed" do c = Class.new - lambda { c.send(:class_variable_get, :invalid_name) }.should raise_error(NameError) - lambda { c.send(:class_variable_get, "@invalid_name") }.should raise_error(NameError) + -> { c.send(:class_variable_get, :invalid_name) }.should raise_error(NameError) + -> { c.send(:class_variable_get, "@invalid_name") }.should raise_error(NameError) end it "converts a non string/symbol/fixnum name to string using to_str" do @@ -69,8 +69,8 @@ describe "Module#class_variable_get" do it "raises a TypeError when the given names can't be converted to strings using to_str" do c = Class.new { class_variable_set :@@class_var, "test" } o = mock('123') - lambda { c.send(:class_variable_get, o) }.should raise_error(TypeError) + -> { c.send(:class_variable_get, o) }.should raise_error(TypeError) o.should_receive(:to_str).and_return(123) - lambda { c.send(:class_variable_get, o) }.should raise_error(TypeError) + -> { c.send(:class_variable_get, o) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/module/class_variable_set_spec.rb b/spec/ruby/core/module/class_variable_set_spec.rb index dcb5da87b6..204bbaf75e 100644 --- a/spec/ruby/core/module/class_variable_set_spec.rb +++ b/spec/ruby/core/module/class_variable_set_spec.rb @@ -26,10 +26,10 @@ describe "Module#class_variable_set" do end it "raises a #{frozen_error_class} when self is frozen" do - lambda { + -> { Class.new.freeze.send(:class_variable_set, :@@test, "test") }.should raise_error(frozen_error_class) - lambda { + -> { Module.new.freeze.send(:class_variable_set, :@@test, "test") }.should raise_error(frozen_error_class) end @@ -37,10 +37,10 @@ describe "Module#class_variable_set" do it "raises a NameError when the given name is not allowed" do c = Class.new - lambda { + -> { c.send(:class_variable_set, :invalid_name, "test") }.should raise_error(NameError) - lambda { + -> { c.send(:class_variable_set, "@invalid_name", "test") }.should raise_error(NameError) end @@ -55,8 +55,8 @@ describe "Module#class_variable_set" do it "raises a TypeError when the given names can't be converted to strings using to_str" do c = Class.new { class_variable_set :@@class_var, "test" } o = mock('123') - lambda { c.send(:class_variable_set, o, "test") }.should raise_error(TypeError) + -> { c.send(:class_variable_set, o, "test") }.should raise_error(TypeError) o.should_receive(:to_str).and_return(123) - lambda { c.send(:class_variable_set, o, "test") }.should raise_error(TypeError) + -> { c.send(:class_variable_set, o, "test") }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/module/const_defined_spec.rb b/spec/ruby/core/module/const_defined_spec.rb index cb1674c7e7..0673adca3d 100644 --- a/spec/ruby/core/module/const_defined_spec.rb +++ b/spec/ruby/core/module/const_defined_spec.rb @@ -105,19 +105,19 @@ describe "Module#const_defined?" do end it "raises a NameError if the name does not start with a capital letter" do - lambda { ConstantSpecs.const_defined? "name" }.should raise_error(NameError) + -> { ConstantSpecs.const_defined? "name" }.should raise_error(NameError) end it "raises a NameError if the name starts with '_'" do - lambda { ConstantSpecs.const_defined? "__CONSTX__" }.should raise_error(NameError) + -> { ConstantSpecs.const_defined? "__CONSTX__" }.should raise_error(NameError) end it "raises a NameError if the name starts with '@'" do - lambda { ConstantSpecs.const_defined? "@Name" }.should raise_error(NameError) + -> { ConstantSpecs.const_defined? "@Name" }.should raise_error(NameError) end it "raises a NameError if the name starts with '!'" do - lambda { ConstantSpecs.const_defined? "!Name" }.should raise_error(NameError) + -> { ConstantSpecs.const_defined? "!Name" }.should raise_error(NameError) end it "returns true or false for the nested name" do @@ -130,15 +130,15 @@ describe "Module#const_defined?" do it "raises a NameError if the name contains non-alphabetic characters except '_'" do ConstantSpecs.const_defined?("CS_CONSTX").should == false - lambda { ConstantSpecs.const_defined? "Name=" }.should raise_error(NameError) - lambda { ConstantSpecs.const_defined? "Name?" }.should raise_error(NameError) + -> { ConstantSpecs.const_defined? "Name=" }.should raise_error(NameError) + -> { ConstantSpecs.const_defined? "Name?" }.should raise_error(NameError) end it "raises a TypeError if conversion to a String by calling #to_str fails" do name = mock('123') - lambda { ConstantSpecs.const_defined? name }.should raise_error(TypeError) + -> { ConstantSpecs.const_defined? name }.should raise_error(TypeError) name.should_receive(:to_str).and_return(123) - lambda { ConstantSpecs.const_defined? name }.should raise_error(TypeError) + -> { ConstantSpecs.const_defined? name }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/module/const_get_spec.rb b/spec/ruby/core/module/const_get_spec.rb index d125c35762..0a6702903f 100644 --- a/spec/ruby/core/module/const_get_spec.rb +++ b/spec/ruby/core/module/const_get_spec.rb @@ -9,28 +9,28 @@ describe "Module#const_get" do end it "raises a NameError if no constant is defined in the search path" do - lambda { ConstantSpecs.const_get :CS_CONSTX }.should raise_error(NameError) + -> { ConstantSpecs.const_get :CS_CONSTX }.should raise_error(NameError) end it "raises a NameError with the not found constant symbol" do - error_inspection = lambda { |e| e.name.should == :CS_CONSTX } - lambda { ConstantSpecs.const_get :CS_CONSTX }.should raise_error(NameError, &error_inspection) + error_inspection = -> e { e.name.should == :CS_CONSTX } + -> { ConstantSpecs.const_get :CS_CONSTX }.should raise_error(NameError, &error_inspection) end it "raises a NameError if the name does not start with a capital letter" do - lambda { ConstantSpecs.const_get "name" }.should raise_error(NameError) + -> { ConstantSpecs.const_get "name" }.should raise_error(NameError) end it "raises a NameError if the name starts with a non-alphabetic character" do - lambda { ConstantSpecs.const_get "__CONSTX__" }.should raise_error(NameError) - lambda { ConstantSpecs.const_get "@CS_CONST1" }.should raise_error(NameError) - lambda { ConstantSpecs.const_get "!CS_CONST1" }.should raise_error(NameError) + -> { ConstantSpecs.const_get "__CONSTX__" }.should raise_error(NameError) + -> { ConstantSpecs.const_get "@CS_CONST1" }.should raise_error(NameError) + -> { ConstantSpecs.const_get "!CS_CONST1" }.should raise_error(NameError) end it "raises a NameError if the name contains non-alphabetic characters except '_'" do Object.const_get("CS_CONST1").should == :const1 - lambda { ConstantSpecs.const_get "CS_CONST1=" }.should raise_error(NameError) - lambda { ConstantSpecs.const_get "CS_CONST1?" }.should raise_error(NameError) + -> { ConstantSpecs.const_get "CS_CONST1=" }.should raise_error(NameError) + -> { ConstantSpecs.const_get "CS_CONST1?" }.should raise_error(NameError) end it "calls #to_str to convert the given name to a String" do @@ -41,10 +41,10 @@ describe "Module#const_get" do it "raises a TypeError if conversion to a String by calling #to_str fails" do name = mock('123') - lambda { ConstantSpecs.const_get(name) }.should raise_error(TypeError) + -> { ConstantSpecs.const_get(name) }.should raise_error(TypeError) name.should_receive(:to_str).and_return(123) - lambda { ConstantSpecs.const_get(name) }.should raise_error(TypeError) + -> { ConstantSpecs.const_get(name) }.should raise_error(TypeError) end it "calls #const_missing on the receiver if unable to locate the constant" do @@ -53,21 +53,21 @@ describe "Module#const_get" do end it "does not search the singleton class of a Class or Module" do - lambda do + -> do ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST14) end.should raise_error(NameError) - lambda { ConstantSpecs.const_get(:CS_CONST14) }.should raise_error(NameError) + -> { ConstantSpecs.const_get(:CS_CONST14) }.should raise_error(NameError) end it "does not search the containing scope" do ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST20).should == :const20_2 - lambda do + -> do ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST5) end.should raise_error(NameError) end it "raises a NameError if the constant is defined in the receiver's superclass and the inherit flag is false" do - lambda do + -> do ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, false) end.should raise_error(NameError) end @@ -77,13 +77,13 @@ describe "Module#const_get" do end it "raises a NameError when the receiver is a Module, the constant is defined at toplevel and the inherit flag is false" do - lambda do + -> do ConstantSpecs::ModuleA.const_get(:CS_CONST1, false) end.should raise_error(NameError) end it "raises a NameError when the receiver is a Class, the constant is defined at toplevel and the inherit flag is false" do - lambda do + -> do ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST1, false) end.should raise_error(NameError) end @@ -97,19 +97,19 @@ describe "Module#const_get" do end it "raises a NameError if the name includes two successive scope separators" do - lambda { ConstantSpecs.const_get("ClassA::::CS_CONST10") }.should raise_error(NameError) + -> { ConstantSpecs.const_get("ClassA::::CS_CONST10") }.should raise_error(NameError) end it "raises a NameError if only '::' is passed" do - lambda { ConstantSpecs.const_get("::") }.should raise_error(NameError) + -> { ConstantSpecs.const_get("::") }.should raise_error(NameError) end it "raises a NameError if a Symbol has a toplevel scope qualifier" do - lambda { ConstantSpecs.const_get(:'::CS_CONST1') }.should raise_error(NameError) + -> { ConstantSpecs.const_get(:'::CS_CONST1') }.should raise_error(NameError) end it "raises a NameError if a Symbol is a scoped constant name" do - lambda { ConstantSpecs.const_get(:'ClassA::CS_CONST10') }.should raise_error(NameError) + -> { ConstantSpecs.const_get(:'ClassA::CS_CONST10') }.should raise_error(NameError) end it "does read private constants" do @@ -220,7 +220,7 @@ describe "Module#const_get" do ConstantSpecs::ClassB::CS_CONST309 = :const309_1 ConstantSpecs::ClassB.const_get(:CS_CONST309).should == :const309_1 - lambda { + -> { ConstantSpecs::ClassB::CS_CONST309 = :const309_2 }.should complain(/already initialized constant/) ConstantSpecs::ClassB.const_get(:CS_CONST309).should == :const309_2 diff --git a/spec/ruby/core/module/const_missing_spec.rb b/spec/ruby/core/module/const_missing_spec.rb index 930fe63f8b..742218281c 100644 --- a/spec/ruby/core/module/const_missing_spec.rb +++ b/spec/ruby/core/module/const_missing_spec.rb @@ -11,7 +11,7 @@ describe "Module#const_missing" do end it "raises NameError and includes the name of the value that wasn't found" do - lambda { + -> { ConstantSpecs.const_missing("HelloMissing") }.should raise_error(NameError, /ConstantSpecs::HelloMissing/) end diff --git a/spec/ruby/core/module/const_set_spec.rb b/spec/ruby/core/module/const_set_spec.rb index 25d22ffaba..1b8b86dd04 100644 --- a/spec/ruby/core/module/const_set_spec.rb +++ b/spec/ruby/core/module/const_set_spec.rb @@ -41,20 +41,20 @@ describe "Module#const_set" do end it "raises a NameError if the name does not start with a capital letter" do - lambda { ConstantSpecs.const_set "name", 1 }.should raise_error(NameError) + -> { ConstantSpecs.const_set "name", 1 }.should raise_error(NameError) end it "raises a NameError if the name starts with a non-alphabetic character" do - lambda { ConstantSpecs.const_set "__CONSTX__", 1 }.should raise_error(NameError) - lambda { ConstantSpecs.const_set "@Name", 1 }.should raise_error(NameError) - lambda { ConstantSpecs.const_set "!Name", 1 }.should raise_error(NameError) - lambda { ConstantSpecs.const_set "::Name", 1 }.should raise_error(NameError) + -> { ConstantSpecs.const_set "__CONSTX__", 1 }.should raise_error(NameError) + -> { ConstantSpecs.const_set "@Name", 1 }.should raise_error(NameError) + -> { ConstantSpecs.const_set "!Name", 1 }.should raise_error(NameError) + -> { ConstantSpecs.const_set "::Name", 1 }.should raise_error(NameError) end it "raises a NameError if the name contains non-alphabetic characters except '_'" do ConstantSpecs.const_set("CS_CONST404", :const404).should == :const404 - lambda { ConstantSpecs.const_set "Name=", 1 }.should raise_error(NameError) - lambda { ConstantSpecs.const_set "Name?", 1 }.should raise_error(NameError) + -> { ConstantSpecs.const_set "Name=", 1 }.should raise_error(NameError) + -> { ConstantSpecs.const_set "Name?", 1 }.should raise_error(NameError) end it "calls #to_str to convert the given name to a String" do @@ -66,10 +66,10 @@ describe "Module#const_set" do it "raises a TypeError if conversion to a String by calling #to_str fails" do name = mock('123') - lambda { ConstantSpecs.const_set name, 1 }.should raise_error(TypeError) + -> { ConstantSpecs.const_set name, 1 }.should raise_error(TypeError) name.should_receive(:to_str).and_return(123) - lambda { ConstantSpecs.const_set name, 1 }.should raise_error(TypeError) + -> { ConstantSpecs.const_set name, 1 }.should raise_error(TypeError) end describe "when overwriting an existing constant" do @@ -126,7 +126,7 @@ describe "Module#const_set" do end it "raises a #{frozen_error_class} before setting the name" do - lambda { @frozen.const_set @name, nil }.should raise_error(frozen_error_class) + -> { @frozen.const_set @name, nil }.should raise_error(frozen_error_class) @frozen.should_not have_constant(@name) end end diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb index 3f35c051a1..29394e5b92 100644 --- a/spec/ruby/core/module/define_method_spec.rb +++ b/spec/ruby/core/module/define_method_spec.rb @@ -12,7 +12,7 @@ describe "passed { |a, b = 1| } creates a method that" do end it "raises an ArgumentError when passed zero arguments" do - lambda { @klass.new.m }.should raise_error(ArgumentError) + -> { @klass.new.m }.should raise_error(ArgumentError) end it "has a default value for b when passed one argument" do @@ -24,7 +24,7 @@ describe "passed { |a, b = 1| } creates a method that" do end it "raises an ArgumentError when passed three arguments" do - lambda { @klass.new.m(1, 2, 3) }.should raise_error(ArgumentError) + -> { @klass.new.m(1, 2, 3) }.should raise_error(ArgumentError) end end @@ -83,7 +83,7 @@ describe "Module#define_method when given an UnboundMethod" do define_method :piggy, instance_method(:ziggy) end - lambda { foo.new.ziggy }.should raise_error(NoMethodError) + -> { foo.new.ziggy }.should raise_error(NoMethodError) foo.new.piggy.should == 'piggy' end end @@ -194,7 +194,7 @@ describe "Module#define_method" do it "defines a new method with the given name and the given block as body in self" do class DefineMethodSpecClass define_method(:block_test1) { self } - define_method(:block_test2, &lambda { self }) + define_method(:block_test2, &-> { self }) end o = DefineMethodSpecClass.new @@ -203,21 +203,21 @@ describe "Module#define_method" do end it "raises a TypeError when the given method is no Method/Proc" do - lambda { + -> { Class.new { define_method(:test, "self") } }.should raise_error(TypeError) - lambda { + -> { Class.new { define_method(:test, 1234) } }.should raise_error(TypeError) - lambda { + -> { Class.new { define_method(:test, nil) } }.should raise_error(TypeError) end it "raises an ArgumentError when no block is given" do - lambda { + -> { Class.new { define_method(:test) } }.should raise_error(ArgumentError) end @@ -230,7 +230,7 @@ describe "Module#define_method" do end end - lambda { + -> { o.define(:foo) { raise "not used" } }.should raise_error(ArgumentError) end @@ -242,11 +242,11 @@ describe "Module#define_method" do end obj = DefineMethodSpecClass.new - lambda { obj.proc_style_test :arg }.should raise_error(ArgumentError) + -> { obj.proc_style_test :arg }.should raise_error(ArgumentError) end it "raises a #{frozen_error_class} if frozen" do - lambda { + -> { Class.new { freeze; define_method(:foo) {} } }.should raise_error(frozen_error_class) end @@ -267,7 +267,7 @@ describe "Module#define_method" do c = klass.new c.data = :bar c.other_inspect.should == "data is bar" - lambda{o.other_inspect}.should raise_error(NoMethodError) + ->{o.other_inspect}.should raise_error(NoMethodError) end it "raises a TypeError when a Method from a singleton class is defined on another class" do @@ -279,9 +279,9 @@ describe "Module#define_method" do end m = c.method(:foo) - lambda { + -> { Class.new { define_method :bar, m } - }.should raise_error(TypeError) + }.should raise_error(TypeError, /can't bind singleton method to a different class/) end it "raises a TypeError when a Method from one class is defined on an unrelated class" do @@ -291,7 +291,7 @@ describe "Module#define_method" do end m = c.new.method(:foo) - lambda { + -> { Class.new { define_method :bar, m } }.should raise_error(TypeError) end @@ -305,7 +305,7 @@ describe "Module#define_method" do o = DefineMethodSpecClass.new DefineMethodSpecClass.send(:undef_method, :accessor_method) - lambda { o.accessor_method }.should raise_error(NoMethodError) + -> { o.accessor_method }.should raise_error(NoMethodError) DefineMethodSpecClass.send(:define_method, :accessor_method, m) @@ -396,20 +396,42 @@ describe "Module#define_method" do klass.new.should respond_to(:bar) end + + it "allows an UnboundMethod of a Kernel method retrieved from Object to defined on a BasicObject subclass" do + klass = Class.new(BasicObject) do + define_method :instance_of?, ::Object.instance_method(:instance_of?) + end + klass.new.instance_of?(klass).should == true + end + it "raises a TypeError when an UnboundMethod from a child class is defined on a parent class" do - lambda { + -> { ParentClass = Class.new { define_method(:foo) { :bar } } ChildClass = Class.new(ParentClass) { define_method(:foo) { :baz } } ParentClass.send :define_method, :foo, ChildClass.instance_method(:foo) - }.should raise_error(TypeError) + }.should raise_error(TypeError, /bind argument must be a subclass of ChildClass/) end it "raises a TypeError when an UnboundMethod from one class is defined on an unrelated class" do - lambda { + -> { DestinationClass = Class.new { define_method :bar, ModuleSpecs::InstanceMeth.instance_method(:foo) } - }.should raise_error(TypeError) + }.should raise_error(TypeError, /bind argument must be a subclass of ModuleSpecs::InstanceMeth/) + end + + it "raises a TypeError when an UnboundMethod from a singleton class is defined on another class" do + c = Class.new do + class << self + def foo + end + end + end + m = c.method(:foo).unbind + + -> { + Class.new { define_method :bar, m } + }.should raise_error(TypeError, /can't bind singleton method to a different class/) end end @@ -426,11 +448,11 @@ describe "Module#define_method" do end it "raises an ArgumentError when passed one argument" do - lambda { @klass.new.m 1 }.should raise_error(ArgumentError) + -> { @klass.new.m 1 }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed two arguments" do - lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError) + -> { @klass.new.m 1, 2 }.should raise_error(ArgumentError) end end @@ -446,11 +468,11 @@ describe "Module#define_method" do end it "raises an ArgumentError when passed one argument" do - lambda { @klass.new.m 1 }.should raise_error(ArgumentError) + -> { @klass.new.m 1 }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed two arguments" do - lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError) + -> { @klass.new.m 1, 2 }.should raise_error(ArgumentError) end end @@ -462,15 +484,15 @@ describe "Module#define_method" do end it "raises an ArgumentError when passed zero arguments" do - lambda { @klass.new.m }.should raise_error(ArgumentError) + -> { @klass.new.m }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed zero arguments and a block" do - lambda { @klass.new.m { :computed } }.should raise_error(ArgumentError) + -> { @klass.new.m { :computed } }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed two arguments" do - lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError) + -> { @klass.new.m 1, 2 }.should raise_error(ArgumentError) end it "receives the value passed as the argument when passed one argument" do @@ -507,7 +529,7 @@ describe "Module#define_method" do end it "raises an ArgumentError when passed zero arguments" do - lambda { @klass.new.m }.should raise_error(ArgumentError) + -> { @klass.new.m }.should raise_error(ArgumentError) end it "returns the value computed by the block when passed one argument" do @@ -535,19 +557,19 @@ describe "Module#define_method" do end it "raises an ArgumentError when passed zero arguments" do - lambda { @klass.new.m }.should raise_error(ArgumentError) + -> { @klass.new.m }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed one argument" do - lambda { @klass.new.m 1 }.should raise_error(ArgumentError) + -> { @klass.new.m 1 }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed one argument and a block" do - lambda { @klass.new.m(1) { } }.should raise_error(ArgumentError) + -> { @klass.new.m(1) { } }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed three arguments" do - lambda { @klass.new.m 1, 2, 3 }.should raise_error(ArgumentError) + -> { @klass.new.m 1, 2, 3 }.should raise_error(ArgumentError) end end @@ -559,15 +581,15 @@ describe "Module#define_method" do end it "raises an ArgumentError when passed zero arguments" do - lambda { @klass.new.m }.should raise_error(ArgumentError) + -> { @klass.new.m }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed one argument" do - lambda { @klass.new.m 1 }.should raise_error(ArgumentError) + -> { @klass.new.m 1 }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed one argument and a block" do - lambda { @klass.new.m(1) { } }.should raise_error(ArgumentError) + -> { @klass.new.m(1) { } }.should raise_error(ArgumentError) end it "receives an empty array as the third argument when passed two arguments" do diff --git a/spec/ruby/core/module/define_singleton_method_spec.rb b/spec/ruby/core/module/define_singleton_method_spec.rb index f2b8a5ada4..eb5cb89ed1 100644 --- a/spec/ruby/core/module/define_singleton_method_spec.rb +++ b/spec/ruby/core/module/define_singleton_method_spec.rb @@ -6,7 +6,7 @@ describe "Module#define_singleton_method" do define_singleton_method :a do 42 end - define_singleton_method(:b, lambda {|x| 2*x }) + define_singleton_method(:b, -> x { 2*x }) end klass.a.should == 42 diff --git a/spec/ruby/core/module/deprecate_constant_spec.rb b/spec/ruby/core/module/deprecate_constant_spec.rb index 0954a6d8a5..7bcced981b 100644 --- a/spec/ruby/core/module/deprecate_constant_spec.rb +++ b/spec/ruby/core/module/deprecate_constant_spec.rb @@ -17,27 +17,27 @@ describe "Module#deprecate_constant" do @module.deprecate_constant :PUBLIC1 value = nil - lambda { + -> { value = @module::PUBLIC1 }.should complain(@pattern) value.should equal(@value) - lambda { @module::PRIVATE }.should raise_error(NameError) + -> { @module::PRIVATE }.should raise_error(NameError) end it "warns with a message" do @module.deprecate_constant :PUBLIC1 - lambda { @module::PUBLIC1 }.should complain(@pattern) - lambda { @module.const_get :PRIVATE }.should complain(@pattern) + -> { @module::PUBLIC1 }.should complain(@pattern) + -> { @module.const_get :PRIVATE }.should complain(@pattern) end end it "accepts multiple symbols and strings as constant names" do @module.deprecate_constant "PUBLIC1", :PUBLIC2 - lambda { @module::PUBLIC1 }.should complain(@pattern) - lambda { @module::PUBLIC2 }.should complain(@pattern) + -> { @module::PUBLIC1 }.should complain(@pattern) + -> { @module::PUBLIC2 }.should complain(@pattern) end it "returns self" do @@ -45,6 +45,6 @@ describe "Module#deprecate_constant" do end it "raises a NameError when given an undefined name" do - lambda { @module.deprecate_constant :UNDEFINED }.should raise_error(NameError) + -> { @module.deprecate_constant :UNDEFINED }.should raise_error(NameError) end end diff --git a/spec/ruby/core/module/extend_object_spec.rb b/spec/ruby/core/module/extend_object_spec.rb index df16f03ea0..bc97a55e7c 100644 --- a/spec/ruby/core/module/extend_object_spec.rb +++ b/spec/ruby/core/module/extend_object_spec.rb @@ -16,7 +16,7 @@ describe "Module#extend_object" do end it "raises a TypeError if calling after rebinded to Class" do - lambda { + -> { Module.instance_method(:extend_object).bind(Class.new).call Object.new }.should raise_error(TypeError) end @@ -61,7 +61,7 @@ describe "Module#extend_object" do end it "raises a RuntimeError before extending the object" do - lambda { @receiver.send(:extend_object, @object) }.should raise_error(RuntimeError) + -> { @receiver.send(:extend_object, @object) }.should raise_error(RuntimeError) @object.should_not be_kind_of(@receiver) end end diff --git a/spec/ruby/core/module/gt_spec.rb b/spec/ruby/core/module/gt_spec.rb index adab89a78b..b8a73c9ff9 100644 --- a/spec/ruby/core/module/gt_spec.rb +++ b/spec/ruby/core/module/gt_spec.rb @@ -31,6 +31,6 @@ describe "Module#>" do end it "raises a TypeError if the argument is not a class/module" do - lambda { ModuleSpecs::Parent > mock('x') }.should raise_error(TypeError) + -> { ModuleSpecs::Parent > mock('x') }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/module/gte_spec.rb b/spec/ruby/core/module/gte_spec.rb index 945721fe6b..18c60ba586 100644 --- a/spec/ruby/core/module/gte_spec.rb +++ b/spec/ruby/core/module/gte_spec.rb @@ -28,6 +28,6 @@ describe "Module#>=" do end it "raises a TypeError if the argument is not a class/module" do - lambda { ModuleSpecs::Parent >= mock('x') }.should raise_error(TypeError) + -> { ModuleSpecs::Parent >= mock('x') }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/module/include_spec.rb b/spec/ruby/core/module/include_spec.rb index ece86bfe00..e7f99a5981 100644 --- a/spec/ruby/core/module/include_spec.rb +++ b/spec/ruby/core/module/include_spec.rb @@ -40,11 +40,11 @@ describe "Module#include" do end it "raises a TypeError when the argument is not a Module" do - lambda { ModuleSpecs::Basic.include(Class.new) }.should raise_error(TypeError) + -> { ModuleSpecs::Basic.include(Class.new) }.should raise_error(TypeError) end it "does not raise a TypeError when the argument is an instance of a subclass of Module" do - lambda { ModuleSpecs::SubclassSpec.include(ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError) + -> { ModuleSpecs::SubclassSpec.include(ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError) end it "imports constants to modules and classes" do @@ -158,7 +158,7 @@ describe "Module#include" do end it "detects cyclic includes" do - lambda { + -> { module ModuleSpecs::M include ModuleSpecs::M end @@ -166,7 +166,7 @@ describe "Module#include" do end it "doesn't accept no-arguments" do - lambda { + -> { Module.new do include end @@ -252,7 +252,7 @@ describe "Module#include?" do end it "raises a TypeError when no module was given" do - lambda { ModuleSpecs::Child.include?("Test") }.should raise_error(TypeError) - lambda { ModuleSpecs::Child.include?(ModuleSpecs::Parent) }.should raise_error(TypeError) + -> { ModuleSpecs::Child.include?("Test") }.should raise_error(TypeError) + -> { ModuleSpecs::Child.include?(ModuleSpecs::Parent) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/module/instance_method_spec.rb b/spec/ruby/core/module/instance_method_spec.rb index 9328df9179..b4d6a0d8c8 100644 --- a/spec/ruby/core/module/instance_method_spec.rb +++ b/spec/ruby/core/module/instance_method_spec.rb @@ -52,13 +52,13 @@ describe "Module#instance_method" do end it "raises a TypeError if not passed a symbol" do - lambda { Object.instance_method([]) }.should raise_error(TypeError) - lambda { Object.instance_method(0) }.should raise_error(TypeError) + -> { Object.instance_method([]) }.should raise_error(TypeError) + -> { Object.instance_method(0) }.should raise_error(TypeError) end it "raises a TypeError if the given name is not a string/symbol" do - lambda { Object.instance_method(nil) }.should raise_error(TypeError) - lambda { Object.instance_method(mock('x')) }.should raise_error(TypeError) + -> { Object.instance_method(nil) }.should raise_error(TypeError) + -> { Object.instance_method(mock('x')) }.should raise_error(TypeError) end it "raises a NameError if the method has been undefined" do @@ -66,13 +66,13 @@ describe "Module#instance_method" do child.send :undef_method, :foo um = ModuleSpecs::InstanceMeth.instance_method(:foo) um.should == @parent_um - lambda do + -> do child.instance_method(:foo) end.should raise_error(NameError) end it "raises a NameError if the method does not exist" do - lambda { Object.instance_method(:missing) }.should raise_error(NameError) + -> { Object.instance_method(:missing) }.should raise_error(NameError) end it "sets the NameError#name attribute to the name of the missing method" do diff --git a/spec/ruby/core/module/lt_spec.rb b/spec/ruby/core/module/lt_spec.rb index 1fd528a54e..d7771e07a8 100644 --- a/spec/ruby/core/module/lt_spec.rb +++ b/spec/ruby/core/module/lt_spec.rb @@ -31,6 +31,6 @@ describe "Module#<" do end it "raises a TypeError if the argument is not a class/module" do - lambda { ModuleSpecs::Parent < mock('x') }.should raise_error(TypeError) + -> { ModuleSpecs::Parent < mock('x') }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/module/lte_spec.rb b/spec/ruby/core/module/lte_spec.rb index b8252cfe55..7a0e8496b8 100644 --- a/spec/ruby/core/module/lte_spec.rb +++ b/spec/ruby/core/module/lte_spec.rb @@ -28,6 +28,6 @@ describe "Module#<=" do end it "raises a TypeError if the argument is not a class/module" do - lambda { ModuleSpecs::Parent <= mock('x') }.should raise_error(TypeError) + -> { ModuleSpecs::Parent <= mock('x') }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/module/method_defined_spec.rb b/spec/ruby/core/module/method_defined_spec.rb index f5203917b4..c2a8702d97 100644 --- a/spec/ruby/core/module/method_defined_spec.rb +++ b/spec/ruby/core/module/method_defined_spec.rb @@ -34,10 +34,10 @@ describe "Module#method_defined?" do c = Class.new o = mock('123') - lambda { c.method_defined?(o) }.should raise_error(TypeError) + -> { c.method_defined?(o) }.should raise_error(TypeError) o.should_receive(:to_str).and_return(123) - lambda { c.method_defined?(o) }.should raise_error(TypeError) + -> { c.method_defined?(o) }.should raise_error(TypeError) end it "converts the given name to a string using to_str" do diff --git a/spec/ruby/core/module/module_function_spec.rb b/spec/ruby/core/module/module_function_spec.rb index 41d52849fd..407237d48f 100644 --- a/spec/ruby/core/module/module_function_spec.rb +++ b/spec/ruby/core/module/module_function_spec.rb @@ -12,11 +12,11 @@ describe "Module#module_function" do end it "raises a TypeError if calling after rebinded to Class" do - lambda { + -> { Module.instance_method(:module_function).bind(Class.new).call }.should raise_error(TypeError) - lambda { + -> { Module.instance_method(:module_function).bind(Class.new).call :foo }.should raise_error(TypeError) end @@ -87,7 +87,7 @@ describe "Module#module_function with specific method names" do o.respond_to?(:test).should == false m.should have_private_instance_method(:test) o.send(:test).should == "hello" - lambda { o.test }.should raise_error(NoMethodError) + -> { o.test }.should raise_error(NoMethodError) end it "makes the new Module methods public" do @@ -116,10 +116,10 @@ describe "Module#module_function with specific method names" do it "raises a TypeError when the given names can't be converted to string using to_str" do o = mock('123') - lambda { Module.new { module_function(o) } }.should raise_error(TypeError) + -> { Module.new { module_function(o) } }.should raise_error(TypeError) o.should_receive(:to_str).and_return(123) - lambda { Module.new { module_function(o) } }.should raise_error(TypeError) + -> { Module.new { module_function(o) } }.should raise_error(TypeError) end it "can make accessible private methods" do # JRUBY-4214 diff --git a/spec/ruby/core/module/prepend_features_spec.rb b/spec/ruby/core/module/prepend_features_spec.rb index 2779073e9c..b6fce9aba0 100644 --- a/spec/ruby/core/module/prepend_features_spec.rb +++ b/spec/ruby/core/module/prepend_features_spec.rb @@ -23,7 +23,7 @@ describe "Module#prepend_features" do end it "raises an ArgumentError on a cyclic prepend" do - lambda { + -> { ModuleSpecs::CyclicPrepend.send(:prepend_features, ModuleSpecs::CyclicPrepend) }.should raise_error(ArgumentError) end @@ -68,7 +68,7 @@ describe "Module#prepend_features" do end it "raises a TypeError if calling after rebinded to Class" do - lambda { + -> { Module.instance_method(:prepend_features).bind(Class.new).call Module.new }.should raise_error(TypeError) end diff --git a/spec/ruby/core/module/prepend_spec.rb b/spec/ruby/core/module/prepend_spec.rb index b186381640..e143f51673 100644 --- a/spec/ruby/core/module/prepend_spec.rb +++ b/spec/ruby/core/module/prepend_spec.rb @@ -37,11 +37,11 @@ describe "Module#prepend" do end it "raises a TypeError when the argument is not a Module" do - lambda { ModuleSpecs::Basic.prepend(Class.new) }.should raise_error(TypeError) + -> { ModuleSpecs::Basic.prepend(Class.new) }.should raise_error(TypeError) end it "does not raise a TypeError when the argument is an instance of a subclass of Module" do - lambda { ModuleSpecs::SubclassSpec.prepend(ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError) + -> { ModuleSpecs::SubclassSpec.prepend(ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError) end it "imports constants" do @@ -204,7 +204,7 @@ describe "Module#prepend" do super << :class end end - lambda { c.new.chain }.should raise_error(NoMethodError) + -> { c.new.chain }.should raise_error(NoMethodError) end it "calls prepended after prepend_features" do @@ -224,7 +224,7 @@ describe "Module#prepend" do end it "detects cyclic prepends" do - lambda { + -> { module ModuleSpecs::P prepend ModuleSpecs::P end @@ -232,7 +232,7 @@ describe "Module#prepend" do end it "doesn't accept no-arguments" do - lambda { + -> { Module.new do prepend end diff --git a/spec/ruby/core/module/private_class_method_spec.rb b/spec/ruby/core/module/private_class_method_spec.rb index 73275b0e6b..e35b50d986 100644 --- a/spec/ruby/core/module/private_class_method_spec.rb +++ b/spec/ruby/core/module/private_class_method_spec.rb @@ -22,11 +22,11 @@ describe "Module#private_class_method" do it "makes an existing class method private" do ModuleSpecs::Parent.private_method_1.should == nil ModuleSpecs::Parent.private_class_method :private_method_1 - lambda { ModuleSpecs::Parent.private_method_1 }.should raise_error(NoMethodError) + -> { ModuleSpecs::Parent.private_method_1 }.should raise_error(NoMethodError) # Technically above we're testing the Singleton classes, class method(right?). # Try a "real" class method set private. - lambda { ModuleSpecs::Parent.private_method }.should raise_error(NoMethodError) + -> { ModuleSpecs::Parent.private_method }.should raise_error(NoMethodError) end it "makes an existing class method private up the inheritance tree" do @@ -34,8 +34,8 @@ describe "Module#private_class_method" do ModuleSpecs::Child.private_method_1.should == nil ModuleSpecs::Child.private_class_method :private_method_1 - lambda { ModuleSpecs::Child.private_method_1 }.should raise_error(NoMethodError) - lambda { ModuleSpecs::Child.private_method }.should raise_error(NoMethodError) + -> { ModuleSpecs::Child.private_method_1 }.should raise_error(NoMethodError) + -> { ModuleSpecs::Child.private_method }.should raise_error(NoMethodError) end it "accepts more than one method at a time" do @@ -44,12 +44,12 @@ describe "Module#private_class_method" do ModuleSpecs::Child.private_class_method :private_method_1, :private_method_2 - lambda { ModuleSpecs::Child.private_method_1 }.should raise_error(NoMethodError) - lambda { ModuleSpecs::Child.private_method_2 }.should raise_error(NoMethodError) + -> { ModuleSpecs::Child.private_method_1 }.should raise_error(NoMethodError) + -> { ModuleSpecs::Child.private_method_2 }.should raise_error(NoMethodError) end it "raises a NameError if class method doesn't exist" do - lambda do + -> do ModuleSpecs.private_class_method :no_method_here end.should raise_error(NameError) end @@ -59,11 +59,11 @@ describe "Module#private_class_method" do def self.foo() "foo" end private_class_method :foo end - lambda { c.foo }.should raise_error(NoMethodError) + -> { c.foo }.should raise_error(NoMethodError) end it "raises a NameError when the given name is not a method" do - lambda do + -> do Class.new do private_class_method :foo end @@ -71,7 +71,7 @@ describe "Module#private_class_method" do end it "raises a NameError when the given name is an instance method" do - lambda do + -> do Class.new do def foo() "foo" end private_class_method :foo diff --git a/spec/ruby/core/module/private_constant_spec.rb b/spec/ruby/core/module/private_constant_spec.rb index 45aaec6c26..3a91b3c3cd 100644 --- a/spec/ruby/core/module/private_constant_spec.rb +++ b/spec/ruby/core/module/private_constant_spec.rb @@ -6,7 +6,7 @@ describe "Module#private_constant" do cls1.const_set :Foo, true cls2 = Class.new(cls1) - lambda do + -> do cls2.send :private_constant, :Foo end.should raise_error(NameError) end @@ -16,7 +16,7 @@ describe "Module#private_constant" do cls.const_set :Foo, true cls.send :private_constant, "Foo" - lambda { cls::Foo }.should raise_error(NameError) + -> { cls::Foo }.should raise_error(NameError) end it "accepts multiple names" do @@ -26,7 +26,7 @@ describe "Module#private_constant" do mod.send :private_constant, :Foo, :Bar - lambda {mod::Foo}.should raise_error(NameError) - lambda {mod::Bar}.should raise_error(NameError) + -> {mod::Foo}.should raise_error(NameError) + -> {mod::Bar}.should raise_error(NameError) end end diff --git a/spec/ruby/core/module/private_method_defined_spec.rb b/spec/ruby/core/module/private_method_defined_spec.rb index a3cf55852e..515542d9df 100644 --- a/spec/ruby/core/module/private_method_defined_spec.rb +++ b/spec/ruby/core/module/private_method_defined_spec.rb @@ -32,25 +32,25 @@ describe "Module#private_method_defined?" do end it "raises a TypeError if passed a Fixnum" do - lambda do + -> do ModuleSpecs::CountsMixin.private_method_defined?(1) end.should raise_error(TypeError) end it "raises a TypeError if passed nil" do - lambda do + -> do ModuleSpecs::CountsMixin.private_method_defined?(nil) end.should raise_error(TypeError) end it "raises a TypeError if passed false" do - lambda do + -> do ModuleSpecs::CountsMixin.private_method_defined?(false) end.should raise_error(TypeError) end it "raises a TypeError if passed an object that does not defined #to_str" do - lambda do + -> do ModuleSpecs::CountsMixin.private_method_defined?(mock('x')) end.should raise_error(TypeError) end @@ -59,7 +59,7 @@ describe "Module#private_method_defined?" do sym = mock('symbol') def sym.to_sym() :private_3 end - lambda do + -> do ModuleSpecs::CountsMixin.private_method_defined?(sym) end.should raise_error(TypeError) end diff --git a/spec/ruby/core/module/private_spec.rb b/spec/ruby/core/module/private_spec.rb index 5d85c34855..e893c24f38 100644 --- a/spec/ruby/core/module/private_spec.rb +++ b/spec/ruby/core/module/private_spec.rb @@ -17,7 +17,7 @@ describe "Module#private" do private :foo end - lambda { obj.foo }.should raise_error(NoMethodError) + -> { obj.foo }.should raise_error(NoMethodError) end it "makes a public Object instance method private in a new module" do @@ -47,7 +47,7 @@ describe "Module#private" do end it "raises a NameError when given an undefined name" do - lambda do + -> do Module.new.send(:private, :undefined) end.should raise_error(NameError) end @@ -67,7 +67,7 @@ describe "Module#private" do end base.new.wrapped.should == 1 - lambda do + -> do klass.new.wrapped end.should raise_error(NameError) end diff --git a/spec/ruby/core/module/protected_method_defined_spec.rb b/spec/ruby/core/module/protected_method_defined_spec.rb index 75e02e0433..7be7bdd3c9 100644 --- a/spec/ruby/core/module/protected_method_defined_spec.rb +++ b/spec/ruby/core/module/protected_method_defined_spec.rb @@ -32,25 +32,25 @@ describe "Module#protected_method_defined?" do end it "raises a TypeError if passed a Fixnum" do - lambda do + -> do ModuleSpecs::CountsMixin.protected_method_defined?(1) end.should raise_error(TypeError) end it "raises a TypeError if passed nil" do - lambda do + -> do ModuleSpecs::CountsMixin.protected_method_defined?(nil) end.should raise_error(TypeError) end it "raises a TypeError if passed false" do - lambda do + -> do ModuleSpecs::CountsMixin.protected_method_defined?(false) end.should raise_error(TypeError) end it "raises a TypeError if passed an object that does not defined #to_str" do - lambda do + -> do ModuleSpecs::CountsMixin.protected_method_defined?(mock('x')) end.should raise_error(TypeError) end @@ -59,7 +59,7 @@ describe "Module#protected_method_defined?" do sym = mock('symbol') def sym.to_sym() :protected_3 end - lambda do + -> do ModuleSpecs::CountsMixin.protected_method_defined?(sym) end.should raise_error(TypeError) end diff --git a/spec/ruby/core/module/protected_spec.rb b/spec/ruby/core/module/protected_spec.rb index 985e4621c5..aa04a42fb8 100644 --- a/spec/ruby/core/module/protected_spec.rb +++ b/spec/ruby/core/module/protected_spec.rb @@ -18,7 +18,7 @@ describe "Module#protected" do protected :protected_method_1 end - lambda { ModuleSpecs::Parent.protected_method_1 }.should raise_error(NoMethodError) + -> { ModuleSpecs::Parent.protected_method_1 }.should raise_error(NoMethodError) end it "makes a public Object instance method protected in a new module" do @@ -48,7 +48,7 @@ describe "Module#protected" do end it "raises a NameError when given an undefined name" do - lambda do + -> do Module.new.send(:protected, :undefined) end.should raise_error(NameError) end diff --git a/spec/ruby/core/module/public_class_method_spec.rb b/spec/ruby/core/module/public_class_method_spec.rb index 7745ed1f86..c09cc64863 100644 --- a/spec/ruby/core/module/public_class_method_spec.rb +++ b/spec/ruby/core/module/public_class_method_spec.rb @@ -18,7 +18,7 @@ describe "Module#public_class_method" do end it "makes an existing class method public" do - lambda { ModuleSpecs::Parent.public_method_1 }.should raise_error(NoMethodError) + -> { ModuleSpecs::Parent.public_method_1 }.should raise_error(NoMethodError) ModuleSpecs::Parent.public_class_method :public_method_1 ModuleSpecs::Parent.public_method_1.should == nil @@ -29,7 +29,7 @@ describe "Module#public_class_method" do it "makes an existing class method public up the inheritance tree" do ModuleSpecs::Child.private_class_method :public_method_1 - lambda { ModuleSpecs::Child.public_method_1 }.should raise_error(NoMethodError) + -> { ModuleSpecs::Child.public_method_1 }.should raise_error(NoMethodError) ModuleSpecs::Child.public_class_method :public_method_1 ModuleSpecs::Child.public_method_1.should == nil @@ -37,8 +37,8 @@ describe "Module#public_class_method" do end it "accepts more than one method at a time" do - lambda { ModuleSpecs::Parent.public_method_1 }.should raise_error(NameError) - lambda { ModuleSpecs::Parent.public_method_2 }.should raise_error(NameError) + -> { ModuleSpecs::Parent.public_method_1 }.should raise_error(NameError) + -> { ModuleSpecs::Parent.public_method_2 }.should raise_error(NameError) ModuleSpecs::Child.public_class_method :public_method_1, :public_method_2 @@ -47,7 +47,7 @@ describe "Module#public_class_method" do end it "raises a NameError if class method doesn't exist" do - lambda do + -> do ModuleSpecs.public_class_method :no_method_here end.should raise_error(NameError) end @@ -62,7 +62,7 @@ describe "Module#public_class_method" do end it "raises a NameError when the given name is not a method" do - lambda do + -> do Class.new do public_class_method :foo end @@ -70,7 +70,7 @@ describe "Module#public_class_method" do end it "raises a NameError when the given name is an instance method" do - lambda do + -> do Class.new do def foo() "foo" end public_class_method :foo diff --git a/spec/ruby/core/module/public_constant_spec.rb b/spec/ruby/core/module/public_constant_spec.rb index b2e6a08a4e..e624d45fd2 100644 --- a/spec/ruby/core/module/public_constant_spec.rb +++ b/spec/ruby/core/module/public_constant_spec.rb @@ -6,7 +6,7 @@ describe "Module#public_constant" do cls1.const_set :Foo, true cls2 = Class.new(cls1) - lambda do + -> do cls2.send :public_constant, :Foo end.should raise_error(NameError) end diff --git a/spec/ruby/core/module/public_instance_method_spec.rb b/spec/ruby/core/module/public_instance_method_spec.rb index aee6c03cf2..ba19ad0404 100644 --- a/spec/ruby/core/module/public_instance_method_spec.rb +++ b/spec/ruby/core/module/public_instance_method_spec.rb @@ -28,29 +28,29 @@ describe "Module#public_instance_method" do end it "raises a TypeError when given a name is not Symbol or String" do - lambda { Module.new.public_instance_method(nil) }.should raise_error(TypeError) + -> { Module.new.public_instance_method(nil) }.should raise_error(TypeError) end it "raises a NameError when given a protected method name" do - lambda do + -> do ModuleSpecs::Basic.public_instance_method(:protected_module) end.should raise_error(NameError) end it "raises a NameError if the method is private" do - lambda do + -> do ModuleSpecs::Basic.public_instance_method(:private_module) end.should raise_error(NameError) end it "raises a NameError if the method has been undefined" do - lambda do + -> do ModuleSpecs::Parent.public_instance_method(:undefed_method) end.should raise_error(NameError) end it "raises a NameError if the method does not exist" do - lambda do + -> do Module.new.public_instance_method(:missing) end.should raise_error(NameError) end diff --git a/spec/ruby/core/module/public_method_defined_spec.rb b/spec/ruby/core/module/public_method_defined_spec.rb index 0d7d3e031c..d2fcfd1e72 100644 --- a/spec/ruby/core/module/public_method_defined_spec.rb +++ b/spec/ruby/core/module/public_method_defined_spec.rb @@ -32,25 +32,25 @@ describe "Module#public_method_defined?" do end it "raises a TypeError if passed a Fixnum" do - lambda do + -> do ModuleSpecs::CountsMixin.public_method_defined?(1) end.should raise_error(TypeError) end it "raises a TypeError if passed nil" do - lambda do + -> do ModuleSpecs::CountsMixin.public_method_defined?(nil) end.should raise_error(TypeError) end it "raises a TypeError if passed false" do - lambda do + -> do ModuleSpecs::CountsMixin.public_method_defined?(false) end.should raise_error(TypeError) end it "raises a TypeError if passed an object that does not defined #to_str" do - lambda do + -> do ModuleSpecs::CountsMixin.public_method_defined?(mock('x')) end.should raise_error(TypeError) end @@ -59,7 +59,7 @@ describe "Module#public_method_defined?" do sym = mock('symbol') def sym.to_sym() :public_3 end - lambda do + -> do ModuleSpecs::CountsMixin.public_method_defined?(sym) end.should raise_error(TypeError) end diff --git a/spec/ruby/core/module/public_spec.rb b/spec/ruby/core/module/public_spec.rb index a948a55e5e..e7059f6aa6 100644 --- a/spec/ruby/core/module/public_spec.rb +++ b/spec/ruby/core/module/public_spec.rb @@ -37,7 +37,7 @@ describe "Module#public" do end it "raises a NameError when given an undefined name" do - lambda do + -> do Module.new.send(:public, :undefined) end.should raise_error(NameError) end diff --git a/spec/ruby/core/module/refine_spec.rb b/spec/ruby/core/module/refine_spec.rb index 7a1b2fc5fc..66c19ddb66 100644 --- a/spec/ruby/core/module/refine_spec.rb +++ b/spec/ruby/core/module/refine_spec.rb @@ -59,7 +59,7 @@ describe "Module#refine" do end it "raises ArgumentError if not passed an argument" do - lambda do + -> do Module.new do refine {} end @@ -67,7 +67,7 @@ describe "Module#refine" do end it "raises TypeError if not passed a class" do - lambda do + -> do Module.new do refine("foo") {} end @@ -88,7 +88,7 @@ describe "Module#refine" do end it "raises ArgumentError if not given a block" do - lambda do + -> do Module.new do refine String end @@ -109,7 +109,7 @@ describe "Module#refine" do it "doesn't apply refinements outside the refine block" do Module.new do refine(String) {def foo; "foo"; end} - -> () { + -> { "hello".foo }.should raise_error(NoMethodError) end @@ -120,7 +120,7 @@ describe "Module#refine" do refine(String) {def foo; 'foo'; end} end - lambda {"hello".foo}.should raise_error(NoMethodError) + -> {"hello".foo}.should raise_error(NoMethodError) end # When defining multiple refinements in the same module, @@ -177,7 +177,7 @@ describe "Module#refine" do result = nil - -> () { + -> { Module.new do using refinery_integer using refinery_array @@ -575,7 +575,7 @@ describe "Module#refine" do refinement = Module.new do refine String do def to_proc(*args) - -> (*) { 'foo' } + -> * { 'foo' } end end end @@ -594,7 +594,7 @@ describe "Module#refine" do refinement = Module.new do refine String do def to_proc(*args) - -> (*) { 'foo' } + -> * { 'foo' } end end end @@ -689,7 +689,7 @@ describe "Module#refine" do } [1,2].orig_count.should == 2 end - lambda { [1,2].orig_count }.should raise_error(NoMethodError) + -> { [1,2].orig_count }.should raise_error(NoMethodError) end it 'and alias_method aliases a method within a refinement module, but not outside it' do @@ -701,7 +701,7 @@ describe "Module#refine" do } [1,2].orig_count.should == 2 end - lambda { [1,2].orig_count }.should raise_error(NoMethodError) + -> { [1,2].orig_count }.should raise_error(NoMethodError) end # Refinements are inherited by module inclusion. diff --git a/spec/ruby/core/module/remove_class_variable_spec.rb b/spec/ruby/core/module/remove_class_variable_spec.rb index e431243ab4..ab9514adf6 100644 --- a/spec/ruby/core/module/remove_class_variable_spec.rb +++ b/spec/ruby/core/module/remove_class_variable_spec.rb @@ -23,19 +23,19 @@ describe "Module#remove_class_variable" do it "raises a NameError when removing class variable declared in included module" do c = ModuleSpecs::RemoveClassVariable.new { include ModuleSpecs::MVars.dup } - lambda { c.send(:remove_class_variable, :@@mvar) }.should raise_error(NameError) + -> { c.send(:remove_class_variable, :@@mvar) }.should raise_error(NameError) end it "raises a NameError when passed a symbol with one leading @" do - lambda { ModuleSpecs::MVars.send(:remove_class_variable, :@mvar) }.should raise_error(NameError) + -> { ModuleSpecs::MVars.send(:remove_class_variable, :@mvar) }.should raise_error(NameError) end it "raises a NameError when passed a symbol with no leading @" do - lambda { ModuleSpecs::MVars.send(:remove_class_variable, :mvar) }.should raise_error(NameError) + -> { ModuleSpecs::MVars.send(:remove_class_variable, :mvar) }.should raise_error(NameError) end it "raises a NameError when an uninitialized class variable is given" do - lambda { ModuleSpecs::MVars.send(:remove_class_variable, :@@nonexisting_class_variable) }.should raise_error(NameError) + -> { ModuleSpecs::MVars.send(:remove_class_variable, :@@nonexisting_class_variable) }.should raise_error(NameError) end it "is public" do diff --git a/spec/ruby/core/module/remove_const_spec.rb b/spec/ruby/core/module/remove_const_spec.rb index 073e2c1501..20eb2dc3ed 100644 --- a/spec/ruby/core/module/remove_const_spec.rb +++ b/spec/ruby/core/module/remove_const_spec.rb @@ -7,13 +7,13 @@ describe "Module#remove_const" do ConstantSpecs::ModuleM::CS_CONST252.should == :const252 ConstantSpecs::ModuleM.send :remove_const, :CS_CONST252 - lambda { ConstantSpecs::ModuleM::CS_CONST252 }.should raise_error(NameError) + -> { ConstantSpecs::ModuleM::CS_CONST252 }.should raise_error(NameError) ConstantSpecs::ModuleM::CS_CONST253 = :const253 ConstantSpecs::ModuleM::CS_CONST253.should == :const253 ConstantSpecs::ModuleM.send :remove_const, "CS_CONST253" - lambda { ConstantSpecs::ModuleM::CS_CONST253 }.should raise_error(NameError) + -> { ConstantSpecs::ModuleM::CS_CONST253 }.should raise_error(NameError) end it "returns the value of the removed constant" do @@ -23,7 +23,7 @@ describe "Module#remove_const" do it "raises a NameError and does not call #const_missing if the constant is not defined" do ConstantSpecs.should_not_receive(:const_missing) - lambda { ConstantSpecs.send(:remove_const, :Nonexistent) }.should raise_error(NameError) + -> { ConstantSpecs.send(:remove_const, :Nonexistent) }.should raise_error(NameError) end it "raises a NameError and does not call #const_missing if the constant is not defined directly in the module" do @@ -32,7 +32,7 @@ describe "Module#remove_const" do ConstantSpecs::ContainerA::CS_CONST255.should == :const255 ConstantSpecs::ContainerA.should_not_receive(:const_missing) - lambda do + -> do ConstantSpecs::ContainerA.send :remove_const, :CS_CONST255 end.should raise_error(NameError) ensure @@ -41,21 +41,21 @@ describe "Module#remove_const" do end it "raises a NameError if the name does not start with a capital letter" do - lambda { ConstantSpecs.send :remove_const, "name" }.should raise_error(NameError) + -> { ConstantSpecs.send :remove_const, "name" }.should raise_error(NameError) end it "raises a NameError if the name starts with a non-alphabetic character" do - lambda { ConstantSpecs.send :remove_const, "__CONSTX__" }.should raise_error(NameError) - lambda { ConstantSpecs.send :remove_const, "@Name" }.should raise_error(NameError) - lambda { ConstantSpecs.send :remove_const, "!Name" }.should raise_error(NameError) - lambda { ConstantSpecs.send :remove_const, "::Name" }.should raise_error(NameError) + -> { ConstantSpecs.send :remove_const, "__CONSTX__" }.should raise_error(NameError) + -> { ConstantSpecs.send :remove_const, "@Name" }.should raise_error(NameError) + -> { ConstantSpecs.send :remove_const, "!Name" }.should raise_error(NameError) + -> { ConstantSpecs.send :remove_const, "::Name" }.should raise_error(NameError) end it "raises a NameError if the name contains non-alphabetic characters except '_'" do ConstantSpecs::ModuleM::CS_CONST256 = :const256 ConstantSpecs::ModuleM.send :remove_const, "CS_CONST256" - lambda { ConstantSpecs.send :remove_const, "Name=" }.should raise_error(NameError) - lambda { ConstantSpecs.send :remove_const, "Name?" }.should raise_error(NameError) + -> { ConstantSpecs.send :remove_const, "Name=" }.should raise_error(NameError) + -> { ConstantSpecs.send :remove_const, "Name?" }.should raise_error(NameError) end it "calls #to_str to convert the given name to a String" do @@ -67,10 +67,10 @@ describe "Module#remove_const" do it "raises a TypeError if conversion to a String by calling #to_str fails" do name = mock('123') - lambda { ConstantSpecs.send :remove_const, name }.should raise_error(TypeError) + -> { ConstantSpecs.send :remove_const, name }.should raise_error(TypeError) name.should_receive(:to_str).and_return(123) - lambda { ConstantSpecs.send :remove_const, name }.should raise_error(TypeError) + -> { ConstantSpecs.send :remove_const, name }.should raise_error(TypeError) end it "is a private method" do diff --git a/spec/ruby/core/module/remove_method_spec.rb b/spec/ruby/core/module/remove_method_spec.rb index 70048a83fb..ba08cc9b44 100644 --- a/spec/ruby/core/module/remove_method_spec.rb +++ b/spec/ruby/core/module/remove_method_spec.rb @@ -98,15 +98,15 @@ describe "Module#remove_method" do end it "raises a #{frozen_error_class} when passed a name" do - lambda { @frozen.send :remove_method, :method_to_remove }.should raise_error(frozen_error_class) + -> { @frozen.send :remove_method, :method_to_remove }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} when passed a missing name" do - lambda { @frozen.send :remove_method, :not_exist }.should raise_error(frozen_error_class) + -> { @frozen.send :remove_method, :not_exist }.should raise_error(frozen_error_class) end it "raises a TypeError when passed a not name" do - lambda { @frozen.send :remove_method, Object.new }.should raise_error(TypeError) + -> { @frozen.send :remove_method, Object.new }.should raise_error(TypeError) end it "does not raise exceptions when no arguments given" do diff --git a/spec/ruby/core/module/shared/class_eval.rb b/spec/ruby/core/module/shared/class_eval.rb index 6bb9668fee..08f8ff7597 100644 --- a/spec/ruby/core/module/shared/class_eval.rb +++ b/spec/ruby/core/module/shared/class_eval.rb @@ -14,7 +14,7 @@ describe :module_class_eval, shared: true do 'foo' end end - lambda {42.foo}.should raise_error(NoMethodError) + -> {42.foo}.should raise_error(NoMethodError) end it "resolves constants in the caller scope" do @@ -59,7 +59,7 @@ describe :module_class_eval, shared: true do it "raises a TypeError when the given filename can't be converted to string using to_str" do (file = mock('123')).should_receive(:to_str).and_return(123) - lambda { ModuleSpecs.send(@method, "1+1", file) }.should raise_error(TypeError) + -> { ModuleSpecs.send(@method, "1+1", file) }.should raise_error(TypeError) end it "converts non string eval-string to string using to_str" do @@ -69,24 +69,24 @@ describe :module_class_eval, shared: true do it "raises a TypeError when the given eval-string can't be converted to string using to_str" do o = mock('x') - lambda { ModuleSpecs.send(@method, o) }.should raise_error(TypeError) + -> { ModuleSpecs.send(@method, o) }.should raise_error(TypeError) (o = mock('123')).should_receive(:to_str).and_return(123) - lambda { ModuleSpecs.send(@method, o) }.should raise_error(TypeError) + -> { ModuleSpecs.send(@method, o) }.should raise_error(TypeError) end it "raises an ArgumentError when no arguments and no block are given" do - lambda { ModuleSpecs.send(@method) }.should raise_error(ArgumentError) + -> { ModuleSpecs.send(@method) }.should raise_error(ArgumentError) end it "raises an ArgumentError when more than 3 arguments are given" do - lambda { + -> { ModuleSpecs.send(@method, "1 + 1", "some file", 0, "bogus") }.should raise_error(ArgumentError) end it "raises an ArgumentError when a block and normal arguments are given" do - lambda { + -> { ModuleSpecs.send(@method, "1 + 1") { 1 + 1 } }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/module/shared/class_exec.rb b/spec/ruby/core/module/shared/class_exec.rb index c5c18b0a34..c7a9e5297f 100644 --- a/spec/ruby/core/module/shared/class_exec.rb +++ b/spec/ruby/core/module/shared/class_exec.rb @@ -5,7 +5,7 @@ describe :module_class_exec, shared: true do 'foo' end end - lambda {42.foo}.should raise_error(NoMethodError) + -> {42.foo}.should raise_error(NoMethodError) end it "defines method in the receiver's scope" do @@ -19,7 +19,7 @@ describe :module_class_exec, shared: true do end it "raises a LocalJumpError when no block is given" do - lambda { ModuleSpecs::Subclass.send(@method) }.should raise_error(LocalJumpError) + -> { ModuleSpecs::Subclass.send(@method) }.should raise_error(LocalJumpError) end it "passes arguments to the block" do diff --git a/spec/ruby/core/module/undef_method_spec.rb b/spec/ruby/core/module/undef_method_spec.rb index 539de330e9..9b2c9240f4 100644 --- a/spec/ruby/core/module/undef_method_spec.rb +++ b/spec/ruby/core/module/undef_method_spec.rb @@ -41,8 +41,8 @@ describe "Module#undef_method" do x = klass.new klass.send(:undef_method, :method_to_undef, :another_method_to_undef) - lambda { x.method_to_undef }.should raise_error(NoMethodError) - lambda { x.another_method_to_undef }.should raise_error(NoMethodError) + -> { x.method_to_undef }.should raise_error(NoMethodError) + -> { x.another_method_to_undef }.should raise_error(NoMethodError) end it "does not undef any instance methods when argument not given" do @@ -57,7 +57,7 @@ describe "Module#undef_method" do end it "raises a NameError when passed a missing name" do - lambda { @module.send :undef_method, :not_exist }.should raise_error(NameError) { |e| + -> { @module.send :undef_method, :not_exist }.should raise_error(NameError) { |e| # a NameError and not a NoMethodError e.class.should == NameError } @@ -69,15 +69,15 @@ describe "Module#undef_method" do end it "raises a #{frozen_error_class} when passed a name" do - lambda { @frozen.send :undef_method, :method_to_undef }.should raise_error(frozen_error_class) + -> { @frozen.send :undef_method, :method_to_undef }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} when passed a missing name" do - lambda { @frozen.send :undef_method, :not_exist }.should raise_error(frozen_error_class) + -> { @frozen.send :undef_method, :not_exist }.should raise_error(frozen_error_class) end it "raises a TypeError when passed a not name" do - lambda { @frozen.send :undef_method, Object.new }.should raise_error(TypeError) + -> { @frozen.send :undef_method, Object.new }.should raise_error(TypeError) end it "does not raise exceptions when no arguments given" do @@ -98,7 +98,7 @@ describe "Module#undef_method with symbol" do klass.send :undef_method, :method_to_undef - lambda { x.method_to_undef }.should raise_error(NoMethodError) + -> { x.method_to_undef }.should raise_error(NoMethodError) end it "removes a method defined in a super class" do @@ -108,7 +108,7 @@ describe "Module#undef_method with symbol" do child_class.send :undef_method, :method_to_undef - lambda { child.method_to_undef }.should raise_error(NoMethodError) + -> { child.method_to_undef }.should raise_error(NoMethodError) end it "does not remove a method defined in a super class when removed from a subclass" do @@ -134,7 +134,7 @@ describe "Module#undef_method with string" do klass.send :undef_method, 'another_method_to_undef' - lambda { x.another_method_to_undef }.should raise_error(NoMethodError) + -> { x.another_method_to_undef }.should raise_error(NoMethodError) end it "removes a method defined in a super class" do @@ -144,7 +144,7 @@ describe "Module#undef_method with string" do child_class.send :undef_method, 'another_method_to_undef' - lambda { child.another_method_to_undef }.should raise_error(NoMethodError) + -> { child.another_method_to_undef }.should raise_error(NoMethodError) end it "does not remove a method defined in a super class when removed from a subclass" do diff --git a/spec/ruby/core/module/using_spec.rb b/spec/ruby/core/module/using_spec.rb index 9b6b38f622..533d87d080 100644 --- a/spec/ruby/core/module/using_spec.rb +++ b/spec/ruby/core/module/using_spec.rb @@ -24,7 +24,7 @@ describe "Module#using" do end end - -> () { + -> { Module.new do using refinement end @@ -34,7 +34,7 @@ describe "Module#using" do it "accepts module without refinements" do mod = Module.new - -> () { + -> { Module.new do using mod end @@ -44,7 +44,7 @@ describe "Module#using" do it "does not accept class" do klass = Class.new - -> () { + -> { Module.new do using klass end @@ -52,7 +52,7 @@ describe "Module#using" do end it "raises TypeError if passed something other than module" do - -> () { + -> { Module.new do using "foo" end @@ -93,7 +93,7 @@ describe "Module#using" do end end - -> () { + -> { mod.foo }.should raise_error(RuntimeError, /Module#using is not permitted in methods/) end diff --git a/spec/ruby/core/mutex/lock_spec.rb b/spec/ruby/core/mutex/lock_spec.rb index a1a2972d8c..7a39817b11 100644 --- a/spec/ruby/core/mutex/lock_spec.rb +++ b/spec/ruby/core/mutex/lock_spec.rb @@ -14,12 +14,12 @@ describe "Mutex#lock" do it "blocks the caller if already locked" do m = Mutex.new m.lock - lambda { m.lock }.should block_caller + -> { m.lock }.should block_caller end it "does not block the caller if not locked" do m = Mutex.new - lambda { m.lock }.should_not block_caller + -> { m.lock }.should_not block_caller end # Unable to find a specific ticket but behavior change may be diff --git a/spec/ruby/core/mutex/sleep_spec.rb b/spec/ruby/core/mutex/sleep_spec.rb index 72ed397eb5..477f9278c8 100644 --- a/spec/ruby/core/mutex/sleep_spec.rb +++ b/spec/ruby/core/mutex/sleep_spec.rb @@ -4,21 +4,21 @@ describe "Mutex#sleep" do describe "when not locked by the current thread" do it "raises a ThreadError" do m = Mutex.new - lambda { m.sleep }.should raise_error(ThreadError) + -> { m.sleep }.should raise_error(ThreadError) end it "raises an ArgumentError if passed a negative duration" do m = Mutex.new - lambda { m.sleep(-0.1) }.should raise_error(ArgumentError) - lambda { m.sleep(-1) }.should raise_error(ArgumentError) + -> { m.sleep(-0.1) }.should raise_error(ArgumentError) + -> { m.sleep(-1) }.should raise_error(ArgumentError) end end it "raises an ArgumentError if passed a negative duration" do m = Mutex.new m.lock - lambda { m.sleep(-0.1) }.should raise_error(ArgumentError) - lambda { m.sleep(-1) }.should raise_error(ArgumentError) + -> { m.sleep(-0.1) }.should raise_error(ArgumentError) + -> { m.sleep(-1) }.should raise_error(ArgumentError) end it "pauses execution for approximately the duration requested" do diff --git a/spec/ruby/core/mutex/synchronize_spec.rb b/spec/ruby/core/mutex/synchronize_spec.rb index e3dad508b8..7942885197 100644 --- a/spec/ruby/core/mutex/synchronize_spec.rb +++ b/spec/ruby/core/mutex/synchronize_spec.rb @@ -8,7 +8,7 @@ describe "Mutex#synchronize" do synchronized = false th = Thread.new do - lambda do + -> do m1.synchronize do synchronized = true m2.lock @@ -28,12 +28,12 @@ describe "Mutex#synchronize" do it "blocks the caller if already locked" do m = Mutex.new m.lock - lambda { m.synchronize { } }.should block_caller + -> { m.synchronize { } }.should block_caller end it "does not block the caller if not locked" do m = Mutex.new - lambda { m.synchronize { } }.should_not block_caller + -> { m.synchronize { } }.should_not block_caller end it "blocks the caller if another thread is also in the synchronize block" do @@ -50,7 +50,7 @@ describe "Mutex#synchronize" do q1.pop.should == :ready - lambda { m.synchronize { } }.should block_caller + -> { m.synchronize { } }.should block_caller q2.push :done t.join @@ -60,7 +60,7 @@ describe "Mutex#synchronize" do m = Mutex.new m.synchronize do - lambda { m.synchronize { } }.should raise_error(ThreadError) + -> { m.synchronize { } }.should raise_error(ThreadError) end end end diff --git a/spec/ruby/core/mutex/unlock_spec.rb b/spec/ruby/core/mutex/unlock_spec.rb index 12353f9ba3..c9c3bfe14f 100644 --- a/spec/ruby/core/mutex/unlock_spec.rb +++ b/spec/ruby/core/mutex/unlock_spec.rb @@ -3,7 +3,7 @@ require_relative '../../spec_helper' describe "Mutex#unlock" do it "raises ThreadError unless Mutex is locked" do mutex = Mutex.new - lambda { mutex.unlock }.should raise_error(ThreadError) + -> { mutex.unlock }.should raise_error(ThreadError) end it "raises ThreadError unless thread owns Mutex" do @@ -19,7 +19,7 @@ describe "Mutex#unlock" do Thread.pass until mutex.locked? Thread.pass while th.status and th.status != "sleep" - lambda { mutex.unlock }.should raise_error(ThreadError) + -> { mutex.unlock }.should raise_error(ThreadError) wait.unlock th.join @@ -33,6 +33,6 @@ describe "Mutex#unlock" do th.join - lambda { mutex.unlock }.should raise_error(ThreadError) + -> { mutex.unlock }.should raise_error(ThreadError) end end diff --git a/spec/ruby/core/nil/nilclass_spec.rb b/spec/ruby/core/nil/nilclass_spec.rb index 72d3d37b2e..7f6d8af25d 100644 --- a/spec/ruby/core/nil/nilclass_spec.rb +++ b/spec/ruby/core/nil/nilclass_spec.rb @@ -2,13 +2,13 @@ require_relative '../../spec_helper' describe "NilClass" do it ".allocate raises a TypeError" do - lambda do + -> do NilClass.allocate end.should raise_error(TypeError) end it ".new is undefined" do - lambda do + -> do NilClass.new end.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/nil/rationalize_spec.rb b/spec/ruby/core/nil/rationalize_spec.rb index f65d8eebee..84d6e6f056 100644 --- a/spec/ruby/core/nil/rationalize_spec.rb +++ b/spec/ruby/core/nil/rationalize_spec.rb @@ -10,7 +10,7 @@ describe "NilClass#rationalize" do end it "raises ArgumentError when passed more than one argument" do - lambda { nil.rationalize(0.1, 0.1) }.should raise_error(ArgumentError) - lambda { nil.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) + -> { nil.rationalize(0.1, 0.1) }.should raise_error(ArgumentError) + -> { nil.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/numeric/coerce_spec.rb b/spec/ruby/core/numeric/coerce_spec.rb index c0136b181e..4c4416d30b 100644 --- a/spec/ruby/core/numeric/coerce_spec.rb +++ b/spec/ruby/core/numeric/coerce_spec.rb @@ -25,7 +25,7 @@ describe "Numeric#coerce" do class << a; true; end # watch it explode - lambda { a.coerce(b) }.should raise_error(TypeError) + -> { a.coerce(b) }.should raise_error(TypeError) end end @@ -38,22 +38,22 @@ describe "Numeric#coerce" do it "raise TypeError if they are instances of different classes and other does not respond to #to_f" do other = mock("numeric") - lambda { @obj.coerce(other) }.should raise_error(TypeError) + -> { @obj.coerce(other) }.should raise_error(TypeError) end it "raises a TypeError when passed nil" do - lambda { @obj.coerce(nil) }.should raise_error(TypeError) + -> { @obj.coerce(nil) }.should raise_error(TypeError) end it "raises a TypeError when passed a boolean" do - lambda { @obj.coerce(false) }.should raise_error(TypeError) + -> { @obj.coerce(false) }.should raise_error(TypeError) end it "raises a TypeError when passed a Symbol" do - lambda { @obj.coerce(:symbol) }.should raise_error(TypeError) + -> { @obj.coerce(:symbol) }.should raise_error(TypeError) end it "raises an ArgumentError when passed a non-numeric String" do - lambda { @obj.coerce("test") }.should raise_error(ArgumentError) + -> { @obj.coerce("test") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/numeric/div_spec.rb b/spec/ruby/core/numeric/div_spec.rb index 0017311487..53917b84c9 100644 --- a/spec/ruby/core/numeric/div_spec.rb +++ b/spec/ruby/core/numeric/div_spec.rb @@ -15,8 +15,8 @@ describe "Numeric#div" do end it "raises ZeroDivisionError for 0" do - lambda { @obj.div(0) }.should raise_error(ZeroDivisionError) - lambda { @obj.div(0.0) }.should raise_error(ZeroDivisionError) - lambda { @obj.div(Complex(0,0)) }.should raise_error(ZeroDivisionError) + -> { @obj.div(0) }.should raise_error(ZeroDivisionError) + -> { @obj.div(0.0) }.should raise_error(ZeroDivisionError) + -> { @obj.div(Complex(0,0)) }.should raise_error(ZeroDivisionError) end end diff --git a/spec/ruby/core/numeric/quo_spec.rb b/spec/ruby/core/numeric/quo_spec.rb index bf05cf678d..5c952b11a9 100644 --- a/spec/ruby/core/numeric/quo_spec.rb +++ b/spec/ruby/core/numeric/quo_spec.rb @@ -16,11 +16,11 @@ describe "Numeric#quo" do end it "raises a ZeroDivisionError when the given Integer is 0" do - lambda { 0.quo(0) }.should raise_error(ZeroDivisionError) - lambda { 10.quo(0) }.should raise_error(ZeroDivisionError) - lambda { -10.quo(0) }.should raise_error(ZeroDivisionError) - lambda { bignum_value.quo(0) }.should raise_error(ZeroDivisionError) - lambda { -bignum_value.quo(0) }.should raise_error(ZeroDivisionError) + -> { 0.quo(0) }.should raise_error(ZeroDivisionError) + -> { 10.quo(0) }.should raise_error(ZeroDivisionError) + -> { -10.quo(0) }.should raise_error(ZeroDivisionError) + -> { bignum_value.quo(0) }.should raise_error(ZeroDivisionError) + -> { -bignum_value.quo(0) }.should raise_error(ZeroDivisionError) end it "calls #to_r to convert the object to a Rational" do @@ -34,16 +34,16 @@ describe "Numeric#quo" do obj = NumericSpecs::Subclass.new obj.should_receive(:to_r).and_return(1) - lambda { obj.quo(19) }.should raise_error(TypeError) + -> { obj.quo(19) }.should raise_error(TypeError) end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('x')).should_not_receive(:to_int) 13.quo(obj) }.should raise_error(TypeError) - lambda { 13.quo("10") }.should raise_error(TypeError) - lambda { 13.quo(:symbol) }.should raise_error(TypeError) + -> { 13.quo("10") }.should raise_error(TypeError) + -> { 13.quo(:symbol) }.should raise_error(TypeError) end it "returns the result of calling self#/ with other" do diff --git a/spec/ruby/core/numeric/real_spec.rb b/spec/ruby/core/numeric/real_spec.rb index 8c318dce0f..caa8dcec6d 100644 --- a/spec/ruby/core/numeric/real_spec.rb +++ b/spec/ruby/core/numeric/real_spec.rb @@ -25,7 +25,7 @@ describe "Numeric#real" do it "raises an ArgumentError if given any arguments" do @numbers.each do |number| - lambda { number.real(number) }.should raise_error(ArgumentError) + -> { number.real(number) }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/numeric/shared/imag.rb b/spec/ruby/core/numeric/shared/imag.rb index 11daf0af55..ac2da40a3b 100644 --- a/spec/ruby/core/numeric/shared/imag.rb +++ b/spec/ruby/core/numeric/shared/imag.rb @@ -20,7 +20,7 @@ describe :numeric_imag, shared: true do it "raises an ArgumentError if given any arguments" do @numbers.each do |number| - lambda { number.send(@method, number) }.should raise_error(ArgumentError) + -> { number.send(@method, number) }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/numeric/shared/rect.rb b/spec/ruby/core/numeric/shared/rect.rb index 047d6556e1..9cde19a398 100644 --- a/spec/ruby/core/numeric/shared/rect.rb +++ b/spec/ruby/core/numeric/shared/rect.rb @@ -42,7 +42,7 @@ describe :numeric_rect, shared: true do it "raises an ArgumentError if given any arguments" do @numbers.each do |number| - lambda { number.send(@method, number) }.should raise_error(ArgumentError) + -> { number.send(@method, number) }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/numeric/shared/step.rb b/spec/ruby/core/numeric/shared/step.rb index 5dcaa4b253..b0cbbd0585 100644 --- a/spec/ruby/core/numeric/shared/step.rb +++ b/spec/ruby/core/numeric/shared/step.rb @@ -8,7 +8,7 @@ require_relative '../fixtures/classes' describe :numeric_step, :shared => true do before :each do ScratchPad.record [] - @prc = lambda { |x| ScratchPad << x } + @prc = -> x { ScratchPad << x } end it "defaults to step = 1" do @@ -233,33 +233,33 @@ describe :numeric_step, :shared => true do describe "with self and stop as Fixnums" do it "raises an #{error} when step is a numeric representation" do - lambda { 1.send(@method, *@step_args.call(5, "1")) {} }.should raise_error(error) - lambda { 1.send(@method, *@step_args.call(5, "0.1")) {} }.should raise_error(error) - lambda { 1.send(@method, *@step_args.call(5, "1/3")) {} }.should raise_error(error) + -> { 1.send(@method, *@step_args.call(5, "1")) {} }.should raise_error(error) + -> { 1.send(@method, *@step_args.call(5, "0.1")) {} }.should raise_error(error) + -> { 1.send(@method, *@step_args.call(5, "1/3")) {} }.should raise_error(error) end it "raises an #{error} with step as an alphanumeric string" do - lambda { 1.send(@method, *@step_args.call(5, "foo")) {} }.should raise_error(error) + -> { 1.send(@method, *@step_args.call(5, "foo")) {} }.should raise_error(error) end end describe "with self and stop as Floats" do it "raises an #{error} when step is a numeric representation" do - lambda { 1.1.send(@method, *@step_args.call(5.1, "1")) {} }.should raise_error(error) - lambda { 1.1.send(@method, *@step_args.call(5.1, "0.1")) {} }.should raise_error(error) - lambda { 1.1.send(@method, *@step_args.call(5.1, "1/3")) {} }.should raise_error(error) + -> { 1.1.send(@method, *@step_args.call(5.1, "1")) {} }.should raise_error(error) + -> { 1.1.send(@method, *@step_args.call(5.1, "0.1")) {} }.should raise_error(error) + -> { 1.1.send(@method, *@step_args.call(5.1, "1/3")) {} }.should raise_error(error) end it "raises an #{error} with step as an alphanumeric string" do - lambda { 1.1.send(@method, *@step_args.call(5.1, "foo")) {} }.should raise_error(error) + -> { 1.1.send(@method, *@step_args.call(5.1, "foo")) {} }.should raise_error(error) end end end it "does not rescue ArgumentError exceptions" do - lambda { 1.send(@method, *@step_args.call(2)) { raise ArgumentError, "" }}.should raise_error(ArgumentError) + -> { 1.send(@method, *@step_args.call(2)) { raise ArgumentError, "" }}.should raise_error(ArgumentError) end it "does not rescue TypeError exceptions" do - lambda { 1.send(@method, *@step_args.call(2)) { raise TypeError, "" } }.should raise_error(TypeError) + -> { 1.send(@method, *@step_args.call(2)) { raise TypeError, "" } }.should raise_error(TypeError) end describe "when no block is given" do @@ -311,23 +311,23 @@ describe :numeric_step, :shared => true do describe "with self and stop as Fixnums" do it "raises an #{error} when step is a numeric representation" do - lambda { 1.send(@method, *@step_args.call(5, "1")).size }.should raise_error(error) - lambda { 1.send(@method, *@step_args.call(5, "0.1")).size }.should raise_error(error) - lambda { 1.send(@method, *@step_args.call(5, "1/3")).size }.should raise_error(error) + -> { 1.send(@method, *@step_args.call(5, "1")).size }.should raise_error(error) + -> { 1.send(@method, *@step_args.call(5, "0.1")).size }.should raise_error(error) + -> { 1.send(@method, *@step_args.call(5, "1/3")).size }.should raise_error(error) end it "raises an #{error} with step as an alphanumeric string" do - lambda { 1.send(@method, *@step_args.call(5, "foo")).size }.should raise_error(error) + -> { 1.send(@method, *@step_args.call(5, "foo")).size }.should raise_error(error) end end describe "with self and stop as Floats" do it "raises an #{error} when step is a numeric representation" do - lambda { 1.1.send(@method, *@step_args.call(5.1, "1")).size }.should raise_error(error) - lambda { 1.1.send(@method, *@step_args.call(5.1, "0.1")).size }.should raise_error(error) - lambda { 1.1.send(@method, *@step_args.call(5.1, "1/3")).size }.should raise_error(error) + -> { 1.1.send(@method, *@step_args.call(5.1, "1")).size }.should raise_error(error) + -> { 1.1.send(@method, *@step_args.call(5.1, "0.1")).size }.should raise_error(error) + -> { 1.1.send(@method, *@step_args.call(5.1, "1/3")).size }.should raise_error(error) end it "raises an #{error} with step as an alphanumeric string" do - lambda { 1.1.send(@method, *@step_args.call(5.1, "foo")).size }.should raise_error(error) + -> { 1.1.send(@method, *@step_args.call(5.1, "foo")).size }.should raise_error(error) end end end diff --git a/spec/ruby/core/numeric/singleton_method_added_spec.rb b/spec/ruby/core/numeric/singleton_method_added_spec.rb index c39e9d7b32..2091398e5d 100644 --- a/spec/ruby/core/numeric/singleton_method_added_spec.rb +++ b/spec/ruby/core/numeric/singleton_method_added_spec.rb @@ -18,22 +18,22 @@ describe "Numeric#singleton_method_added" do end it "raises a TypeError when trying to define a singleton method on a Numeric" do - lambda do + -> do a = NumericSpecs::Subclass.new def a.test; end end.should raise_error(TypeError) - lambda do + -> do a = 1 def a.test; end end.should raise_error(TypeError) - lambda do + -> do a = 1.5 def a.test; end end.should raise_error(TypeError) - lambda do + -> do a = bignum_value def a.test; end end.should raise_error(TypeError) diff --git a/spec/ruby/core/numeric/step_spec.rb b/spec/ruby/core/numeric/step_spec.rb index 12369a47a2..fc80cc4ab0 100644 --- a/spec/ruby/core/numeric/step_spec.rb +++ b/spec/ruby/core/numeric/step_spec.rb @@ -6,17 +6,17 @@ describe "Numeric#step" do describe 'with positional args' do it "raises an ArgumentError when step is 0" do - lambda { 1.step(5, 0) {} }.should raise_error(ArgumentError) + -> { 1.step(5, 0) {} }.should raise_error(ArgumentError) end it "raises an ArgumentError when step is 0.0" do - lambda { 1.step(2, 0.0) {} }.should raise_error(ArgumentError) + -> { 1.step(2, 0.0) {} }.should raise_error(ArgumentError) end before :all do # This lambda definition limits to return the arguments it receives. # It's needed to test numeric_step behaviour with positional arguments. - @step_args = ->(*args) { args } + @step_args = -> *args { args } end it_behaves_like :numeric_step, :step @@ -40,12 +40,12 @@ describe "Numeric#step" do ruby_version_is ""..."2.6" do it "raises an ArgumentError when step is 0" do enum = 1.step(5, 0) - lambda { enum.size }.should raise_error(ArgumentError) + -> { enum.size }.should raise_error(ArgumentError) end it "raises an ArgumentError when step is 0.0" do enum = 1.step(2, 0.0) - lambda { enum.size }.should raise_error(ArgumentError) + -> { enum.size }.should raise_error(ArgumentError) end end @@ -87,11 +87,11 @@ describe "Numeric#step" do describe 'with keyword arguments' do it "doesn't raise an error when step is 0" do - lambda { 1.step(to: 5, by: 0) { break } }.should_not raise_error + -> { 1.step(to: 5, by: 0) { break } }.should_not raise_error end it "doesn't raise an error when step is 0.0" do - lambda { 1.step(to: 2, by: 0.0) { break } }.should_not raise_error + -> { 1.step(to: 2, by: 0.0) { break } }.should_not raise_error end it "should loop over self when step is 0 or 0.0" do @@ -138,7 +138,7 @@ describe "Numeric#step" do # This lambda transforms a positional step method args into # keyword arguments. # It's needed to test numeric_step behaviour with keyword arguments. - @step_args = ->(*args) do + @step_args = -> *args do kw_args = {to: args[0]} kw_args[:by] = args[1] if args.size == 2 [kw_args] @@ -149,19 +149,19 @@ describe "Numeric#step" do describe 'with mixed arguments' do it "doesn't raise an error when step is 0" do - lambda { 1.step(5, by: 0) { break } }.should_not raise_error + -> { 1.step(5, by: 0) { break } }.should_not raise_error end it "doesn't raise an error when step is 0.0" do - lambda { 1.step(2, by: 0.0) { break } }.should_not raise_error + -> { 1.step(2, by: 0.0) { break } }.should_not raise_error end it "raises a ArgumentError when limit and to are defined" do - lambda { 1.step(5, 1, to: 5) { break } }.should raise_error(ArgumentError) + -> { 1.step(5, 1, to: 5) { break } }.should raise_error(ArgumentError) end it "raises a ArgumentError when step and by are defined" do - lambda { 1.step(5, 1, by: 5) { break } }.should raise_error(ArgumentError) + -> { 1.step(5, 1, by: 5) { break } }.should raise_error(ArgumentError) end it "should loop over self when step is 0 or 0.0" do @@ -188,7 +188,7 @@ describe "Numeric#step" do # a mix of positional and keyword arguments. # It's needed to test numeric_step behaviour with positional mixed with # keyword arguments. - @step_args = ->(*args) do + @step_args = -> *args do if args.size == 2 [args[0], {by: args[1]}] else diff --git a/spec/ruby/core/objectspace/define_finalizer_spec.rb b/spec/ruby/core/objectspace/define_finalizer_spec.rb index b7e47473a0..3f7b1ae576 100644 --- a/spec/ruby/core/objectspace/define_finalizer_spec.rb +++ b/spec/ruby/core/objectspace/define_finalizer_spec.rb @@ -5,13 +5,13 @@ require_relative 'fixtures/classes' # passed proc or callable will be called at any particular time. describe "ObjectSpace.define_finalizer" do it "raises an ArgumentError if the action does not respond to call" do - lambda { + -> { ObjectSpace.define_finalizer("", mock("ObjectSpace.define_finalizer no #call")) }.should raise_error(ArgumentError) end it "accepts an object and a proc" do - handler = lambda { |obj| obj } + handler = -> obj { obj } ObjectSpace.define_finalizer("garbage", handler).should == [0, handler] end @@ -22,7 +22,7 @@ describe "ObjectSpace.define_finalizer" do end it "raises ArgumentError trying to define a finalizer on a non-reference" do - lambda { + -> { ObjectSpace.define_finalizer(:blah) { 1 } }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/objectspace/fixtures/classes.rb b/spec/ruby/core/objectspace/fixtures/classes.rb index 9a4b0aa865..612156c180 100644 --- a/spec/ruby/core/objectspace/fixtures/classes.rb +++ b/spec/ruby/core/objectspace/fixtures/classes.rb @@ -24,7 +24,7 @@ module ObjectSpaceFixtures end def self.define_finalizer - handler = lambda { |obj| ScratchPad.record :finalized } + handler = -> obj { ScratchPad.record :finalized } ObjectSpace.define_finalizer "#{rand 5}", handler end diff --git a/spec/ruby/core/objectspace/garbage_collect_spec.rb b/spec/ruby/core/objectspace/garbage_collect_spec.rb index 90000038c2..1aec3ea072 100644 --- a/spec/ruby/core/objectspace/garbage_collect_spec.rb +++ b/spec/ruby/core/objectspace/garbage_collect_spec.rb @@ -3,15 +3,15 @@ require_relative '../../spec_helper' describe "ObjectSpace.garbage_collect" do it "can be invoked without any exceptions" do - lambda { ObjectSpace.garbage_collect }.should_not raise_error + -> { ObjectSpace.garbage_collect }.should_not raise_error end it "doesn't accept any arguments" do - lambda { ObjectSpace.garbage_collect(1) }.should raise_error(ArgumentError) + -> { ObjectSpace.garbage_collect(1) }.should raise_error(ArgumentError) end it "ignores the supplied block" do - lambda { ObjectSpace.garbage_collect {} }.should_not raise_error + -> { ObjectSpace.garbage_collect {} }.should_not raise_error end it "always returns nil" do diff --git a/spec/ruby/core/proc/allocate_spec.rb b/spec/ruby/core/proc/allocate_spec.rb index a512c73b1a..54e1b69df9 100644 --- a/spec/ruby/core/proc/allocate_spec.rb +++ b/spec/ruby/core/proc/allocate_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Proc.allocate" do it "raises a TypeError" do - lambda { + -> { Proc.allocate }.should raise_error(TypeError) end diff --git a/spec/ruby/core/proc/binding_spec.rb b/spec/ruby/core/proc/binding_spec.rb index 5e8a461a55..86ab6bd400 100644 --- a/spec/ruby/core/proc/binding_spec.rb +++ b/spec/ruby/core/proc/binding_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Proc#binding" do it "returns a Binding instance" do - [Proc.new{}, lambda {}, proc {}].each { |p| + [Proc.new{}, -> {}, proc {}].each { |p| p.binding.should be_kind_of(Binding) } end @@ -10,7 +10,7 @@ describe "Proc#binding" do it "returns the binding associated with self" do obj = mock('binding') def obj.test_binding(some, params) - lambda {} + -> {} end lambdas_binding = obj.test_binding(1, 2).binding diff --git a/spec/ruby/core/proc/compose_spec.rb b/spec/ruby/core/proc/compose_spec.rb index f1befe658b..35e949a779 100644 --- a/spec/ruby/core/proc/compose_spec.rb +++ b/spec/ruby/core/proc/compose_spec.rb @@ -44,6 +44,14 @@ ruby_version_is "2.6" do (inc << mul).call(2, 3).should == 7 end + + it "passes blocks to the second proc" do + ScratchPad.record [] + one = proc { |&arg| arg.call :one if arg } + two = proc { |&arg| arg.call :two if arg } + (one << two).call { |x| ScratchPad << x } + ScratchPad.recorded.should == [:two] + end end end @@ -89,6 +97,14 @@ ruby_version_is "2.6" do (mul >> inc).call(2, 3).should == 7 end + + it "passes blocks to the first proc" do + ScratchPad.record [] + one = proc { |&arg| arg.call :one if arg } + two = proc { |&arg| arg.call :two if arg } + (one >> two).call { |x| ScratchPad << x } + ScratchPad.recorded.should == [:one] + end end end end diff --git a/spec/ruby/core/proc/curry_spec.rb b/spec/ruby/core/proc/curry_spec.rb index 7d1da441f1..24df2a8a72 100644 --- a/spec/ruby/core/proc/curry_spec.rb +++ b/spec/ruby/core/proc/curry_spec.rb @@ -3,7 +3,7 @@ require_relative '../../spec_helper' describe "Proc#curry" do before :each do @proc_add = Proc.new {|x,y,z| (x||0) + (y||0) + (z||0) } - @lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) } + @lambda_add = -> x, y, z { (x||0) + (y||0) + (z||0) } end it "returns a Proc when called on a proc" do @@ -12,7 +12,7 @@ describe "Proc#curry" do end it "returns a Proc when called on a lambda" do - p = lambda { true } + p = -> { true } p.curry.should be_an_instance_of(Proc) end @@ -36,10 +36,10 @@ describe "Proc#curry" do it "can be called multiple times on the same Proc" do @proc_add.curry - lambda { @proc_add.curry }.should_not raise_error + -> { @proc_add.curry }.should_not raise_error @lambda_add.curry - lambda { @lambda_add.curry }.should_not raise_error + -> { @lambda_add.curry }.should_not raise_error end it "can be passed superfluous arguments if created from a proc" do @@ -49,19 +49,19 @@ describe "Proc#curry" do end it "raises an ArgumentError if passed superfluous arguments when created from a lambda" do - lambda { @lambda_add.curry[1,2,3,4] }.should raise_error(ArgumentError) - lambda { @lambda_add.curry[1,2].curry[3,4,5,6] }.should raise_error(ArgumentError) + -> { @lambda_add.curry[1,2,3,4] }.should raise_error(ArgumentError) + -> { @lambda_add.curry[1,2].curry[3,4,5,6] }.should raise_error(ArgumentError) end it "returns Procs with arities of -1" do @proc_add.curry.arity.should == -1 @lambda_add.curry.arity.should == -1 - l = lambda { |*a| } + l = -> *a { } l.curry.arity.should == -1 end it "produces Procs that raise ArgumentError for #binding" do - lambda do + -> do @proc_add.curry.binding end.should raise_error(ArgumentError) end @@ -81,7 +81,7 @@ describe "Proc#curry" do end it "combines arguments and calculates incoming arity accurately for successively currying" do - l = lambda{|a,b,c| a+b+c } + l = -> a, b, c { a+b+c } l1 = l.curry.call(1) # the l1 currying seems unnecessary, but it triggered the original issue l2 = l1.curry.call(2) @@ -93,13 +93,13 @@ end describe "Proc#curry with arity argument" do before :each do - @proc_add = proc {|x,y,z| (x||0) + (y||0) + (z||0) } - @lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) } + @proc_add = proc { |x,y,z| (x||0) + (y||0) + (z||0) } + @lambda_add = -> x, y, z { (x||0) + (y||0) + (z||0) } end it "accepts an optional Integer argument for the arity" do - lambda { @proc_add.curry(3) }.should_not raise_error - lambda { @lambda_add.curry(3) }.should_not raise_error + -> { @proc_add.curry(3) }.should_not raise_error + -> { @lambda_add.curry(3) }.should_not raise_error end it "returns a Proc when called on a proc" do @@ -117,22 +117,22 @@ describe "Proc#curry with arity argument" do end it "raises an ArgumentError if called on a lambda that requires more than _arity_ arguments" do - lambda { @lambda_add.curry(2) }.should raise_error(ArgumentError) - lambda { lambda{|x, y, z, *more|}.curry(2) }.should raise_error(ArgumentError) + -> { @lambda_add.curry(2) }.should raise_error(ArgumentError) + -> { -> x, y, z, *more{}.curry(2) }.should raise_error(ArgumentError) end it 'returns a Proc if called on a lambda that requires fewer than _arity_ arguments but may take more' do - lambda{|a, b, c, d=nil, e=nil|}.curry(4).should be_an_instance_of(Proc) - lambda{|a, b, c, d=nil, *e|}.curry(4).should be_an_instance_of(Proc) - lambda{|a, b, c, *d|}.curry(4).should be_an_instance_of(Proc) + -> a, b, c, d=nil, e=nil {}.curry(4).should be_an_instance_of(Proc) + -> a, b, c, d=nil, *e {}.curry(4).should be_an_instance_of(Proc) + -> a, b, c, *d {}.curry(4).should be_an_instance_of(Proc) end it "raises an ArgumentError if called on a lambda that requires fewer than _arity_ arguments" do - lambda { @lambda_add.curry(4) }.should raise_error(ArgumentError) - lambda { lambda { true }.curry(1) }.should raise_error(ArgumentError) - lambda { lambda {|a, b=nil|}.curry(5) }.should raise_error(ArgumentError) - lambda { lambda {|a, &b|}.curry(2) }.should raise_error(ArgumentError) - lambda { lambda {|a, b=nil, &c|}.curry(3) }.should raise_error(ArgumentError) + -> { @lambda_add.curry(4) }.should raise_error(ArgumentError) + -> { -> { true }.curry(1) }.should raise_error(ArgumentError) + -> { -> a, b=nil {}.curry(5) }.should raise_error(ArgumentError) + -> { -> a, &b {}.curry(2) }.should raise_error(ArgumentError) + -> { -> a, b=nil, &c {}.curry(3) }.should raise_error(ArgumentError) end it "calls the curried proc with the arguments if _arity_ arguments have been given" do @@ -152,29 +152,29 @@ describe "Proc#curry with arity argument" do it "can be specified multiple times on the same Proc" do @proc_add.curry(2) - lambda { @proc_add.curry(1) }.should_not raise_error + -> { @proc_add.curry(1) }.should_not raise_error @lambda_add.curry(3) - lambda { @lambda_add.curry(3) }.should_not raise_error + -> { @lambda_add.curry(3) }.should_not raise_error end it "can be passed more than _arity_ arguments if created from a proc" do - lambda { @proc_add.curry(3)[1,2,3,4].should == 6 }.should_not + -> { @proc_add.curry(3)[1,2,3,4].should == 6 }.should_not raise_error(ArgumentError) - lambda { @proc_add.curry(1)[1,2].curry(3)[3,4,5,6].should == 6 }.should_not + -> { @proc_add.curry(1)[1,2].curry(3)[3,4,5,6].should == 6 }.should_not raise_error(ArgumentError) end it "raises an ArgumentError if passed more than _arity_ arguments when created from a lambda" do - lambda { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError) - lambda { @lambda_add.curry(1)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError) + -> { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError) + -> { @lambda_add.curry(1)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError) end it "returns Procs with arities of -1 regardless of the value of _arity_" do @proc_add.curry(1).arity.should == -1 @proc_add.curry(2).arity.should == -1 @lambda_add.curry(3).arity.should == -1 - l = lambda { |*a| } + l = -> *a { } l.curry(3).arity.should == -1 end end diff --git a/spec/ruby/core/proc/fixtures/source_location.rb b/spec/ruby/core/proc/fixtures/source_location.rb index 468262e02a..688dac1e22 100644 --- a/spec/ruby/core/proc/fixtures/source_location.rb +++ b/spec/ruby/core/proc/fixtures/source_location.rb @@ -5,7 +5,7 @@ module ProcSpecs end def self.my_lambda - lambda { true } + -> { true } end def self.my_proc_new @@ -24,7 +24,7 @@ module ProcSpecs end def self.my_multiline_lambda - lambda do + -> do 'a'.upcase 1 + 22 end @@ -43,7 +43,7 @@ module ProcSpecs end def self.my_detached_lambda - body = lambda { true } + body = -> { true } lambda(&body) end diff --git a/spec/ruby/core/proc/hash_spec.rb b/spec/ruby/core/proc/hash_spec.rb index 5993ad5098..d780c1ceb0 100644 --- a/spec/ruby/core/proc/hash_spec.rb +++ b/spec/ruby/core/proc/hash_spec.rb @@ -3,7 +3,7 @@ require_relative '../../spec_helper' describe "Proc#hash" do it "is provided" do proc {}.respond_to?(:hash).should be_true - lambda {}.respond_to?(:hash).should be_true + -> {}.respond_to?(:hash).should be_true end it "returns an Integer" do diff --git a/spec/ruby/core/proc/lambda_spec.rb b/spec/ruby/core/proc/lambda_spec.rb index edf2151f27..fe2ceb4279 100644 --- a/spec/ruby/core/proc/lambda_spec.rb +++ b/spec/ruby/core/proc/lambda_spec.rb @@ -3,7 +3,7 @@ require_relative 'fixtures/common' describe "Proc#lambda?" do it "returns true if the Proc was created from a block with the lambda keyword" do - lambda {}.lambda?.should be_true + -> {}.lambda?.should be_true end it "returns false if the Proc was created from a block with the proc keyword" do @@ -15,17 +15,17 @@ describe "Proc#lambda?" do end it "is preserved when passing a Proc with & to the lambda keyword" do - lambda(&lambda{}).lambda?.should be_true + lambda(&->{}).lambda?.should be_true lambda(&proc{}).lambda?.should be_false end it "is preserved when passing a Proc with & to the proc keyword" do - proc(&lambda{}).lambda?.should be_true + proc(&->{}).lambda?.should be_true proc(&proc{}).lambda?.should be_false end it "is preserved when passing a Proc with & to Proc.new" do - Proc.new(&lambda{}).lambda?.should be_true + Proc.new(&->{}).lambda?.should be_true Proc.new(&proc{}).lambda?.should be_false end @@ -34,7 +34,7 @@ describe "Proc#lambda?" do end it "is preserved when the Proc was passed using &" do - ProcSpecs.new_proc_from_amp(&lambda{}).lambda?.should be_true + ProcSpecs.new_proc_from_amp(&->{}).lambda?.should be_true ProcSpecs.new_proc_from_amp(&proc{}).lambda?.should be_false ProcSpecs.new_proc_from_amp(&Proc.new{}).lambda?.should be_false end @@ -47,13 +47,13 @@ describe "Proc#lambda?" do # [ruby-core:24127] it "is preserved when a Proc is curried" do - lambda{}.curry.lambda?.should be_true + ->{}.curry.lambda?.should be_true proc{}.curry.lambda?.should be_false Proc.new{}.curry.lambda?.should be_false end it "is preserved when a curried Proc is called without enough arguments" do - lambda{|x,y|}.curry.call(42).lambda?.should be_true + -> x, y{}.curry.call(42).lambda?.should be_true proc{|x,y|}.curry.call(42).lambda?.should be_false Proc.new{|x,y|}.curry.call(42).lambda?.should be_false end diff --git a/spec/ruby/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb index 60a7320e4b..cc033467e5 100644 --- a/spec/ruby/core/proc/new_spec.rb +++ b/spec/ruby/core/proc/new_spec.rb @@ -71,7 +71,7 @@ describe "Proc.new with an associated block" do end res = some_method() - lambda { res.call }.should raise_error(LocalJumpError) + -> { res.call }.should raise_error(LocalJumpError) end it "returns from within enclosing method when 'return' is used in the block" do @@ -169,15 +169,15 @@ end describe "Proc.new without a block" do it "raises an ArgumentError" do - lambda { Proc.new }.should raise_error(ArgumentError) + -> { Proc.new }.should raise_error(ArgumentError) end it "raises an ArgumentError if invoked from within a method with no block" do - lambda { ProcSpecs.new_proc_in_method }.should raise_error(ArgumentError) + -> { ProcSpecs.new_proc_in_method }.should raise_error(ArgumentError) end it "raises an ArgumentError if invoked on a subclass from within a method with no block" do - lambda { ProcSpecs.new_proc_subclass_in_method }.should raise_error(ArgumentError) + -> { ProcSpecs.new_proc_subclass_in_method }.should raise_error(ArgumentError) end ruby_version_is ""..."2.7" do @@ -205,11 +205,11 @@ describe "Proc.new without a block" do ruby_version_is "2.7" do it "can be created if invoked from within a method with a block" do - lambda { ProcSpecs.new_proc_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) + -> { ProcSpecs.new_proc_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) end it "can be created if invoked on a subclass from within a method with a block" do - lambda { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) + -> { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) end diff --git a/spec/ruby/core/proc/parameters_spec.rb b/spec/ruby/core/proc/parameters_spec.rb index 4a8958497d..2bc5f1325c 100644 --- a/spec/ruby/core/proc/parameters_spec.rb +++ b/spec/ruby/core/proc/parameters_spec.rb @@ -25,17 +25,17 @@ describe "Proc#parameters" do end it "regards parameters with default values as optional" do - lambda {|x=1| }.parameters.first.first.should == :opt + -> x=1 { }.parameters.first.first.should == :opt proc {|x=1| }.parameters.first.first.should == :opt end it "sets the first element of each sub-Array to :req for required arguments" do - lambda {|x,y=[]| }.parameters.first.first.should == :req - lambda {|y,*x| }.parameters.first.first.should == :req + -> x, y=[] { }.parameters.first.first.should == :req + -> y, *x { }.parameters.first.first.should == :req end it "regards named parameters in lambdas as required" do - lambda {|x| }.parameters.first.first.should == :req + -> x { }.parameters.first.first.should == :req end it "regards keyword parameters in lambdas as required" do @@ -43,32 +43,32 @@ describe "Proc#parameters" do end it "sets the first element of each sub-Array to :rest for parameters prefixed with asterisks" do - lambda {|*x| }.parameters.first.first.should == :rest - lambda {|x,*y| }.parameters.last.first.should == :rest + -> *x { }.parameters.first.first.should == :rest + -> x, *y { }.parameters.last.first.should == :rest proc {|*x| }.parameters.first.first.should == :rest proc {|x,*y| }.parameters.last.first.should == :rest end it "sets the first element of each sub-Array to :keyrest for parameters prefixed with double asterisks" do - lambda {|**x| }.parameters.first.first.should == :keyrest - lambda {|x,**y| }.parameters.last.first.should == :keyrest + -> **x { }.parameters.first.first.should == :keyrest + -> x, **y { }.parameters.last.first.should == :keyrest proc {|**x| }.parameters.first.first.should == :keyrest proc {|x,**y| }.parameters.last.first.should == :keyrest end it "sets the first element of each sub-Array to :block for parameters prefixed with ampersands" do - lambda {|&x| }.parameters.first.first.should == :block - lambda {|x,&y| }.parameters.last.first.should == :block + ->&x { }.parameters.first.first.should == :block + -> x, &y { }.parameters.last.first.should == :block proc {|&x| }.parameters.first.first.should == :block proc {|x,&y| }.parameters.last.first.should == :block end it "sets the second element of each sub-Array to the name of the argument" do - lambda {|x| }.parameters.first.last.should == :x - lambda {|x=Math::PI| }.parameters.first.last.should == :x - lambda {|an_argument, glark, &foo| }.parameters[1].last.should == :glark - lambda {|*rest| }.parameters.first.last.should == :rest - lambda {|&block| }.parameters.first.last.should == :block + -> x { }.parameters.first.last.should == :x + -> x=Math::PI { }.parameters.first.last.should == :x + -> an_argument, glark, &foo { }.parameters[1].last.should == :glark + -> *rest { }.parameters.first.last.should == :rest + ->&block { }.parameters.first.last.should == :block proc {|x| }.parameters.first.last.should == :x proc {|x=Math::PI| }.parameters.first.last.should == :x proc {|an_argument, glark, &foo| }.parameters[1].last.should == :glark @@ -77,15 +77,15 @@ describe "Proc#parameters" do end it "ignores unnamed rest args" do - lambda {|x,|}.parameters.should == [[:req, :x]] + -> x {}.parameters.should == [[:req, :x]] end it "adds nameless rest arg for \"star\" argument" do - lambda {|x,*|}.parameters.should == [[:req, :x], [:rest]] + -> x, * {}.parameters.should == [[:req, :x], [:rest]] end it "does not add locals as block options with a block and splat" do - lambda do |*args, &blk| + -> *args, &blk do local_is_not_parameter = {} end.parameters.should == [[:rest, :args], [:block, :blk]] proc do |*args, &blk| diff --git a/spec/ruby/core/proc/shared/call.rb b/spec/ruby/core/proc/shared/call.rb index 996d0e055d..c30ea84b23 100644 --- a/spec/ruby/core/proc/shared/call.rb +++ b/spec/ruby/core/proc/shared/call.rb @@ -3,7 +3,7 @@ require_relative '../fixtures/common' describe :proc_call, shared: true do it "invokes self" do Proc.new { "test!" }.send(@method).should == "test!" - lambda { "test!" }.send(@method).should == "test!" + -> { "test!" }.send(@method).should == "test!" proc { "test!" }.send(@method).should == "test!" end @@ -12,9 +12,9 @@ describe :proc_call, shared: true do Proc.new { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4] Proc.new { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3] - lambda { |a, b| a + b }.send(@method, 1, 2).should == 3 - lambda { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4] - lambda { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3] + -> a, b { a + b }.send(@method, 1, 2).should == 3 + -> *args { args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4] + -> _, *args { args }.send(@method, 1, 2, 3).should == [2, 3] proc { |a, b| a + b }.send(@method, 1, 2).should == 3 proc { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4] @@ -65,28 +65,28 @@ describe :proc_call_on_proc_or_lambda, shared: true do end it "raises an ArgumentError on excess arguments when self is a lambda" do - lambda { - lambda {|x| x}.send(@method, 1, 2) + -> { + -> x { x }.send(@method, 1, 2) }.should raise_error(ArgumentError) - lambda { - lambda {|x| x}.send(@method, 1, 2, 3) + -> { + -> x { x }.send(@method, 1, 2, 3) }.should raise_error(ArgumentError) end it "raises an ArgumentError on missing arguments when self is a lambda" do - lambda { - lambda {|x| x}.send(@method) + -> { + -> x { x }.send(@method) }.should raise_error(ArgumentError) - lambda { - lambda {|x,y| [x,y]}.send(@method, 1) + -> { + -> x, y { [x,y] }.send(@method, 1) }.should raise_error(ArgumentError) end it "treats a single Array argument as a single argument when self is a lambda" do - lambda { |a| a }.send(@method, [1, 2]).should == [1, 2] - lambda { |a, b| [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3] + -> a { a }.send(@method, [1, 2]).should == [1, 2] + -> a, b { [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3] end it "treats a single Array argument as a single argument when self is a proc" do diff --git a/spec/ruby/core/proc/shared/call_arguments.rb b/spec/ruby/core/proc/shared/call_arguments.rb index a937bd99d0..ef6ec04620 100644 --- a/spec/ruby/core/proc/shared/call_arguments.rb +++ b/spec/ruby/core/proc/shared/call_arguments.rb @@ -1,7 +1,7 @@ describe :proc_call_block_args, shared: true do it "can receive block arguments" do Proc.new {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2 - lambda {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2 + ->&b { b.send(@method)}.send(@method) {1 + 1}.should == 2 proc {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2 end diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb index fb6fff299d..eda1d6929d 100644 --- a/spec/ruby/core/proc/shared/dup.rb +++ b/spec/ruby/core/proc/shared/dup.rb @@ -1,6 +1,6 @@ describe :proc_dup, shared: true do it "returns a copy of self" do - a = lambda { "hello" } + a = -> { "hello" } b = a.send(@method) a.should_not equal(b) diff --git a/spec/ruby/core/proc/shared/equal.rb b/spec/ruby/core/proc/shared/equal.rb index a5d067cea3..46a1894424 100644 --- a/spec/ruby/core/proc/shared/equal.rb +++ b/spec/ruby/core/proc/shared/equal.rb @@ -13,7 +13,7 @@ describe :proc_equal, shared: true do p = Proc.new { :foo } p.send(@method, p).should be_true - p = lambda { :foo } + p = -> { :foo } p.send(@method, p).should be_true end @@ -24,7 +24,7 @@ describe :proc_equal, shared: true do p = Proc.new { :foo } p.send(@method, p.dup).should be_true - p = lambda { :foo } + p = -> { :foo } p.send(@method, p.dup).should be_true end @@ -43,18 +43,18 @@ describe :proc_equal, shared: true do end it "returns true if both lambdas with the same body and environment" do - x = lambda { :foo } - x2 = lambda { :foo } + x = -> { :foo } + x2 = -> { :foo } x.send(@method, x2).should be_true end it "returns true if both different kinds of procs with the same body and env" do - p = lambda { :foo } + p = -> { :foo } p2 = proc { :foo } p.send(@method, p2).should be_true x = proc { :bar } - x2 = lambda { :bar } + x2 = -> { :bar } x.send(@method, x2).should be_true end @@ -65,7 +65,7 @@ describe :proc_equal, shared: true do p = Proc.new { :foo } p.send(@method, Object.new).should be_false - p = lambda { :foo } + p = -> { :foo } p.send(@method, :foo).should be_false end @@ -76,8 +76,8 @@ describe :proc_equal, shared: true do end it "returns false if self and other are both lambdas but have different bodies" do - p = lambda { :foo } - p2 = lambda { :bar } + p = -> { :foo } + p2 = -> { :bar } p.send(@method, p2).should be_false end end @@ -94,7 +94,7 @@ describe :proc_equal_undefined, shared: true do p = Proc.new { :foo } p.send(@method, p.dup).should be_false - p = lambda { :foo } + p = -> { :foo } p.send(@method, p.dup).should be_false end end diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb index 59fcf5bef0..a4d1d5d630 100644 --- a/spec/ruby/core/proc/shared/to_s.rb +++ b/spec/ruby/core/proc/shared/to_s.rb @@ -11,11 +11,11 @@ describe :proc_to_s, shared: true do describe "for a proc created with lambda" do it "returns a description including '(lambda)' and optionally including file and line number" do - lambda { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:10)? \(lambda\)>$/ + -> { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:10)? \(lambda\)>$/ end it "has a binary encoding" do - lambda { "hello" }.send(@method).encoding.should == Encoding::BINARY + -> { "hello" }.send(@method).encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/proc/source_location_spec.rb b/spec/ruby/core/proc/source_location_spec.rb index 89409c357b..b5b8178df2 100644 --- a/spec/ruby/core/proc/source_location_spec.rb +++ b/spec/ruby/core/proc/source_location_spec.rb @@ -55,7 +55,7 @@ describe "Proc#source_location" do it "works even if the proc was created on the same line" do proc { true }.source_location.should == [__FILE__, __LINE__] Proc.new { true }.source_location.should == [__FILE__, __LINE__] - lambda { true }.source_location.should == [__FILE__, __LINE__] + -> { true }.source_location.should == [__FILE__, __LINE__] end it "returns the first line of a multi-line proc (i.e. the line containing 'proc do')" do diff --git a/spec/ruby/core/proc/to_proc_spec.rb b/spec/ruby/core/proc/to_proc_spec.rb index 24e66760e4..ffaa34929b 100644 --- a/spec/ruby/core/proc/to_proc_spec.rb +++ b/spec/ruby/core/proc/to_proc_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Proc#to_proc" do it "returns self" do - [Proc.new {}, lambda {}, proc {}].each { |p| + [Proc.new {}, -> {}, proc {}].each { |p| p.to_proc.should equal(p) } end diff --git a/spec/ruby/core/process/clock_gettime_spec.rb b/spec/ruby/core/process/clock_gettime_spec.rb index 4cd13857ea..d3f973d7ae 100644 --- a/spec/ruby/core/process/clock_gettime_spec.rb +++ b/spec/ruby/core/process/clock_gettime_spec.rb @@ -20,7 +20,7 @@ describe "Process.clock_gettime" do end it 'raises an ArgumentError for an invalid time unit' do - lambda { Process.clock_gettime(Process::CLOCK_MONOTONIC, :bad) }.should raise_error(ArgumentError) + -> { Process.clock_gettime(Process::CLOCK_MONOTONIC, :bad) }.should raise_error(ArgumentError) end it 'defaults to :float_second' do diff --git a/spec/ruby/core/process/daemon_spec.rb b/spec/ruby/core/process/daemon_spec.rb index b472a3b9e9..70ffd1b320 100644 --- a/spec/ruby/core/process/daemon_spec.rb +++ b/spec/ruby/core/process/daemon_spec.rb @@ -107,7 +107,7 @@ end platform_is :windows do describe "Process.daemon" do it "raises a NotImplementedError" do - lambda { + -> { Process.daemon }.should raise_error(NotImplementedError) end diff --git a/spec/ruby/core/process/detach_spec.rb b/spec/ruby/core/process/detach_spec.rb index 74169a2fed..1c27ed9c2c 100644 --- a/spec/ruby/core/process/detach_spec.rb +++ b/spec/ruby/core/process/detach_spec.rb @@ -23,7 +23,7 @@ describe "Process.detach" do it "reaps the child process's status automatically" do pid = Process.fork { Process.exit! } Process.detach(pid).join - lambda { Process.waitpid(pid) }.should raise_error(Errno::ECHILD) + -> { Process.waitpid(pid) }.should raise_error(Errno::ECHILD) end end diff --git a/spec/ruby/core/process/euid_spec.rb b/spec/ruby/core/process/euid_spec.rb index ffb71a7178..7bbacfadfd 100644 --- a/spec/ruby/core/process/euid_spec.rb +++ b/spec/ruby/core/process/euid_spec.rb @@ -18,16 +18,16 @@ describe "Process.euid=" do platform_is_not :windows do it "raises TypeError if not passed an Integer" do - lambda { Process.euid = Object.new }.should raise_error(TypeError) + -> { Process.euid = Object.new }.should raise_error(TypeError) end as_user do it "raises Errno::ERPERM if run by a non superuser trying to set the superuser id" do - lambda { (Process.euid = 0)}.should raise_error(Errno::EPERM) + -> { (Process.euid = 0)}.should raise_error(Errno::EPERM) end it "raises Errno::ERPERM if run by a non superuser trying to set the superuser id from username" do - lambda { Process.euid = "root" }.should raise_error(Errno::EPERM) + -> { Process.euid = "root" }.should raise_error(Errno::EPERM) end end diff --git a/spec/ruby/core/process/exec_spec.rb b/spec/ruby/core/process/exec_spec.rb index 098898d42e..848990c6dc 100644 --- a/spec/ruby/core/process/exec_spec.rb +++ b/spec/ruby/core/process/exec_spec.rb @@ -2,27 +2,27 @@ require_relative '../../spec_helper' describe "Process.exec" do it "raises Errno::ENOENT for an empty string" do - lambda { Process.exec "" }.should raise_error(Errno::ENOENT) + -> { Process.exec "" }.should raise_error(Errno::ENOENT) end it "raises Errno::ENOENT for a command which does not exist" do - lambda { Process.exec "bogus-noent-script.sh" }.should raise_error(Errno::ENOENT) + -> { Process.exec "bogus-noent-script.sh" }.should raise_error(Errno::ENOENT) end it "raises an ArgumentError if the command includes a null byte" do - lambda { Process.exec "\000" }.should raise_error(ArgumentError) + -> { Process.exec "\000" }.should raise_error(ArgumentError) end unless File.executable?(__FILE__) # Some FS (e.g. vboxfs) locate all files executable platform_is_not :windows do it "raises Errno::EACCES when the file does not have execute permissions" do - lambda { Process.exec __FILE__ }.should raise_error(Errno::EACCES) + -> { Process.exec __FILE__ }.should raise_error(Errno::EACCES) end end platform_is :windows do it "raises Errno::EACCES or Errno::ENOEXEC when the file is not an executable file" do - lambda { Process.exec __FILE__ }.should raise_error(SystemCallError) { |e| + -> { Process.exec __FILE__ }.should raise_error(SystemCallError) { |e| [Errno::EACCES, Errno::ENOEXEC].should include(e.class) } end @@ -31,13 +31,13 @@ describe "Process.exec" do platform_is_not :openbsd do it "raises Errno::EACCES when passed a directory" do - lambda { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EACCES) + -> { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EACCES) end end platform_is :openbsd do it "raises Errno::EISDIR when passed a directory" do - lambda { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EISDIR) + -> { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EISDIR) end end @@ -179,9 +179,9 @@ describe "Process.exec" do end it "raises an ArgumentError if the Array does not have exactly two elements" do - lambda { Process.exec([]) }.should raise_error(ArgumentError) - lambda { Process.exec([:a]) }.should raise_error(ArgumentError) - lambda { Process.exec([:a, :b, :c]) }.should raise_error(ArgumentError) + -> { Process.exec([]) }.should raise_error(ArgumentError) + -> { Process.exec([:a]) }.should raise_error(ArgumentError) + -> { Process.exec([:a, :b, :c]) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/process/getrlimit_spec.rb b/spec/ruby/core/process/getrlimit_spec.rb index d866a48186..f77a61a475 100644 --- a/spec/ruby/core/process/getrlimit_spec.rb +++ b/spec/ruby/core/process/getrlimit_spec.rb @@ -36,7 +36,7 @@ platform_is_not :windows do obj = mock("process getrlimit integer") obj.should_receive(:to_int).and_return(nil) - lambda { Process.getrlimit(obj) }.should raise_error(TypeError) + -> { Process.getrlimit(obj) }.should raise_error(TypeError) end end @@ -49,7 +49,7 @@ platform_is_not :windows do end it "raises ArgumentError when passed an unknown resource" do - lambda { Process.getrlimit(:FOO) }.should raise_error(ArgumentError) + -> { Process.getrlimit(:FOO) }.should raise_error(ArgumentError) end end @@ -62,7 +62,7 @@ platform_is_not :windows do end it "raises ArgumentError when passed an unknown resource" do - lambda { Process.getrlimit("FOO") }.should raise_error(ArgumentError) + -> { Process.getrlimit("FOO") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/process/groups_spec.rb b/spec/ruby/core/process/groups_spec.rb index 325deb5977..6b9175736d 100644 --- a/spec/ruby/core/process/groups_spec.rb +++ b/spec/ruby/core/process/groups_spec.rb @@ -46,14 +46,14 @@ describe "Process.groups=" do Process.groups.should == [ Process.gid ] supplementary = groups - [ Process.gid ] if supplementary.length > 0 - lambda { Process.groups = supplementary }.should raise_error(Errno::EPERM) + -> { Process.groups = supplementary }.should raise_error(Errno::EPERM) end end end platform_is_not :aix do it "raises Errno::EPERM" do - lambda { + -> { Process.groups = [0] }.should raise_error(Errno::EPERM) end diff --git a/spec/ruby/core/process/initgroups_spec.rb b/spec/ruby/core/process/initgroups_spec.rb index e711fc0798..1dd516d8b2 100644 --- a/spec/ruby/core/process/initgroups_spec.rb +++ b/spec/ruby/core/process/initgroups_spec.rb @@ -14,7 +14,7 @@ describe "Process.initgroups" do Process.groups.sort.should == augmented_groups.sort Process.groups = groups else - lambda { Process.initgroups(name, gid) }.should raise_error(Errno::EPERM) + -> { Process.initgroups(name, gid) }.should raise_error(Errno::EPERM) end end end diff --git a/spec/ruby/core/process/kill_spec.rb b/spec/ruby/core/process/kill_spec.rb index 14deba2451..4bd64a1fe8 100644 --- a/spec/ruby/core/process/kill_spec.rb +++ b/spec/ruby/core/process/kill_spec.rb @@ -9,25 +9,25 @@ describe "Process.kill" do end it "raises an ArgumentError for unknown signals" do - lambda { Process.kill("FOO", @pid) }.should raise_error(ArgumentError) + -> { Process.kill("FOO", @pid) }.should raise_error(ArgumentError) end it "raises an ArgumentError if passed a lowercase signal name" do - lambda { Process.kill("term", @pid) }.should raise_error(ArgumentError) + -> { Process.kill("term", @pid) }.should raise_error(ArgumentError) end it "raises an ArgumentError if signal is not a Fixnum or String" do signal = mock("process kill signal") signal.should_not_receive(:to_int) - lambda { Process.kill(signal, @pid) }.should raise_error(ArgumentError) + -> { Process.kill(signal, @pid) }.should raise_error(ArgumentError) end it "raises Errno::ESRCH if the process does not exist" do pid = Process.spawn(*ruby_exe, "-e", "sleep 10") Process.kill("SIGKILL", pid) Process.wait(pid) - lambda { + -> { Process.kill("SIGKILL", pid) }.should raise_error(Errno::ESRCH) end diff --git a/spec/ruby/core/process/setrlimit_spec.rb b/spec/ruby/core/process/setrlimit_spec.rb index f4ff607b7b..8bc035a4f1 100644 --- a/spec/ruby/core/process/setrlimit_spec.rb +++ b/spec/ruby/core/process/setrlimit_spec.rb @@ -16,7 +16,7 @@ platform_is_not :windows do obj = mock("process getrlimit integer") obj.should_receive(:to_int).and_return(nil) - lambda { Process.setrlimit(obj, @limit, @max) }.should raise_error(TypeError) + -> { Process.setrlimit(obj, @limit, @max) }.should raise_error(TypeError) end it "calls #to_int to convert the soft limit to an Integer" do @@ -27,7 +27,7 @@ platform_is_not :windows do obj = mock("process getrlimit integer") obj.should_receive(:to_int).and_return(nil) - lambda { Process.setrlimit(@resource, obj, @max) }.should raise_error(TypeError) + -> { Process.setrlimit(@resource, obj, @max) }.should raise_error(TypeError) end it "calls #to_int to convert the hard limit to an Integer" do @@ -38,7 +38,7 @@ platform_is_not :windows do obj = mock("process getrlimit integer") obj.should_receive(:to_int).and_return(nil) - lambda { Process.setrlimit(@resource, @limit, obj) }.should raise_error(TypeError) + -> { Process.setrlimit(@resource, @limit, obj) }.should raise_error(TypeError) end end @@ -120,7 +120,7 @@ platform_is_not :windows do end it "raises ArgumentError when passed an unknown resource" do - lambda { Process.setrlimit(:FOO, 1, 1) }.should raise_error(ArgumentError) + -> { Process.setrlimit(:FOO, 1, 1) }.should raise_error(ArgumentError) end end @@ -202,7 +202,7 @@ platform_is_not :windows do end it "raises ArgumentError when passed an unknown resource" do - lambda { Process.setrlimit("FOO", 1, 1) }.should raise_error(ArgumentError) + -> { Process.setrlimit("FOO", 1, 1) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/process/spawn_spec.rb b/spec/ruby/core/process/spawn_spec.rb index aa7a7dc3aa..46faced3e4 100644 --- a/spec/ruby/core/process/spawn_spec.rb +++ b/spec/ruby/core/process/spawn_spec.rb @@ -45,7 +45,7 @@ describe "Process.spawn" do end it "executes the given command" do - lambda { Process.wait Process.spawn("echo spawn") }.should output_to_fd("spawn\n") + -> { Process.wait Process.spawn("echo spawn") }.should output_to_fd("spawn\n") end it "returns the process ID of the new process as a Fixnum" do @@ -67,43 +67,43 @@ describe "Process.spawn" do describe "with a single argument" do platform_is_not :windows do it "subjects the specified command to shell expansion" do - lambda { Process.wait Process.spawn("echo *") }.should_not output_to_fd("*\n") + -> { Process.wait Process.spawn("echo *") }.should_not output_to_fd("*\n") end it "creates an argument array with shell parsing semantics for whitespace" do - lambda { Process.wait Process.spawn("echo a b c d") }.should output_to_fd("a b c d\n") + -> { Process.wait Process.spawn("echo a b c d") }.should output_to_fd("a b c d\n") end end platform_is :windows do # There is no shell expansion on Windows it "does not subject the specified command to shell expansion on Windows" do - lambda { Process.wait Process.spawn("echo *") }.should output_to_fd("*\n") + -> { Process.wait Process.spawn("echo *") }.should output_to_fd("*\n") end it "does not create an argument array with shell parsing semantics for whitespace on Windows" do - lambda { Process.wait Process.spawn("echo a b c d") }.should output_to_fd("a b c d\n") + -> { Process.wait Process.spawn("echo a b c d") }.should output_to_fd("a b c d\n") end end it "calls #to_str to convert the argument to a String" do o = mock("to_str") o.should_receive(:to_str).and_return("echo foo") - lambda { Process.wait Process.spawn(o) }.should output_to_fd("foo\n") + -> { Process.wait Process.spawn(o) }.should output_to_fd("foo\n") end it "raises an ArgumentError if the command includes a null byte" do - lambda { Process.spawn "\000" }.should raise_error(ArgumentError) + -> { Process.spawn "\000" }.should raise_error(ArgumentError) end it "raises a TypeError if the argument does not respond to #to_str" do - lambda { Process.spawn :echo }.should raise_error(TypeError) + -> { Process.spawn :echo }.should raise_error(TypeError) end end describe "with multiple arguments" do it "does not subject the arguments to shell expansion" do - lambda { Process.wait Process.spawn("echo", "*") }.should output_to_fd("*\n") + -> { Process.wait Process.spawn("echo", "*") }.should output_to_fd("*\n") end it "preserves whitespace in passed arguments" do @@ -112,36 +112,36 @@ describe "Process.spawn" do # The echo command on Windows takes quotes literally out = "\"a b c d\"\n" end - lambda { Process.wait Process.spawn("echo", "a b c d") }.should output_to_fd(out) + -> { Process.wait Process.spawn("echo", "a b c d") }.should output_to_fd(out) end it "calls #to_str to convert the arguments to Strings" do o = mock("to_str") o.should_receive(:to_str).and_return("foo") - lambda { Process.wait Process.spawn("echo", o) }.should output_to_fd("foo\n") + -> { Process.wait Process.spawn("echo", o) }.should output_to_fd("foo\n") end it "raises an ArgumentError if an argument includes a null byte" do - lambda { Process.spawn "echo", "\000" }.should raise_error(ArgumentError) + -> { Process.spawn "echo", "\000" }.should raise_error(ArgumentError) end it "raises a TypeError if an argument does not respond to #to_str" do - lambda { Process.spawn "echo", :foo }.should raise_error(TypeError) + -> { Process.spawn "echo", :foo }.should raise_error(TypeError) end end describe "with a command array" do it "uses the first element as the command name and the second as the argv[0] value" do platform_is_not :windows do - lambda { Process.wait Process.spawn(["/bin/sh", "argv_zero"], "-c", "echo $0") }.should output_to_fd("argv_zero\n") + -> { Process.wait Process.spawn(["/bin/sh", "argv_zero"], "-c", "echo $0") }.should output_to_fd("argv_zero\n") end platform_is :windows do - lambda { Process.wait Process.spawn(["cmd.exe", "/C"], "/C", "echo", "argv_zero") }.should output_to_fd("argv_zero\n") + -> { Process.wait Process.spawn(["cmd.exe", "/C"], "/C", "echo", "argv_zero") }.should output_to_fd("argv_zero\n") end end it "does not subject the arguments to shell expansion" do - lambda { Process.wait Process.spawn(["echo", "echo"], "*") }.should output_to_fd("*\n") + -> { Process.wait Process.spawn(["echo", "echo"], "*") }.should output_to_fd("*\n") end it "preserves whitespace in passed arguments" do @@ -150,47 +150,47 @@ describe "Process.spawn" do # The echo command on Windows takes quotes literally out = "\"a b c d\"\n" end - lambda { Process.wait Process.spawn(["echo", "echo"], "a b c d") }.should output_to_fd(out) + -> { Process.wait Process.spawn(["echo", "echo"], "a b c d") }.should output_to_fd(out) end it "calls #to_ary to convert the argument to an Array" do o = mock("to_ary") platform_is_not :windows do o.should_receive(:to_ary).and_return(["/bin/sh", "argv_zero"]) - lambda { Process.wait Process.spawn(o, "-c", "echo $0") }.should output_to_fd("argv_zero\n") + -> { Process.wait Process.spawn(o, "-c", "echo $0") }.should output_to_fd("argv_zero\n") end platform_is :windows do o.should_receive(:to_ary).and_return(["cmd.exe", "/C"]) - lambda { Process.wait Process.spawn(o, "/C", "echo", "argv_zero") }.should output_to_fd("argv_zero\n") + -> { Process.wait Process.spawn(o, "/C", "echo", "argv_zero") }.should output_to_fd("argv_zero\n") end end it "calls #to_str to convert the first element to a String" do o = mock("to_str") o.should_receive(:to_str).and_return("echo") - lambda { Process.wait Process.spawn([o, "echo"], "foo") }.should output_to_fd("foo\n") + -> { Process.wait Process.spawn([o, "echo"], "foo") }.should output_to_fd("foo\n") end it "calls #to_str to convert the second element to a String" do o = mock("to_str") o.should_receive(:to_str).and_return("echo") - lambda { Process.wait Process.spawn(["echo", o], "foo") }.should output_to_fd("foo\n") + -> { Process.wait Process.spawn(["echo", o], "foo") }.should output_to_fd("foo\n") end it "raises an ArgumentError if the Array does not have exactly two elements" do - lambda { Process.spawn([]) }.should raise_error(ArgumentError) - lambda { Process.spawn([:a]) }.should raise_error(ArgumentError) - lambda { Process.spawn([:a, :b, :c]) }.should raise_error(ArgumentError) + -> { Process.spawn([]) }.should raise_error(ArgumentError) + -> { Process.spawn([:a]) }.should raise_error(ArgumentError) + -> { Process.spawn([:a, :b, :c]) }.should raise_error(ArgumentError) end it "raises an ArgumentError if the Strings in the Array include a null byte" do - lambda { Process.spawn ["\000", "echo"] }.should raise_error(ArgumentError) - lambda { Process.spawn ["echo", "\000"] }.should raise_error(ArgumentError) + -> { Process.spawn ["\000", "echo"] }.should raise_error(ArgumentError) + -> { Process.spawn ["echo", "\000"] }.should raise_error(ArgumentError) end it "raises a TypeError if an element in the Array does not respond to #to_str" do - lambda { Process.spawn ["echo", :echo] }.should raise_error(TypeError) - lambda { Process.spawn [:echo, "echo"] }.should raise_error(TypeError) + -> { Process.spawn ["echo", :echo] }.should raise_error(TypeError) + -> { Process.spawn [:echo, "echo"] }.should raise_error(TypeError) end end @@ -238,19 +238,19 @@ describe "Process.spawn" do end it "raises an ArgumentError if an environment key includes an equals sign" do - lambda do + -> do Process.spawn({"FOO=" => "BAR"}, "echo #{@var}>#{@name}") end.should raise_error(ArgumentError) end it "raises an ArgumentError if an environment key includes a null byte" do - lambda do + -> do Process.spawn({"\000" => "BAR"}, "echo #{@var}>#{@name}") end.should raise_error(ArgumentError) end it "raises an ArgumentError if an environment value includes a null byte" do - lambda do + -> do Process.spawn({"FOO" => "\000"}, "echo #{@var}>#{@name}") end.should raise_error(ArgumentError) end @@ -294,25 +294,25 @@ describe "Process.spawn" do platform_is_not :windows do it "joins the current process group by default" do - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)")) end.should output_to_fd(Process.getpgid(Process.pid).to_s) end it "joins the current process if pgroup: false" do - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: false) end.should output_to_fd(Process.getpgid(Process.pid).to_s) end it "joins the current process if pgroup: nil" do - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: nil) end.should output_to_fd(Process.getpgid(Process.pid).to_s) end it "joins a new process group if pgroup: true" do - process = lambda do + process = -> do Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: true) end @@ -321,7 +321,7 @@ describe "Process.spawn" do end it "joins a new process group if pgroup: 0" do - process = lambda do + process = -> do Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: 0) end @@ -331,23 +331,23 @@ describe "Process.spawn" do it "joins the specified process group if pgroup: pgid" do pgid = Process.getpgid(Process.pid) - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: pgid) end.should output_to_fd(pgid.to_s) end it "raises an ArgumentError if given a negative :pgroup option" do - lambda { Process.spawn("echo", pgroup: -1) }.should raise_error(ArgumentError) + -> { Process.spawn("echo", pgroup: -1) }.should raise_error(ArgumentError) end it "raises a TypeError if given a symbol as :pgroup option" do - lambda { Process.spawn("echo", pgroup: :true) }.should raise_error(TypeError) + -> { Process.spawn("echo", pgroup: :true) }.should raise_error(TypeError) end end platform_is :windows do it "raises an ArgumentError if given :pgroup option" do - lambda { Process.spawn("echo", pgroup: false) }.should raise_error(ArgumentError) + -> { Process.spawn("echo", pgroup: false) }.should raise_error(ArgumentError) end end @@ -358,7 +358,7 @@ describe "Process.spawn" do # :chdir it "uses the current working directory as its working directory" do - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print Dir.pwd")) end.should output_to_fd(Dir.pwd) end @@ -374,7 +374,7 @@ describe "Process.spawn" do end it "changes to the directory passed for :chdir" do - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print Dir.pwd"), chdir: @dir) end.should output_to_fd(@dir) end @@ -383,7 +383,7 @@ describe "Process.spawn" do dir = mock("spawn_to_path") dir.should_receive(:to_path).and_return(@dir) - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print Dir.pwd"), chdir: dir) end.should output_to_fd(@dir) end @@ -424,7 +424,7 @@ describe "Process.spawn" do sleep(1) children.each do |child| - lambda do + -> do Process.kill("TERM", child) end.should raise_error(Errno::ESRCH) end @@ -436,14 +436,14 @@ describe "Process.spawn" do # :umask it "uses the current umask by default" do - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print File.umask")) end.should output_to_fd(File.umask.to_s) end platform_is_not :windows do it "sets the umask if given the :umask option" do - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print File.umask"), umask: 146) end.should output_to_fd("146") end @@ -453,7 +453,7 @@ describe "Process.spawn" do it "redirects STDOUT to the given file descriptor if out: Fixnum" do File.open(@name, 'w') do |file| - lambda do + -> do Process.wait Process.spawn("echo glark", out: file.fileno) end.should output_to_fd("glark\n", file) end @@ -461,7 +461,7 @@ describe "Process.spawn" do it "redirects STDOUT to the given file if out: IO" do File.open(@name, 'w') do |file| - lambda do + -> do Process.wait Process.spawn("echo glark", out: file) end.should output_to_fd("glark\n", file) end @@ -479,7 +479,7 @@ describe "Process.spawn" do it "redirects STDERR to the given file descriptor if err: Fixnum" do File.open(@name, 'w') do |file| - lambda do + -> do Process.wait Process.spawn("echo glark>&2", err: file.fileno) end.should output_to_fd("glark\n", file) end @@ -487,7 +487,7 @@ describe "Process.spawn" do it "redirects STDERR to the given file descriptor if err: IO" do File.open(@name, 'w') do |file| - lambda do + -> do Process.wait Process.spawn("echo glark>&2", err: file) end.should output_to_fd("glark\n", file) end @@ -500,7 +500,7 @@ describe "Process.spawn" do it "redirects STDERR to child STDOUT if :err => [:child, :out]" do File.open(@name, 'w') do |file| - lambda do + -> do Process.wait Process.spawn("echo glark>&2", :out => file, :err => [:child, :out]) end.should output_to_fd("glark\n", file) end @@ -508,7 +508,7 @@ describe "Process.spawn" do it "redirects both STDERR and STDOUT to the given file descriptor" do File.open(@name, 'w') do |file| - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print(:glark); STDOUT.flush; STDERR.print(:bang)"), [:out, :err] => file.fileno) end.should output_to_fd("glarkbang", file) @@ -517,7 +517,7 @@ describe "Process.spawn" do it "redirects both STDERR and STDOUT to the given IO" do File.open(@name, 'w') do |file| - lambda do + -> do Process.wait Process.spawn(ruby_cmd("print(:glark); STDOUT.flush; STDERR.print(:bang)"), [:out, :err] => file) end.should output_to_fd("glarkbang", file) @@ -626,35 +626,35 @@ describe "Process.spawn" do # error handling it "raises an ArgumentError if passed no command arguments" do - lambda { Process.spawn }.should raise_error(ArgumentError) + -> { Process.spawn }.should raise_error(ArgumentError) end it "raises an ArgumentError if passed env or options but no command arguments" do - lambda { Process.spawn({}) }.should raise_error(ArgumentError) + -> { Process.spawn({}) }.should raise_error(ArgumentError) end it "raises an ArgumentError if passed env and options but no command arguments" do - lambda { Process.spawn({}, {}) }.should raise_error(ArgumentError) + -> { Process.spawn({}, {}) }.should raise_error(ArgumentError) end it "raises an Errno::ENOENT for an empty string" do - lambda { Process.spawn "" }.should raise_error(Errno::ENOENT) + -> { Process.spawn "" }.should raise_error(Errno::ENOENT) end it "raises an Errno::ENOENT if the command does not exist" do - lambda { Process.spawn "nonesuch" }.should raise_error(Errno::ENOENT) + -> { Process.spawn "nonesuch" }.should raise_error(Errno::ENOENT) end unless File.executable?(__FILE__) # Some FS (e.g. vboxfs) locate all files executable platform_is_not :windows do it "raises an Errno::EACCES when the file does not have execute permissions" do - lambda { Process.spawn __FILE__ }.should raise_error(Errno::EACCES) + -> { Process.spawn __FILE__ }.should raise_error(Errno::EACCES) end end platform_is :windows do it "raises Errno::EACCES or Errno::ENOEXEC when the file is not an executable file" do - lambda { Process.spawn __FILE__ }.should raise_error(SystemCallError) { |e| + -> { Process.spawn __FILE__ }.should raise_error(SystemCallError) { |e| [Errno::EACCES, Errno::ENOEXEC].should include(e.class) } end @@ -662,17 +662,17 @@ describe "Process.spawn" do end it "raises an Errno::EACCES or Errno::EISDIR when passed a directory" do - lambda { Process.spawn File.dirname(__FILE__) }.should raise_error(SystemCallError) { |e| + -> { Process.spawn File.dirname(__FILE__) }.should raise_error(SystemCallError) { |e| [Errno::EACCES, Errno::EISDIR].should include(e.class) } end it "raises an ArgumentError when passed a string key in options" do - lambda { Process.spawn("echo", "chdir" => Dir.pwd) }.should raise_error(ArgumentError) + -> { Process.spawn("echo", "chdir" => Dir.pwd) }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed an unknown option key" do - lambda { Process.spawn("echo", nonesuch: :foo) }.should raise_error(ArgumentError) + -> { Process.spawn("echo", nonesuch: :foo) }.should raise_error(ArgumentError) end platform_is_not :windows, :aix do diff --git a/spec/ruby/core/process/uid_spec.rb b/spec/ruby/core/process/uid_spec.rb index 350779aff3..a068b1a2c1 100644 --- a/spec/ruby/core/process/uid_spec.rb +++ b/spec/ruby/core/process/uid_spec.rb @@ -20,16 +20,16 @@ end describe "Process.uid=" do platform_is_not :windows do it "raises TypeError if not passed an Integer" do - lambda { Process.uid = Object.new }.should raise_error(TypeError) + -> { Process.uid = Object.new }.should raise_error(TypeError) end as_user do it "raises Errno::ERPERM if run by a non privileged user trying to set the superuser id" do - lambda { (Process.uid = 0)}.should raise_error(Errno::EPERM) + -> { (Process.uid = 0)}.should raise_error(Errno::EPERM) end it "raises Errno::ERPERM if run by a non privileged user trying to set the superuser id from username" do - lambda { Process.uid = "root" }.should raise_error(Errno::EPERM) + -> { Process.uid = "root" }.should raise_error(Errno::EPERM) end end diff --git a/spec/ruby/core/process/wait2_spec.rb b/spec/ruby/core/process/wait2_spec.rb index 4b6491ccd2..6eb7fc6d06 100644 --- a/spec/ruby/core/process/wait2_spec.rb +++ b/spec/ruby/core/process/wait2_spec.rb @@ -30,7 +30,7 @@ describe "Process.wait2" do end it "raises a StandardError if no child processes exist" do - lambda { Process.wait2 }.should raise_error(Errno::ECHILD) - lambda { Process.wait2 }.should raise_error(StandardError) + -> { Process.wait2 }.should raise_error(Errno::ECHILD) + -> { Process.wait2 }.should raise_error(StandardError) end end diff --git a/spec/ruby/core/process/wait_spec.rb b/spec/ruby/core/process/wait_spec.rb index 000ff684d4..f393a99e0f 100644 --- a/spec/ruby/core/process/wait_spec.rb +++ b/spec/ruby/core/process/wait_spec.rb @@ -15,7 +15,7 @@ describe "Process.wait" do end it "raises an Errno::ECHILD if there are no child processes" do - lambda { Process.wait }.should raise_error(Errno::ECHILD) + -> { Process.wait }.should raise_error(Errno::ECHILD) end platform_is_not :windows do @@ -34,7 +34,7 @@ describe "Process.wait" do it "waits for any child process if no pid is given" do pid = Process.spawn(ruby_cmd('exit')) Process.wait.should == pid - lambda { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) + -> { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) end it "waits for a specific child if a pid is given" do @@ -42,14 +42,14 @@ describe "Process.wait" do pid2 = Process.spawn(ruby_cmd('exit')) Process.wait(pid2).should == pid2 Process.wait(pid1).should == pid1 - lambda { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH) - lambda { Process.kill(0, pid2) }.should raise_error(Errno::ESRCH) + -> { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH) + -> { Process.kill(0, pid2) }.should raise_error(Errno::ESRCH) end it "coerces the pid to an Integer" do pid1 = Process.spawn(ruby_cmd('exit')) Process.wait(mock_int(pid1)).should == pid1 - lambda { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH) + -> { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH) end # This spec is probably system-dependent. @@ -86,7 +86,7 @@ describe "Process.wait" do it "always accepts flags=0" do pid = Process.spawn(ruby_cmd('exit')) Process.wait(-1, 0).should == pid - lambda { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) + -> { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) end end end diff --git a/spec/ruby/core/process/waitall_spec.rb b/spec/ruby/core/process/waitall_spec.rb index bdc1ea7490..6cf4e32bc9 100644 --- a/spec/ruby/core/process/waitall_spec.rb +++ b/spec/ruby/core/process/waitall_spec.rb @@ -13,7 +13,7 @@ describe "Process.waitall" do end it "takes no arguments" do - lambda { Process.waitall(0) }.should raise_error(ArgumentError) + -> { Process.waitall(0) }.should raise_error(ArgumentError) end platform_is_not :windows do @@ -24,7 +24,7 @@ describe "Process.waitall" do pids << Process.fork { Process.exit! 0 } Process.waitall pids.each { |pid| - lambda { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) + -> { Process.kill(0, pid) }.should raise_error(Errno::ESRCH) } end diff --git a/spec/ruby/core/random/fixtures/classes.rb b/spec/ruby/core/random/fixtures/classes.rb new file mode 100644 index 0000000000..9c8d113e24 --- /dev/null +++ b/spec/ruby/core/random/fixtures/classes.rb @@ -0,0 +1,15 @@ +module RandomSpecs + CustomRangeInteger = Struct.new(:value) do + def to_int; value; end + def <=>(other); to_int <=> other.to_int; end + def -(other); self.class.new(to_int - other.to_int); end + def +(other); self.class.new(to_int + other.to_int); end + end + + CustomRangeFloat = Struct.new(:value) do + def to_f; value; end + def <=>(other); to_f <=> other.to_f; end + def -(other); to_f - other.to_f; end + def +(other); self.class.new(to_f + other.to_f); end + end +end diff --git a/spec/ruby/core/random/new_spec.rb b/spec/ruby/core/random/new_spec.rb index 8160f44d79..07d7b439ca 100644 --- a/spec/ruby/core/random/new_spec.rb +++ b/spec/ruby/core/random/new_spec.rb @@ -30,7 +30,7 @@ describe "Random.new" do end it "raises a RangeError if passed a Complex (with imaginary part) seed value as an argument" do - lambda do + -> do Random.new(Complex(20,2)) end.should raise_error(RangeError) end diff --git a/spec/ruby/core/random/rand_spec.rb b/spec/ruby/core/random/rand_spec.rb index 395e89dc75..b585aa9737 100644 --- a/spec/ruby/core/random/rand_spec.rb +++ b/spec/ruby/core/random/rand_spec.rb @@ -1,4 +1,5 @@ require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "Random.rand" do it "returns a Float if no max argument is passed" do @@ -83,13 +84,13 @@ describe "Random#rand with Fixnum" do end it "raises an ArgumentError when the argument is 0" do - lambda do + -> do Random.new.rand(0) end.should raise_error(ArgumentError) end it "raises an ArgumentError when the argument is negative" do - lambda do + -> do Random.new.rand(-12) end.should raise_error(ArgumentError) end @@ -122,7 +123,7 @@ describe "Random#rand with Bignum" do end it "raises an ArgumentError when the argument is negative" do - lambda do + -> do Random.new.rand(-bignum_value) end.should raise_error(ArgumentError) end @@ -154,7 +155,7 @@ describe "Random#rand with Float" do end it "raises an ArgumentError when the argument is negative" do - lambda do + -> do Random.new.rand(-1.234567) end.should raise_error(ArgumentError) end @@ -165,6 +166,12 @@ describe "Random#rand with Range" do Random.new.rand(20..43).should be_an_instance_of(Fixnum) end + it "supports custom object types" do + rand(RandomSpecs::CustomRangeInteger.new(1)..RandomSpecs::CustomRangeInteger.new(42)).should be_an_instance_of(RandomSpecs::CustomRangeInteger) + rand(RandomSpecs::CustomRangeFloat.new(1.0)..RandomSpecs::CustomRangeFloat.new(42.0)).should be_an_instance_of(RandomSpecs::CustomRangeFloat) + rand(Time.now..Time.now).should be_an_instance_of(Time) + end + it "returns an object that is a member of the Range" do prng = Random.new r = 20..30 @@ -203,13 +210,13 @@ describe "Random#rand with Range" do end it "raises an ArgumentError when the startpoint lacks #+ and #- methods" do - lambda do + -> do Random.new.rand(Object.new..67) end.should raise_error(ArgumentError) end it "raises an ArgumentError when the endpoint lacks #+ and #- methods" do - lambda do + -> do Random.new.rand(68..Object.new) end.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/random/shared/urandom.rb b/spec/ruby/core/random/shared/urandom.rb index 316167b63f..159716075c 100644 --- a/spec/ruby/core/random/shared/urandom.rb +++ b/spec/ruby/core/random/shared/urandom.rb @@ -8,7 +8,7 @@ describe :random_urandom, shared: true do end it "raises an ArgumentError on a negative size" do - lambda { + -> { Random.send(@method, -1) }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/range/bsearch_spec.rb b/spec/ruby/core/range/bsearch_spec.rb index 399bd49623..009cafb00e 100644 --- a/spec/ruby/core/range/bsearch_spec.rb +++ b/spec/ruby/core/range/bsearch_spec.rb @@ -9,22 +9,22 @@ describe "Range#bsearch" do it_behaves_like :enumeratorized_with_unknown_size, :bsearch, (1..3) it "raises a TypeError if the block returns an Object" do - lambda { (0..1).bsearch { Object.new } }.should raise_error(TypeError) + -> { (0..1).bsearch { Object.new } }.should raise_error(TypeError) end it "raises a TypeError if the block returns a String" do - lambda { (0..1).bsearch { "1" } }.should raise_error(TypeError) + -> { (0..1).bsearch { "1" } }.should raise_error(TypeError) end it "raises a TypeError if the Range has Object values" do value = mock("range bsearch") r = Range.new value, value - lambda { r.bsearch { true } }.should raise_error(TypeError) + -> { r.bsearch { true } }.should raise_error(TypeError) end it "raises a TypeError if the Range has String values" do - lambda { ("a".."e").bsearch { true } }.should raise_error(TypeError) + -> { ("a".."e").bsearch { true } }.should raise_error(TypeError) end context "with Integer values" do diff --git a/spec/ruby/core/range/case_compare_spec.rb b/spec/ruby/core/range/case_compare_spec.rb index 37d8cc4677..0ca03f6a35 100644 --- a/spec/ruby/core/range/case_compare_spec.rb +++ b/spec/ruby/core/range/case_compare_spec.rb @@ -13,7 +13,7 @@ describe "Range#===" do it "requires #succ method to be implemented" do range = RangeSpecs::WithoutSucc.new(0)..RangeSpecs::WithoutSucc.new(10) - lambda do + -> do range === RangeSpecs::WithoutSucc.new(2) end.should raise_error(TypeError, /can't iterate from/) end diff --git a/spec/ruby/core/range/each_spec.rb b/spec/ruby/core/range/each_spec.rb index c5253dafd9..110b0602d0 100644 --- a/spec/ruby/core/range/each_spec.rb +++ b/spec/ruby/core/range/each_spec.rb @@ -33,12 +33,12 @@ describe "Range#each" do end it "raises a TypeError if the first element does not respond to #succ" do - lambda { (0.5..2.4).each { |i| i } }.should raise_error(TypeError) + -> { (0.5..2.4).each { |i| i } }.should raise_error(TypeError) b = mock('x') (a = mock('1')).should_receive(:<=>).with(b).and_return(1) - lambda { (a..b).each { |i| i } }.should raise_error(TypeError) + -> { (a..b).each { |i| i } }.should raise_error(TypeError) end it "returns self" do @@ -54,7 +54,7 @@ describe "Range#each" do it "raises a TypeError if the first element is a Time object" do t = Time.now - lambda { (t..t+1).each { |i| i } }.should raise_error(TypeError) + -> { (t..t+1).each { |i| i } }.should raise_error(TypeError) end it "passes each Symbol element by using #succ" do diff --git a/spec/ruby/core/range/first_spec.rb b/spec/ruby/core/range/first_spec.rb index b7ae72ec6c..5f073b48ee 100644 --- a/spec/ruby/core/range/first_spec.rb +++ b/spec/ruby/core/range/first_spec.rb @@ -21,7 +21,7 @@ describe "Range#first" do end it "raises an ArgumentError when count is negative" do - lambda { (0..2).first(-1) }.should raise_error(ArgumentError) + -> { (0..2).first(-1) }.should raise_error(ArgumentError) end it "calls #to_int to convert the argument" do @@ -32,7 +32,7 @@ describe "Range#first" do it "raises a TypeError if #to_int does not return an Integer" do obj = mock("to_int") obj.should_receive(:to_int).and_return("1") - lambda { (2..3).first(obj) }.should raise_error(TypeError) + -> { (2..3).first(obj) }.should raise_error(TypeError) end it "truncates the value when passed a Float" do @@ -40,10 +40,10 @@ describe "Range#first" do end it "raises a TypeError when passed nil" do - lambda { (2..3).first(nil) }.should raise_error(TypeError) + -> { (2..3).first(nil) }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { (2..3).first("1") }.should raise_error(TypeError) + -> { (2..3).first("1") }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/range/initialize_spec.rb b/spec/ruby/core/range/initialize_spec.rb index 53f6485954..8caf12baa2 100644 --- a/spec/ruby/core/range/initialize_spec.rb +++ b/spec/ruby/core/range/initialize_spec.rb @@ -10,32 +10,32 @@ describe "Range#initialize" do end it "initializes correctly the Range object when given 2 arguments" do - lambda { @range.send(:initialize, 0, 1) }.should_not raise_error + -> { @range.send(:initialize, 0, 1) }.should_not raise_error end it "initializes correctly the Range object when given 3 arguments" do - lambda { @range.send(:initialize, 0, 1, true) }.should_not raise_error + -> { @range.send(:initialize, 0, 1, true) }.should_not raise_error end it "raises an ArgumentError if passed without or with only one argument" do - lambda { @range.send(:initialize) }.should raise_error(ArgumentError) - lambda { @range.send(:initialize, 1) }.should raise_error(ArgumentError) + -> { @range.send(:initialize) }.should raise_error(ArgumentError) + -> { @range.send(:initialize, 1) }.should raise_error(ArgumentError) end it "raises an ArgumentError if passed with four or more arguments" do - lambda { @range.send(:initialize, 1, 3, 5, 7) }.should raise_error(ArgumentError) - lambda { @range.send(:initialize, 1, 3, 5, 7, 9) }.should raise_error(ArgumentError) + -> { @range.send(:initialize, 1, 3, 5, 7) }.should raise_error(ArgumentError) + -> { @range.send(:initialize, 1, 3, 5, 7, 9) }.should raise_error(ArgumentError) end it "raises a NameError if called on an already initialized Range" do - lambda { (0..1).send(:initialize, 1, 3) }.should raise_error(NameError) - lambda { (0..1).send(:initialize, 1, 3, true) }.should raise_error(NameError) + -> { (0..1).send(:initialize, 1, 3) }.should raise_error(NameError) + -> { (0..1).send(:initialize, 1, 3, true) }.should raise_error(NameError) end it "raises an ArgumentError if arguments don't respond to <=>" do o1 = Object.new o2 = Object.new - lambda { @range.send(:initialize, o1, o2) }.should raise_error(ArgumentError) + -> { @range.send(:initialize, o1, o2) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/range/last_spec.rb b/spec/ruby/core/range/last_spec.rb index 8983f80cfb..c7e629e62c 100644 --- a/spec/ruby/core/range/last_spec.rb +++ b/spec/ruby/core/range/last_spec.rb @@ -21,7 +21,7 @@ describe "Range#last" do end it "raises an ArgumentError when count is negative" do - lambda { (0..2).last(-1) }.should raise_error(ArgumentError) + -> { (0..2).last(-1) }.should raise_error(ArgumentError) end it "calls #to_int to convert the argument" do @@ -32,7 +32,7 @@ describe "Range#last" do it "raises a TypeError if #to_int does not return an Integer" do obj = mock("to_int") obj.should_receive(:to_int).and_return("1") - lambda { (2..3).last(obj) }.should raise_error(TypeError) + -> { (2..3).last(obj) }.should raise_error(TypeError) end it "truncates the value when passed a Float" do @@ -40,10 +40,10 @@ describe "Range#last" do end it "raises a TypeError when passed nil" do - lambda { (2..3).last(nil) }.should raise_error(TypeError) + -> { (2..3).last(nil) }.should raise_error(TypeError) end it "raises a TypeError when passed a String" do - lambda { (2..3).last("1") }.should raise_error(TypeError) + -> { (2..3).last("1") }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/range/max_spec.rb b/spec/ruby/core/range/max_spec.rb index e6915cc450..faac0a2032 100644 --- a/spec/ruby/core/range/max_spec.rb +++ b/spec/ruby/core/range/max_spec.rb @@ -14,7 +14,7 @@ describe "Range#max" do end it "raises TypeError when called on an exclusive range and a non Integer value" do - lambda { (303.20...908.1111).max }.should raise_error(TypeError) + -> { (303.20...908.1111).max }.should raise_error(TypeError) end it "returns nil when the endpoint is less than the start point" do @@ -43,7 +43,7 @@ describe "Range#max" do it "raises TypeError when called on a Time...Time(excluded end point)" do time_start = Time.now time_end = Time.now + 1.0 - lambda { (time_start...time_end).max }.should raise_error(TypeError) + -> { (time_start...time_end).max }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/range/new_spec.rb b/spec/ruby/core/range/new_spec.rb index 367511742c..9ed2b65d5a 100644 --- a/spec/ruby/core/range/new_spec.rb +++ b/spec/ruby/core/range/new_spec.rb @@ -25,12 +25,12 @@ describe "Range.new" do end it "raises an ArgumentError when the given start and end can't be compared by using #<=>" do - lambda { Range.new(1, mock('x')) }.should raise_error(ArgumentError) - lambda { Range.new(mock('x'), mock('y')) }.should raise_error(ArgumentError) + -> { Range.new(1, mock('x')) }.should raise_error(ArgumentError) + -> { Range.new(mock('x'), mock('y')) }.should raise_error(ArgumentError) b = mock('x') (a = mock('nil')).should_receive(:<=>).with(b).and_return(nil) - lambda { Range.new(a, b) }.should raise_error(ArgumentError) + -> { Range.new(a, b) }.should raise_error(ArgumentError) end ruby_version_is "2.5" do diff --git a/spec/ruby/core/range/shared/cover_and_include.rb b/spec/ruby/core/range/shared/cover_and_include.rb index bed2c77038..a19e2c6ead 100644 --- a/spec/ruby/core/range/shared/cover_and_include.rb +++ b/spec/ruby/core/range/shared/cover_and_include.rb @@ -29,8 +29,8 @@ describe :range_cover_and_include, shared: true do end it "raises an ArgumentError without exactly one argument" do - lambda{ (1..2).send(@method) }.should raise_error(ArgumentError) - lambda{ (1..2).send(@method, 1, 2) }.should raise_error(ArgumentError) + ->{ (1..2).send(@method) }.should raise_error(ArgumentError) + ->{ (1..2).send(@method, 1, 2) }.should raise_error(ArgumentError) end it "returns true if argument is equal to the first value of the range" do diff --git a/spec/ruby/core/range/step_spec.rb b/spec/ruby/core/range/step_spec.rb index eb136a8902..d564e4a5cd 100644 --- a/spec/ruby/core/range/step_spec.rb +++ b/spec/ruby/core/range/step_spec.rb @@ -12,7 +12,7 @@ describe "Range#step" do it "raises TypeError if step" do obj = mock("mock") - lambda { (1..10).step(obj) { } }.should raise_error(TypeError) + -> { (1..10).step(obj) { } }.should raise_error(TypeError) end it "calls #to_int to coerce step to an Integer" do @@ -26,14 +26,14 @@ describe "Range#step" do it "raises a TypeError if step does not respond to #to_int" do obj = mock("Range#step non-integer") - lambda { (1..2).step(obj) { } }.should raise_error(TypeError) + -> { (1..2).step(obj) { } }.should raise_error(TypeError) end it "raises a TypeError if #to_int does not return an Integer" do obj = mock("Range#step non-integer") obj.should_receive(:to_int).and_return("1") - lambda { (1..2).step(obj) { } }.should raise_error(TypeError) + -> { (1..2).step(obj) { } }.should raise_error(TypeError) end it "coerces the argument to integer by invoking to_int" do @@ -47,19 +47,19 @@ describe "Range#step" do obj = mock("Range#step non-comparable") obj.should_receive(:<=>).with(obj).and_return(1) - lambda { (obj..obj).step { |x| x } }.should raise_error(TypeError) + -> { (obj..obj).step { |x| x } }.should raise_error(TypeError) end it "raises an ArgumentError if step is 0" do - lambda { (-1..1).step(0) { |x| x } }.should raise_error(ArgumentError) + -> { (-1..1).step(0) { |x| x } }.should raise_error(ArgumentError) end it "raises an ArgumentError if step is 0.0" do - lambda { (-1..1).step(0.0) { |x| x } }.should raise_error(ArgumentError) + -> { (-1..1).step(0.0) { |x| x } }.should raise_error(ArgumentError) end it "raises an ArgumentError if step is negative" do - lambda { (-1..1).step(-2) { |x| x } }.should raise_error(ArgumentError) + -> { (-1..1).step(-2) { |x| x } }.should raise_error(ArgumentError) end describe "with inclusive end" do @@ -159,7 +159,7 @@ describe "Range#step" do end it "raises a TypeError when passed a Float step" do - lambda { ("A".."G").step(2.0) { } }.should raise_error(TypeError) + -> { ("A".."G").step(2.0) { } }.should raise_error(TypeError) end it "calls #succ on begin and each element returned by #succ" do @@ -269,7 +269,7 @@ describe "Range#step" do end it "raises a TypeError when passed a Float step" do - lambda { ("A"..."G").step(2.0) { } }.should raise_error(TypeError) + -> { ("A"..."G").step(2.0) { } }.should raise_error(TypeError) end end end @@ -280,7 +280,7 @@ describe "Range#step" do it "raises a TypeError if step does not respond to #to_int" do obj = mock("Range#step non-integer") enum = (1..2).step(obj) - lambda { enum.size }.should raise_error(TypeError) + -> { enum.size }.should raise_error(TypeError) end it "raises a TypeError if #to_int does not return an Integer" do @@ -288,23 +288,23 @@ describe "Range#step" do obj.should_receive(:to_int).and_return("1") enum = (1..2).step(obj) - lambda { enum.size }.should raise_error(TypeError) + -> { enum.size }.should raise_error(TypeError) end ruby_version_is ""..."2.6" do it "raises an ArgumentError if step is 0" do enum = (-1..1).step(0) - lambda { enum.size }.should raise_error(ArgumentError) + -> { enum.size }.should raise_error(ArgumentError) end it "raises an ArgumentError if step is 0.0" do enum = (-1..1).step(0.0) - lambda { enum.size }.should raise_error(ArgumentError) + -> { enum.size }.should raise_error(ArgumentError) end it "raises an ArgumentError if step is negative" do enum = (-1..1).step(-2) - lambda { enum.size }.should raise_error(ArgumentError) + -> { enum.size }.should raise_error(ArgumentError) end end @@ -366,7 +366,7 @@ describe "Range#step" do obj = mock("Range#step non-comparable") obj.should_receive(:<=>).with(obj).and_return(1) enum = (obj..obj).step - lambda { enum.size }.should_not raise_error + -> { enum.size }.should_not raise_error enum.size.should == nil end end diff --git a/spec/ruby/core/range/to_a_spec.rb b/spec/ruby/core/range/to_a_spec.rb index ad2fbf5223..15f0b44a9c 100644 --- a/spec/ruby/core/range/to_a_spec.rb +++ b/spec/ruby/core/range/to_a_spec.rb @@ -6,7 +6,7 @@ describe "Range#to_a" do ('A'..'D').to_a.should == ['A','B','C','D'] ('A'...'D').to_a.should == ['A','B','C'] (0xfffd...0xffff).to_a.should == [0xfffd,0xfffe] - lambda { (0.5..2.4).to_a }.should raise_error(TypeError) + -> { (0.5..2.4).to_a }.should raise_error(TypeError) end it "returns empty array for descending-ordered" do diff --git a/spec/ruby/core/rational/rationalize_spec.rb b/spec/ruby/core/rational/rationalize_spec.rb index 61c7411104..3db027d446 100644 --- a/spec/ruby/core/rational/rationalize_spec.rb +++ b/spec/ruby/core/rational/rationalize_spec.rb @@ -30,7 +30,7 @@ describe "Rational#rationalize" do end it "raises ArgumentError when passed more than one argument" do - lambda { Rational(1,1).rationalize(0.1, 0.1) }.should raise_error(ArgumentError) - lambda { Rational(1,1).rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) + -> { Rational(1,1).rationalize(0.1, 0.1) }.should raise_error(ArgumentError) + -> { Rational(1,1).rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/rational/to_r_spec.rb b/spec/ruby/core/rational/to_r_spec.rb index bd1c7c9307..cc704c965e 100644 --- a/spec/ruby/core/rational/to_r_spec.rb +++ b/spec/ruby/core/rational/to_r_spec.rb @@ -5,7 +5,7 @@ describe "Rational#to_r" do it "raises TypeError trying to convert BasicObject" do obj = BasicObject.new - lambda { Rational(obj) }.should raise_error(TypeError) + -> { Rational(obj) }.should raise_error(TypeError) end it "works when a BasicObject has to_r" do @@ -15,6 +15,6 @@ describe "Rational#to_r" do it "fails when a BasicObject's to_r does not return a Rational" do obj = BasicObject.new; def obj.to_r; 1 end - lambda { Rational(obj) }.should raise_error(TypeError) + -> { Rational(obj) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/regexp/initialize_spec.rb b/spec/ruby/core/regexp/initialize_spec.rb index 026348b1dd..36fd5c7bf2 100644 --- a/spec/ruby/core/regexp/initialize_spec.rb +++ b/spec/ruby/core/regexp/initialize_spec.rb @@ -6,10 +6,10 @@ describe "Regexp#initialize" do end it "raises a SecurityError on a Regexp literal" do - lambda { //.send(:initialize, "") }.should raise_error(SecurityError) + -> { //.send(:initialize, "") }.should raise_error(SecurityError) end it "raises a TypeError on an initialized non-literal Regexp" do - lambda { Regexp.new("").send(:initialize, "") }.should raise_error(TypeError) + -> { Regexp.new("").send(:initialize, "") }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/regexp/match_spec.rb b/spec/ruby/core/regexp/match_spec.rb index ebbba38211..a68448b39c 100644 --- a/spec/ruby/core/regexp/match_spec.rb +++ b/spec/ruby/core/regexp/match_spec.rb @@ -35,7 +35,7 @@ describe "Regexp#match" do end it "raises a TypeError on an uninitialized Regexp" do - lambda { Regexp.allocate.match('foo') }.should raise_error(TypeError) + -> { Regexp.allocate.match('foo') }.should raise_error(TypeError) end describe "with [string, position]" do @@ -50,7 +50,7 @@ describe "Regexp#match" do it "raises an ArgumentError for an invalid encoding" do x96 = ([150].pack('C')).force_encoding('utf-8') - lambda { /(.).(.)/.match("Hello, #{x96} world!", 1) }.should raise_error(ArgumentError) + -> { /(.).(.)/.match("Hello, #{x96} world!", 1) }.should raise_error(ArgumentError) end end @@ -65,7 +65,7 @@ describe "Regexp#match" do it "raises an ArgumentError for an invalid encoding" do x96 = ([150].pack('C')).force_encoding('utf-8') - lambda { /(.).(.)/.match("Hello, #{x96} world!", -1) }.should raise_error(ArgumentError) + -> { /(.).(.)/.match("Hello, #{x96} world!", -1) }.should raise_error(ArgumentError) end end @@ -98,12 +98,12 @@ describe "Regexp#match" do it "raises TypeError when the given argument cannot be coerced to String" do f = 1 - lambda { /foo/.match(f)[0] }.should raise_error(TypeError) + -> { /foo/.match(f)[0] }.should raise_error(TypeError) end it "raises TypeError when the given argument is an Exception" do f = Exception.new("foo") - lambda { /foo/.match(f)[0] }.should raise_error(TypeError) + -> { /foo/.match(f)[0] }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/regexp/new_spec.rb b/spec/ruby/core/regexp/new_spec.rb index 8259b61714..d2d867b3d3 100644 --- a/spec/ruby/core/regexp/new_spec.rb +++ b/spec/ruby/core/regexp/new_spec.rb @@ -16,12 +16,12 @@ end describe "Regexp.new given a Fixnum" do it "raises a TypeError" do - lambda { Regexp.new(1) }.should raise_error(TypeError) + -> { Regexp.new(1) }.should raise_error(TypeError) end end describe "Regexp.new given a Float" do it "raises a TypeError" do - lambda { Regexp.new(1.0) }.should raise_error(TypeError) + -> { Regexp.new(1.0) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/regexp/options_spec.rb b/spec/ruby/core/regexp/options_spec.rb index 5fbde89988..fb4853a014 100644 --- a/spec/ruby/core/regexp/options_spec.rb +++ b/spec/ruby/core/regexp/options_spec.rb @@ -29,7 +29,7 @@ describe "Regexp#options" do end it "raises a TypeError on an uninitialized Regexp" do - lambda { Regexp.allocate.options }.should raise_error(TypeError) + -> { Regexp.allocate.options }.should raise_error(TypeError) end it "includes Regexp::FIXEDENCODING for a Regexp literal with the 'u' option" do diff --git a/spec/ruby/core/regexp/shared/new.rb b/spec/ruby/core/regexp/shared/new.rb index ab833ec236..bb5df7bc2e 100644 --- a/spec/ruby/core/regexp/shared/new.rb +++ b/spec/ruby/core/regexp/shared/new.rb @@ -30,7 +30,7 @@ describe :regexp_new_string, shared: true do end it "raises a RegexpError when passed an incorrect regexp" do - lambda { Regexp.send(@method, "^[$", 0) }.should raise_error(RegexpError) + -> { Regexp.send(@method, "^[$", 0) }.should raise_error(RegexpError) end it "does not set Regexp options if only given one argument" do @@ -98,7 +98,7 @@ describe :regexp_new_string, shared: true do end it "ignores the third argument if it is 'e' or 'euc' (case-insensitive)" do - lambda { + -> { Regexp.send(@method, 'Hi', nil, 'e').encoding.should == Encoding::US_ASCII Regexp.send(@method, 'Hi', nil, 'euc').encoding.should == Encoding::US_ASCII Regexp.send(@method, 'Hi', nil, 'E').encoding.should == Encoding::US_ASCII @@ -107,7 +107,7 @@ describe :regexp_new_string, shared: true do end it "ignores the third argument if it is 's' or 'sjis' (case-insensitive)" do - lambda { + -> { Regexp.send(@method, 'Hi', nil, 's').encoding.should == Encoding::US_ASCII Regexp.send(@method, 'Hi', nil, 'sjis').encoding.should == Encoding::US_ASCII Regexp.send(@method, 'Hi', nil, 'S').encoding.should == Encoding::US_ASCII @@ -116,7 +116,7 @@ describe :regexp_new_string, shared: true do end it "ignores the third argument if it is 'u' or 'utf8' (case-insensitive)" do - lambda { + -> { Regexp.send(@method, 'Hi', nil, 'u').encoding.should == Encoding::US_ASCII Regexp.send(@method, 'Hi', nil, 'utf8').encoding.should == Encoding::US_ASCII Regexp.send(@method, 'Hi', nil, 'U').encoding.should == Encoding::US_ASCII @@ -143,11 +143,11 @@ describe :regexp_new_string, shared: true do describe "with escaped characters" do it "raises a Regexp error if there is a trailing backslash" do - lambda { Regexp.send(@method, "\\") }.should raise_error(RegexpError) + -> { Regexp.send(@method, "\\") }.should raise_error(RegexpError) end it "does not raise a Regexp error if there is an escaped trailing backslash" do - lambda { Regexp.send(@method, "\\\\") }.should_not raise_error(RegexpError) + -> { Regexp.send(@method, "\\\\") }.should_not raise_error(RegexpError) end it "accepts a backspace followed by a character" do @@ -175,7 +175,7 @@ describe :regexp_new_string, shared: true do end it "raises a RegexpError if \\x is not followed by any hexadecimal digits" do - lambda { Regexp.send(@method, "\\" + "xn") }.should raise_error(RegexpError) + -> { Regexp.send(@method, "\\" + "xn") }.should raise_error(RegexpError) end it "accepts an escaped string interpolation" do @@ -331,15 +331,15 @@ describe :regexp_new_string, shared: true do end it "raises a RegexpError if less than four digits are given for \\uHHHH" do - lambda { Regexp.send(@method, "\\" + "u304") }.should raise_error(RegexpError) + -> { Regexp.send(@method, "\\" + "u304") }.should raise_error(RegexpError) end it "raises a RegexpError if the \\u{} escape is empty" do - lambda { Regexp.send(@method, "\\" + "u{}") }.should raise_error(RegexpError) + -> { Regexp.send(@method, "\\" + "u{}") }.should raise_error(RegexpError) end it "raises a RegexpError if more than six hexadecimal digits are given" do - lambda { Regexp.send(@method, "\\" + "u{0ffffff}") }.should raise_error(RegexpError) + -> { Regexp.send(@method, "\\" + "u{0ffffff}") }.should raise_error(RegexpError) end it "returns a Regexp with US-ASCII encoding if only 7-bit ASCII characters are present regardless of the input String's encoding" do @@ -475,7 +475,7 @@ describe :regexp_new_regexp, shared: true do it "does not honour options given as additional arguments" do r = nil - lambda { + -> { r = Regexp.send @method, /hi/, Regexp::IGNORECASE }.should complain(/flags ignored/) (r.options & Regexp::IGNORECASE).should == 0 diff --git a/spec/ruby/core/regexp/union_spec.rb b/spec/ruby/core/regexp/union_spec.rb index 25901c6f2b..81a31d89b3 100644 --- a/spec/ruby/core/regexp/union_spec.rb +++ b/spec/ruby/core/regexp/union_spec.rb @@ -52,83 +52,83 @@ describe "Regexp.union" do end it "raises ArgumentError if the arguments include conflicting ASCII-incompatible Strings" do - lambda { + -> { Regexp.union("a".encode("UTF-16LE"), "b".encode("UTF-16BE")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include conflicting ASCII-incompatible Regexps" do - lambda { + -> { Regexp.union(Regexp.new("a".encode("UTF-16LE")), Regexp.new("b".encode("UTF-16BE"))) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include conflicting fixed encoding Regexps" do - lambda { + -> { Regexp.union(Regexp.new("a".encode("UTF-8"), Regexp::FIXEDENCODING), Regexp.new("b".encode("US-ASCII"), Regexp::FIXEDENCODING)) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include a fixed encoding Regexp and a String containing non-ASCII-compatible characters in a different encoding" do - lambda { + -> { Regexp.union(Regexp.new("a".encode("UTF-8"), Regexp::FIXEDENCODING), "\u00A9".encode("ISO-8859-1")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include a String containing non-ASCII-compatible characters and a fixed encoding Regexp in a different encoding" do - lambda { + -> { Regexp.union("\u00A9".encode("ISO-8859-1"), Regexp.new("a".encode("UTF-8"), Regexp::FIXEDENCODING)) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include an ASCII-incompatible String and an ASCII-only String" do - lambda { + -> { Regexp.union("a".encode("UTF-16LE"), "b".encode("UTF-8")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and an ASCII-only String" do - lambda { + -> { Regexp.union(Regexp.new("a".encode("UTF-16LE")), "b".encode("UTF-8")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include an ASCII-incompatible String and an ASCII-only Regexp" do - lambda { + -> { Regexp.union("a".encode("UTF-16LE"), Regexp.new("b".encode("UTF-8"))) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and an ASCII-only Regexp" do - lambda { + -> { Regexp.union(Regexp.new("a".encode("UTF-16LE")), Regexp.new("b".encode("UTF-8"))) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include an ASCII-incompatible String and a String containing non-ASCII-compatible characters in a different encoding" do - lambda { + -> { Regexp.union("a".encode("UTF-16LE"), "\u00A9".encode("ISO-8859-1")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and a String containing non-ASCII-compatible characters in a different encoding" do - lambda { + -> { Regexp.union(Regexp.new("a".encode("UTF-16LE")), "\u00A9".encode("ISO-8859-1")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include an ASCII-incompatible String and a Regexp containing non-ASCII-compatible characters in a different encoding" do - lambda { + -> { Regexp.union("a".encode("UTF-16LE"), Regexp.new("\u00A9".encode("ISO-8859-1"))) }.should raise_error(ArgumentError) end it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and a Regexp containing non-ASCII-compatible characters in a different encoding" do - lambda { + -> { Regexp.union(Regexp.new("a".encode("UTF-16LE")), Regexp.new("\u00A9".encode("ISO-8859-1"))) }.should raise_error(ArgumentError) end @@ -144,6 +144,6 @@ describe "Regexp.union" do not_supported_on :opal do Regexp.union([/dogs/, /cats/i]).should == /(?-mix:dogs)|(?i-mx:cats)/ end - lambda{Regexp.union(["skiing", "sledding"], [/dogs/, /cats/i])}.should raise_error(TypeError) + ->{Regexp.union(["skiing", "sledding"], [/dogs/, /cats/i])}.should raise_error(TypeError) end end diff --git a/spec/ruby/core/signal/signame_spec.rb b/spec/ruby/core/signal/signame_spec.rb index 41b43d3482..b66de9fc85 100644 --- a/spec/ruby/core/signal/signame_spec.rb +++ b/spec/ruby/core/signal/signame_spec.rb @@ -10,7 +10,7 @@ describe "Signal.signame" do end it "raises a TypeError when the passed argument can't be coerced to Integer" do - lambda { Signal.signame("hello") }.should raise_error(TypeError) + -> { Signal.signame("hello") }.should raise_error(TypeError) end platform_is_not :windows do diff --git a/spec/ruby/core/sizedqueue/append_spec.rb b/spec/ruby/core/sizedqueue/append_spec.rb index ff96b46d2c..ca79068930 100644 --- a/spec/ruby/core/sizedqueue/append_spec.rb +++ b/spec/ruby/core/sizedqueue/append_spec.rb @@ -7,5 +7,5 @@ describe "SizedQueue#<<" do end describe "SizedQueue#<<" do - it_behaves_like :sizedqueue_enq, :<<, ->(n) { SizedQueue.new(n) } + it_behaves_like :sizedqueue_enq, :<<, -> n { SizedQueue.new(n) } end diff --git a/spec/ruby/core/sizedqueue/enq_spec.rb b/spec/ruby/core/sizedqueue/enq_spec.rb index 11c65ec14d..3821afac95 100644 --- a/spec/ruby/core/sizedqueue/enq_spec.rb +++ b/spec/ruby/core/sizedqueue/enq_spec.rb @@ -7,5 +7,5 @@ describe "SizedQueue#enq" do end describe "SizedQueue#enq" do - it_behaves_like :sizedqueue_enq, :enq, ->(n) { SizedQueue.new(n) } + it_behaves_like :sizedqueue_enq, :enq, -> n { SizedQueue.new(n) } end diff --git a/spec/ruby/core/sizedqueue/max_spec.rb b/spec/ruby/core/sizedqueue/max_spec.rb index b65a67eeb0..cbabb5dc10 100644 --- a/spec/ruby/core/sizedqueue/max_spec.rb +++ b/spec/ruby/core/sizedqueue/max_spec.rb @@ -2,9 +2,9 @@ require_relative '../../spec_helper' require_relative '../../shared/sizedqueue/max' describe "SizedQueue#max" do - it_behaves_like :sizedqueue_max, :max, ->(n) { SizedQueue.new(n) } + it_behaves_like :sizedqueue_max, :max, -> n { SizedQueue.new(n) } end describe "SizedQueue#max=" do - it_behaves_like :sizedqueue_max=, :max=, ->(n) { SizedQueue.new(n) } + it_behaves_like :sizedqueue_max=, :max=, -> n { SizedQueue.new(n) } end diff --git a/spec/ruby/core/sizedqueue/new_spec.rb b/spec/ruby/core/sizedqueue/new_spec.rb index 8febbfa63b..d5704732c3 100644 --- a/spec/ruby/core/sizedqueue/new_spec.rb +++ b/spec/ruby/core/sizedqueue/new_spec.rb @@ -2,5 +2,5 @@ require_relative '../../spec_helper' require_relative '../../shared/sizedqueue/new' describe "SizedQueue.new" do - it_behaves_like :sizedqueue_new, :new, ->(*n) { SizedQueue.new(*n) } + it_behaves_like :sizedqueue_new, :new, -> *n { SizedQueue.new(*n) } end diff --git a/spec/ruby/core/sizedqueue/num_waiting_spec.rb b/spec/ruby/core/sizedqueue/num_waiting_spec.rb index cbbbb2d062..9aef25e33d 100644 --- a/spec/ruby/core/sizedqueue/num_waiting_spec.rb +++ b/spec/ruby/core/sizedqueue/num_waiting_spec.rb @@ -2,5 +2,5 @@ require_relative '../../spec_helper' require_relative '../../shared/sizedqueue/num_waiting' describe "SizedQueue#num_waiting" do - it_behaves_like :sizedqueue_num_waiting, :new, ->(n) { SizedQueue.new(n) } + it_behaves_like :sizedqueue_num_waiting, :new, -> n { SizedQueue.new(n) } end diff --git a/spec/ruby/core/sizedqueue/push_spec.rb b/spec/ruby/core/sizedqueue/push_spec.rb index 5f92c5a2b7..bba9be9e3f 100644 --- a/spec/ruby/core/sizedqueue/push_spec.rb +++ b/spec/ruby/core/sizedqueue/push_spec.rb @@ -7,5 +7,5 @@ describe "SizedQueue#push" do end describe "SizedQueue#push" do - it_behaves_like :sizedqueue_enq, :push, ->(n) { SizedQueue.new(n) } + it_behaves_like :sizedqueue_enq, :push, -> n { SizedQueue.new(n) } end diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb index c7f4aed20c..df64cdaa3b 100644 --- a/spec/ruby/core/string/capitalize_spec.rb +++ b/spec/ruby/core/string/capitalize_spec.rb @@ -52,7 +52,7 @@ describe "String#capitalize" do end it "does not allow any other additional option" do - lambda { "iSa".capitalize(:turkic, :ascii) }.should raise_error(ArgumentError) + -> { "iSa".capitalize(:turkic, :ascii) }.should raise_error(ArgumentError) end end @@ -66,16 +66,16 @@ describe "String#capitalize" do end it "does not allow any other additional option" do - lambda { "iß".capitalize(:lithuanian, :ascii) }.should raise_error(ArgumentError) + -> { "iß".capitalize(:lithuanian, :ascii) }.should raise_error(ArgumentError) end end it "does not allow the :fold option for upcasing" do - lambda { "abc".capitalize(:fold) }.should raise_error(ArgumentError) + -> { "abc".capitalize(:fold) }.should raise_error(ArgumentError) end it "does not allow invalid options" do - lambda { "abc".capitalize(:invalid_option) }.should raise_error(ArgumentError) + -> { "abc".capitalize(:invalid_option) }.should raise_error(ArgumentError) end it "returns subclass instances when called on a subclass" do @@ -137,7 +137,7 @@ describe "String#capitalize!" do end it "does not allow any other additional option" do - lambda { a = "iSa"; a.capitalize!(:turkic, :ascii) }.should raise_error(ArgumentError) + -> { a = "iSa"; a.capitalize!(:turkic, :ascii) }.should raise_error(ArgumentError) end end @@ -155,16 +155,16 @@ describe "String#capitalize!" do end it "does not allow any other additional option" do - lambda { a = "iß"; a.capitalize!(:lithuanian, :ascii) }.should raise_error(ArgumentError) + -> { a = "iß"; a.capitalize!(:lithuanian, :ascii) }.should raise_error(ArgumentError) end end it "does not allow the :fold option for upcasing" do - lambda { a = "abc"; a.capitalize!(:fold) }.should raise_error(ArgumentError) + -> { a = "abc"; a.capitalize!(:fold) }.should raise_error(ArgumentError) end it "does not allow invalid options" do - lambda { a = "abc"; a.capitalize!(:invalid_option) }.should raise_error(ArgumentError) + -> { a = "abc"; a.capitalize!(:invalid_option) }.should raise_error(ArgumentError) end it "returns nil when no changes are made" do @@ -179,7 +179,7 @@ describe "String#capitalize!" do it "raises a #{frozen_error_class} when self is frozen" do ["", "Hello", "hello"].each do |a| a.freeze - lambda { a.capitalize! }.should raise_error(frozen_error_class) + -> { a.capitalize! }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/casecmp_spec.rb b/spec/ruby/core/string/casecmp_spec.rb index 35afcc0152..01b22e8f13 100644 --- a/spec/ruby/core/string/casecmp_spec.rb +++ b/spec/ruby/core/string/casecmp_spec.rb @@ -27,7 +27,7 @@ describe "String#casecmp independent of case" do ruby_version_is ""..."2.5" do it "raises a TypeError if other can't be converted to a string" do - lambda { "abc".casecmp(mock('abc')) }.should raise_error(TypeError) + -> { "abc".casecmp(mock('abc')) }.should raise_error(TypeError) end end @@ -198,7 +198,7 @@ describe 'String#casecmp? independent of case' do ruby_version_is "2.4"..."2.5" do it "raises a TypeError if other can't be converted to a string" do - lambda { "abc".casecmp?(mock('abc')) }.should raise_error(TypeError) + -> { "abc".casecmp?(mock('abc')) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/string/center_spec.rb b/spec/ruby/core/string/center_spec.rb index 3a9e689eac..27f8b7387f 100644 --- a/spec/ruby/core/string/center_spec.rb +++ b/spec/ruby/core/string/center_spec.rb @@ -65,10 +65,10 @@ describe "String#center with length, padding" do end it "raises a TypeError when length can't be converted to an integer" do - lambda { "hello".center("x") }.should raise_error(TypeError) - lambda { "hello".center("x", "y") }.should raise_error(TypeError) - lambda { "hello".center([]) }.should raise_error(TypeError) - lambda { "hello".center(mock('x')) }.should raise_error(TypeError) + -> { "hello".center("x") }.should raise_error(TypeError) + -> { "hello".center("x", "y") }.should raise_error(TypeError) + -> { "hello".center([]) }.should raise_error(TypeError) + -> { "hello".center(mock('x')) }.should raise_error(TypeError) end it "calls #to_str to convert padstr to a String" do @@ -79,14 +79,14 @@ describe "String#center with length, padding" do end it "raises a TypeError when padstr can't be converted to a string" do - lambda { "hello".center(20, 100) }.should raise_error(TypeError) - lambda { "hello".center(20, []) }.should raise_error(TypeError) - lambda { "hello".center(20, mock('x')) }.should raise_error(TypeError) + -> { "hello".center(20, 100) }.should raise_error(TypeError) + -> { "hello".center(20, []) }.should raise_error(TypeError) + -> { "hello".center(20, mock('x')) }.should raise_error(TypeError) end it "raises an ArgumentError if padstr is empty" do - lambda { "hello".center(10, "") }.should raise_error(ArgumentError) - lambda { "hello".center(0, "") }.should raise_error(ArgumentError) + -> { "hello".center(10, "") }.should raise_error(ArgumentError) + -> { "hello".center(0, "") }.should raise_error(ArgumentError) end it "returns subclass instances when called on subclasses" do @@ -123,7 +123,7 @@ describe "String#center with length, padding" do it "raises an Encoding::CompatibilityError if the encodings are incompatible" do pat = "ア".encode Encoding::EUC_JP - lambda do + -> do "あれ".center 5, pat end.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/core/string/chomp_spec.rb b/spec/ruby/core/string/chomp_spec.rb index 7400d71336..9db47d1dc6 100644 --- a/spec/ruby/core/string/chomp_spec.rb +++ b/spec/ruby/core/string/chomp_spec.rb @@ -134,7 +134,7 @@ describe "String#chomp" do it "raises a TypeError if #to_str does not return a String" do arg = mock("string chomp") arg.should_receive(:to_str).and_return(1) - lambda { "abc".chomp(arg) }.should raise_error(TypeError) + -> { "abc".chomp(arg) }.should raise_error(TypeError) end end @@ -288,7 +288,7 @@ describe "String#chomp!" do it "raises a TypeError if #to_str does not return a String" do arg = mock("string chomp") arg.should_receive(:to_str).and_return(1) - lambda { "abc".chomp!(arg) }.should raise_error(TypeError) + -> { "abc".chomp!(arg) }.should raise_error(TypeError) end end @@ -318,15 +318,15 @@ describe "String#chomp!" do a = "string\n\r" a.freeze - lambda { a.chomp! }.should raise_error(frozen_error_class) + -> { a.chomp! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] it "raises a #{frozen_error_class} on a frozen instance when it would not be modified" do a = "string\n\r" a.freeze - lambda { a.chomp!(nil) }.should raise_error(frozen_error_class) - lambda { a.chomp!("x") }.should raise_error(frozen_error_class) + -> { a.chomp!(nil) }.should raise_error(frozen_error_class) + -> { a.chomp!("x") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/chop_spec.rb b/spec/ruby/core/string/chop_spec.rb index f33da3ecc4..35a5766b2f 100644 --- a/spec/ruby/core/string/chop_spec.rb +++ b/spec/ruby/core/string/chop_spec.rb @@ -112,13 +112,13 @@ describe "String#chop!" do end it "raises a #{frozen_error_class} on a frozen instance that is modified" do - lambda { "string\n\r".freeze.chop! }.should raise_error(frozen_error_class) + -> { "string\n\r".freeze.chop! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do a = "" a.freeze - lambda { a.chop! }.should raise_error(frozen_error_class) + -> { a.chop! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/clear_spec.rb b/spec/ruby/core/string/clear_spec.rb index 45d452e947..0b5b8e6998 100644 --- a/spec/ruby/core/string/clear_spec.rb +++ b/spec/ruby/core/string/clear_spec.rb @@ -31,7 +31,7 @@ describe "String#clear" do it "raises a #{frozen_error_class} if self is frozen" do @s.freeze - lambda { @s.clear }.should raise_error(frozen_error_class) - lambda { "".freeze.clear }.should raise_error(frozen_error_class) + -> { @s.clear }.should raise_error(frozen_error_class) + -> { "".freeze.clear }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/codepoints_spec.rb b/spec/ruby/core/string/codepoints_spec.rb index e5eeb8b69d..0b6cde82f7 100644 --- a/spec/ruby/core/string/codepoints_spec.rb +++ b/spec/ruby/core/string/codepoints_spec.rb @@ -13,6 +13,6 @@ describe "String#codepoints" do it "raises an ArgumentError when no block is given if self has an invalid encoding" do s = "\xDF".force_encoding(Encoding::UTF_8) s.valid_encoding?.should be_false - lambda { s.codepoints }.should raise_error(ArgumentError) + -> { s.codepoints }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/count_spec.rb b/spec/ruby/core/string/count_spec.rb index e82a7c77ca..06ba5a4f0e 100644 --- a/spec/ruby/core/string/count_spec.rb +++ b/spec/ruby/core/string/count_spec.rb @@ -23,7 +23,7 @@ describe "String#count" do end it "raises an ArgumentError when given no arguments" do - lambda { "hell yeah".count }.should raise_error(ArgumentError) + -> { "hell yeah".count }.should raise_error(ArgumentError) end it "negates sets starting with ^" do @@ -76,8 +76,8 @@ describe "String#count" do it "raises if the given sequences are invalid" do s = "hel-[()]-lo012^" - lambda { s.count("h-e") }.should raise_error(ArgumentError) - lambda { s.count("^h-e") }.should raise_error(ArgumentError) + -> { s.count("h-e") }.should raise_error(ArgumentError) + -> { s.count("^h-e") }.should raise_error(ArgumentError) end it 'returns the number of occurrences of a multi-byte character' do @@ -98,8 +98,8 @@ describe "String#count" do end it "raises a TypeError when a set arg can't be converted to a string" do - lambda { "hello world".count(100) }.should raise_error(TypeError) - lambda { "hello world".count([]) }.should raise_error(TypeError) - lambda { "hello world".count(mock('x')) }.should raise_error(TypeError) + -> { "hello world".count(100) }.should raise_error(TypeError) + -> { "hello world".count([]) }.should raise_error(TypeError) + -> { "hello world".count(mock('x')) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/string/crypt_spec.rb b/spec/ruby/core/string/crypt_spec.rb index 66161b280f..7a0f8835f2 100644 --- a/spec/ruby/core/string/crypt_spec.rb +++ b/spec/ruby/core/string/crypt_spec.rb @@ -15,7 +15,7 @@ describe "String#crypt" do end it "raises Errno::EINVAL when the salt is shorter than 29 characters" do - lambda { "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHW") }.should raise_error(Errno::EINVAL) + -> { "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHW") }.should raise_error(Errno::EINVAL) end it "calls #to_str to converts the salt arg to a String" do @@ -73,7 +73,7 @@ describe "String#crypt" do end it "raises an ArgumentError when the string contains NUL character" do - lambda { "poison\0null".crypt("aa") }.should raise_error(ArgumentError) + -> { "poison\0null".crypt("aa") }.should raise_error(ArgumentError) end it "calls #to_str to converts the salt arg to a String" do @@ -103,16 +103,16 @@ describe "String#crypt" do end it "raises an ArgumentError when the salt is shorter than two characters" do - lambda { "hello".crypt("") }.should raise_error(ArgumentError) - lambda { "hello".crypt("f") }.should raise_error(ArgumentError) - lambda { "hello".crypt("\x00\x00") }.should raise_error(ArgumentError) - lambda { "hello".crypt("\x00a") }.should raise_error(ArgumentError) - lambda { "hello".crypt("a\x00") }.should raise_error(ArgumentError) + -> { "hello".crypt("") }.should raise_error(ArgumentError) + -> { "hello".crypt("f") }.should raise_error(ArgumentError) + -> { "hello".crypt("\x00\x00") }.should raise_error(ArgumentError) + -> { "hello".crypt("\x00a") }.should raise_error(ArgumentError) + -> { "hello".crypt("a\x00") }.should raise_error(ArgumentError) end end it "raises a type error when the salt arg can't be converted to a string" do - lambda { "".crypt(5) }.should raise_error(TypeError) - lambda { "".crypt(mock('x')) }.should raise_error(TypeError) + -> { "".crypt(5) }.should raise_error(TypeError) + -> { "".crypt(mock('x')) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/string/delete_prefix_spec.rb b/spec/ruby/core/string/delete_prefix_spec.rb index 4b4858c9c2..b88c503658 100644 --- a/spec/ruby/core/string/delete_prefix_spec.rb +++ b/spec/ruby/core/string/delete_prefix_spec.rb @@ -73,9 +73,9 @@ ruby_version_is '2.5' do end it "raises a #{frozen_error_class} when self is frozen" do - lambda { 'hello'.freeze.delete_prefix!('hell') }.should raise_error(frozen_error_class) - lambda { 'hello'.freeze.delete_prefix!('') }.should raise_error(frozen_error_class) - lambda { ''.freeze.delete_prefix!('') }.should raise_error(frozen_error_class) + -> { 'hello'.freeze.delete_prefix!('hell') }.should raise_error(frozen_error_class) + -> { 'hello'.freeze.delete_prefix!('') }.should raise_error(frozen_error_class) + -> { ''.freeze.delete_prefix!('') }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/delete_spec.rb b/spec/ruby/core/string/delete_spec.rb index 8725b54c3b..6136cd54af 100644 --- a/spec/ruby/core/string/delete_spec.rb +++ b/spec/ruby/core/string/delete_spec.rb @@ -14,7 +14,7 @@ describe "String#delete" do end it "raises an ArgumentError when given no arguments" do - lambda { "hell yeah".delete }.should raise_error(ArgumentError) + -> { "hell yeah".delete }.should raise_error(ArgumentError) end it "negates sets starting with ^" do @@ -62,10 +62,10 @@ describe "String#delete" do not_supported_on :opal do xFF = [0xFF].pack('C') range = "\x00 - #{xFF}".force_encoding('utf-8') - lambda { "hello".delete(range).should == "" }.should raise_error(ArgumentError) + -> { "hello".delete(range).should == "" }.should raise_error(ArgumentError) end - lambda { "hello".delete("h-e") }.should raise_error(ArgumentError) - lambda { "hello".delete("^h-e") }.should raise_error(ArgumentError) + -> { "hello".delete("h-e") }.should raise_error(ArgumentError) + -> { "hello".delete("^h-e") }.should raise_error(ArgumentError) end it "taints result when self is tainted" do @@ -86,9 +86,9 @@ describe "String#delete" do end it "raises a TypeError when one set arg can't be converted to a string" do - lambda { "hello world".delete(100) }.should raise_error(TypeError) - lambda { "hello world".delete([]) }.should raise_error(TypeError) - lambda { "hello world".delete(mock('x')) }.should raise_error(TypeError) + -> { "hello world".delete(100) }.should raise_error(TypeError) + -> { "hello world".delete([]) }.should raise_error(TypeError) + -> { "hello world".delete(mock('x')) }.should raise_error(TypeError) end it "returns subclass instances when called on a subclass" do @@ -113,7 +113,7 @@ describe "String#delete!" do a = "hello" a.freeze - lambda { a.delete!("") }.should raise_error(frozen_error_class) - lambda { a.delete!("aeiou", "^e") }.should raise_error(frozen_error_class) + -> { a.delete!("") }.should raise_error(frozen_error_class) + -> { a.delete!("aeiou", "^e") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/delete_suffix_spec.rb b/spec/ruby/core/string/delete_suffix_spec.rb index 8541c1d5d2..94909cf71d 100644 --- a/spec/ruby/core/string/delete_suffix_spec.rb +++ b/spec/ruby/core/string/delete_suffix_spec.rb @@ -73,9 +73,9 @@ ruby_version_is '2.5' do end it "raises a #{frozen_error_class} when self is frozen" do - lambda { 'hello'.freeze.delete_suffix!('ello') }.should raise_error(frozen_error_class) - lambda { 'hello'.freeze.delete_suffix!('') }.should raise_error(frozen_error_class) - lambda { ''.freeze.delete_suffix!('') }.should raise_error(frozen_error_class) + -> { 'hello'.freeze.delete_suffix!('ello') }.should raise_error(frozen_error_class) + -> { 'hello'.freeze.delete_suffix!('') }.should raise_error(frozen_error_class) + -> { ''.freeze.delete_suffix!('') }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb index 9d57ea8e25..31c8f3f446 100644 --- a/spec/ruby/core/string/downcase_spec.rb +++ b/spec/ruby/core/string/downcase_spec.rb @@ -39,7 +39,7 @@ describe "String#downcase" do end it "does not allow any other additional option" do - lambda { "İ".downcase(:turkic, :ascii) }.should raise_error(ArgumentError) + -> { "İ".downcase(:turkic, :ascii) }.should raise_error(ArgumentError) end end @@ -53,7 +53,7 @@ describe "String#downcase" do end it "does not allow any other additional option" do - lambda { "İS".downcase(:lithuanian, :ascii) }.should raise_error(ArgumentError) + -> { "İS".downcase(:lithuanian, :ascii) }.should raise_error(ArgumentError) end end @@ -65,7 +65,7 @@ describe "String#downcase" do end it "does not allow invalid options" do - lambda { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError) + -> { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError) end it "taints result when self is tainted" do @@ -126,7 +126,7 @@ describe "String#downcase!" do end it "does not allow any other additional option" do - lambda { a = "İ"; a.downcase!(:turkic, :ascii) }.should raise_error(ArgumentError) + -> { a = "İ"; a.downcase!(:turkic, :ascii) }.should raise_error(ArgumentError) end end @@ -144,7 +144,7 @@ describe "String#downcase!" do end it "does not allow any other additional option" do - lambda { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError) + -> { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError) end end @@ -160,7 +160,7 @@ describe "String#downcase!" do end it "does not allow invalid options" do - lambda { a = "ABC"; a.downcase!(:invalid_option) }.should raise_error(ArgumentError) + -> { a = "ABC"; a.downcase!(:invalid_option) }.should raise_error(ArgumentError) end it "returns nil if no modifications were made" do @@ -170,8 +170,8 @@ describe "String#downcase!" do end it "raises a #{frozen_error_class} when self is frozen" do - lambda { "HeLlo".freeze.downcase! }.should raise_error(frozen_error_class) - lambda { "hello".freeze.downcase! }.should raise_error(frozen_error_class) + -> { "HeLlo".freeze.downcase! }.should raise_error(frozen_error_class) + -> { "hello".freeze.downcase! }.should raise_error(frozen_error_class) end it "sets the result String encoding to the source String encoding" do diff --git a/spec/ruby/core/string/dup_spec.rb b/spec/ruby/core/string/dup_spec.rb index 3c6021b5c2..d650788210 100644 --- a/spec/ruby/core/string/dup_spec.rb +++ b/spec/ruby/core/string/dup_spec.rb @@ -21,7 +21,7 @@ describe "String#dup" do it "does not copy singleton methods" do def @obj.special() :the_one end dup = @obj.dup - lambda { dup.special }.should raise_error(NameError) + -> { dup.special }.should raise_error(NameError) end it "does not copy modules included in the singleton class" do @@ -30,7 +30,7 @@ describe "String#dup" do end dup = @obj.dup - lambda { dup.repr }.should raise_error(NameError) + -> { dup.repr }.should raise_error(NameError) end it "does not copy constants defined in the singleton class" do @@ -39,7 +39,7 @@ describe "String#dup" do end dup = @obj.dup - lambda { class << dup; CLONE; end }.should raise_error(NameError) + -> { class << dup; CLONE; end }.should raise_error(NameError) end it "does not modify the original string when changing dupped string" do diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb index 1fdf72ab0f..34e122b055 100644 --- a/spec/ruby/core/string/element_set_spec.rb +++ b/spec/ruby/core/string/element_set_spec.rb @@ -27,13 +27,13 @@ describe "String#[]= with Fixnum index" do it "raises an IndexError without changing self if idx is outside of self" do str = "hello" - lambda { str[20] = "bam" }.should raise_error(IndexError) + -> { str[20] = "bam" }.should raise_error(IndexError) str.should == "hello" - lambda { str[-20] = "bam" }.should raise_error(IndexError) + -> { str[-20] = "bam" }.should raise_error(IndexError) str.should == "hello" - lambda { ""[-1] = "bam" }.should raise_error(IndexError) + -> { ""[-1] = "bam" }.should raise_error(IndexError) end # Behaviour is verified by matz in @@ -46,7 +46,7 @@ describe "String#[]= with Fixnum index" do it "raises IndexError if the string index doesn't match a position in the string" do str = "hello" - lambda { str['y'] = "bam" }.should raise_error(IndexError) + -> { str['y'] = "bam" }.should raise_error(IndexError) str.should == "hello" end @@ -54,7 +54,7 @@ describe "String#[]= with Fixnum index" do a = "hello" a.freeze - lambda { a[0] = "bam" }.should raise_error(frozen_error_class) + -> { a[0] = "bam" }.should raise_error(frozen_error_class) end it "calls to_int on index" do @@ -78,17 +78,17 @@ describe "String#[]= with Fixnum index" do end it "raises a TypeError if other_str can't be converted to a String" do - lambda { "test"[1] = [] }.should raise_error(TypeError) - lambda { "test"[1] = mock('x') }.should raise_error(TypeError) - lambda { "test"[1] = nil }.should raise_error(TypeError) + -> { "test"[1] = [] }.should raise_error(TypeError) + -> { "test"[1] = mock('x') }.should raise_error(TypeError) + -> { "test"[1] = nil }.should raise_error(TypeError) end it "raises a TypeError if passed a Fixnum replacement" do - lambda { "abc"[1] = 65 }.should raise_error(TypeError) + -> { "abc"[1] = 65 }.should raise_error(TypeError) end it "raises an IndexError if the index is greater than character size" do - lambda { "あれ"[4] = "a" }.should raise_error(IndexError) + -> { "あれ"[4] = "a" }.should raise_error(IndexError) end it "calls #to_int to convert the index" do @@ -104,14 +104,14 @@ describe "String#[]= with Fixnum index" do index = mock("string element set") index.should_receive(:to_int).and_return('1') - lambda { "abc"[index] = "d" }.should raise_error(TypeError) + -> { "abc"[index] = "d" }.should raise_error(TypeError) end it "raises an IndexError if #to_int returns a value out of range" do index = mock("string element set") index.should_receive(:to_int).and_return(4) - lambda { "ab"[index] = "c" }.should raise_error(IndexError) + -> { "ab"[index] = "c" }.should raise_error(IndexError) end it "replaces a character with a multibyte character" do @@ -142,7 +142,7 @@ describe "String#[]= with Fixnum index" do it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do str = "あれ" rep = "が".encode Encoding::EUC_JP - lambda { str[0] = rep }.should raise_error(Encoding::CompatibilityError) + -> { str[0] = rep }.should raise_error(Encoding::CompatibilityError) end end @@ -167,7 +167,7 @@ describe "String#[]= with String index" do it "raises an IndexError if the search String is not found" do str = "abcde" - lambda { str["g"] = "h" }.should raise_error(IndexError) + -> { str["g"] = "h" }.should raise_error(IndexError) end it "replaces characters with a multibyte character" do @@ -198,7 +198,7 @@ describe "String#[]= with String index" do it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do str = "あれ" rep = "が".encode Encoding::EUC_JP - lambda { str["れ"] = rep }.should raise_error(Encoding::CompatibilityError) + -> { str["れ"] = rep }.should raise_error(Encoding::CompatibilityError) end end @@ -211,7 +211,7 @@ describe "String#[]= with a Regexp index" do it "raises IndexError if the regexp index doesn't match a position in the string" do str = "hello" - lambda { str[/y/] = "bam" }.should raise_error(IndexError) + -> { str[/y/] = "bam" }.should raise_error(IndexError) str.should == "hello" end @@ -228,7 +228,7 @@ describe "String#[]= with a Regexp index" do rep = mock("string element set regexp") rep.should_not_receive(:to_str) - lambda { "abc"[/def/] = rep }.should raise_error(IndexError) + -> { "abc"[/def/] = rep }.should raise_error(IndexError) end describe "with 3 arguments" do @@ -245,7 +245,7 @@ describe "String#[]= with a Regexp index" do ref = mock("string element set regexp ref") ref.should_receive(:to_int).and_return(nil) - lambda { "abc"[/a(b)/, ref] = "x" }.should raise_error(TypeError) + -> { "abc"[/a(b)/, ref] = "x" }.should raise_error(TypeError) end it "uses the 2nd of 3 arguments as which capture should be replaced" do @@ -264,20 +264,20 @@ describe "String#[]= with a Regexp index" do rep = mock("string element set regexp") rep.should_not_receive(:to_str) - lambda { "abc"[/a(b)/, 2] = rep }.should raise_error(IndexError) + -> { "abc"[/a(b)/, 2] = rep }.should raise_error(IndexError) end it "raises IndexError if the specified capture isn't available" do str = "aaa bbb ccc" - lambda { str[/a (bbb) c/, 2] = "ddd" }.should raise_error(IndexError) - lambda { str[/a (bbb) c/, -2] = "ddd" }.should raise_error(IndexError) + -> { str[/a (bbb) c/, 2] = "ddd" }.should raise_error(IndexError) + -> { str[/a (bbb) c/, -2] = "ddd" }.should raise_error(IndexError) end describe "when the optional capture does not match" do it "raises an IndexError before setting the replacement" do str1 = "a b c" str2 = str1.dup - lambda { str2[/a (b) (Z)?/, 2] = "d" }.should raise_error(IndexError) + -> { str2[/a (b) (Z)?/, 2] = "d" }.should raise_error(IndexError) str2.should == str1 end end @@ -311,7 +311,7 @@ describe "String#[]= with a Regexp index" do it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do str = "あれ" rep = "が".encode Encoding::EUC_JP - lambda { str[/れ/] = rep }.should raise_error(Encoding::CompatibilityError) + -> { str[/れ/] = rep }.should raise_error(Encoding::CompatibilityError) end end @@ -361,11 +361,11 @@ describe "String#[]= with a Range index" do end it "raises a RangeError if negative Range begin is out of range" do - lambda { "abc"[-4..-2] = "x" }.should raise_error(RangeError) + -> { "abc"[-4..-2] = "x" }.should raise_error(RangeError) end it "raises a RangeError if positive Range begin is greater than String size" do - lambda { "abc"[4..2] = "x" }.should raise_error(RangeError) + -> { "abc"[4..2] = "x" }.should raise_error(RangeError) end it "uses the Range end as an index rather than a count" do @@ -432,7 +432,7 @@ describe "String#[]= with a Range index" do it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do str = "あれ" rep = "が".encode Encoding::EUC_JP - lambda { str[0..1] = rep }.should raise_error(Encoding::CompatibilityError) + -> { str[0..1] = rep }.should raise_error(Encoding::CompatibilityError) end end @@ -511,14 +511,14 @@ describe "String#[]= with Fixnum index, count" do index = mock("string element set index") index.should_receive(:to_int).and_return("1") - lambda { "abc"[index, 2] = "xyz" }.should raise_error(TypeError) + -> { "abc"[index, 2] = "xyz" }.should raise_error(TypeError) end it "raises a TypeError if #to_int for count does not return an Integer" do count = mock("string element set count") count.should_receive(:to_int).and_return("1") - lambda { "abc"[1, count] = "xyz" }.should raise_error(TypeError) + -> { "abc"[1, count] = "xyz" }.should raise_error(TypeError) end it "calls #to_str to convert the replacement object" do @@ -534,23 +534,23 @@ describe "String#[]= with Fixnum index, count" do r = mock("string element set replacement") r.should_receive(:to_str).and_return(nil) - lambda { "abc"[1, 1] = r }.should raise_error(TypeError) + -> { "abc"[1, 1] = r }.should raise_error(TypeError) end it "raises an IndexError if |idx| is greater than the length of the string" do - lambda { "hello"[6, 0] = "bob" }.should raise_error(IndexError) - lambda { "hello"[-6, 0] = "bob" }.should raise_error(IndexError) + -> { "hello"[6, 0] = "bob" }.should raise_error(IndexError) + -> { "hello"[-6, 0] = "bob" }.should raise_error(IndexError) end it "raises an IndexError if count < 0" do - lambda { "hello"[0, -1] = "bob" }.should raise_error(IndexError) - lambda { "hello"[1, -1] = "bob" }.should raise_error(IndexError) + -> { "hello"[0, -1] = "bob" }.should raise_error(IndexError) + -> { "hello"[1, -1] = "bob" }.should raise_error(IndexError) end it "raises a TypeError if other_str is a type other than String" do - lambda { "hello"[0, 2] = nil }.should raise_error(TypeError) - lambda { "hello"[0, 2] = [] }.should raise_error(TypeError) - lambda { "hello"[0, 2] = 33 }.should raise_error(TypeError) + -> { "hello"[0, 2] = nil }.should raise_error(TypeError) + -> { "hello"[0, 2] = [] }.should raise_error(TypeError) + -> { "hello"[0, 2] = 33 }.should raise_error(TypeError) end it "replaces characters with a multibyte character" do @@ -584,7 +584,7 @@ describe "String#[]= with Fixnum index, count" do end it "raises an IndexError if the character index is out of range of a multibyte String" do - lambda { "あれ"[3, 0] = "り" }.should raise_error(IndexError) + -> { "あれ"[3, 0] = "り" }.should raise_error(IndexError) end it "encodes the String in an encoding compatible with the replacement" do @@ -597,6 +597,6 @@ describe "String#[]= with Fixnum index, count" do it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do str = "あれ" rep = "が".encode Encoding::EUC_JP - lambda { str[0, 1] = rep }.should raise_error(Encoding::CompatibilityError) + -> { str[0, 1] = rep }.should raise_error(Encoding::CompatibilityError) end end diff --git a/spec/ruby/core/string/encode_spec.rb b/spec/ruby/core/string/encode_spec.rb index 67a25aff04..1c0c939358 100644 --- a/spec/ruby/core/string/encode_spec.rb +++ b/spec/ruby/core/string/encode_spec.rb @@ -113,12 +113,12 @@ describe "String#encode!" do it_behaves_like :string_encode, :encode! it "raises a #{frozen_error_class} when called on a frozen String" do - lambda { "foo".freeze.encode!("euc-jp") }.should raise_error(frozen_error_class) + -> { "foo".freeze.encode!("euc-jp") }.should raise_error(frozen_error_class) end # http://redmine.ruby-lang.org/issues/show/1836 it "raises a #{frozen_error_class} when called on a frozen String when it's a no-op" do - lambda { "foo".freeze.encode!("utf-8") }.should raise_error(frozen_error_class) + -> { "foo".freeze.encode!("utf-8") }.should raise_error(frozen_error_class) end describe "when passed no options" do diff --git a/spec/ruby/core/string/end_with_spec.rb b/spec/ruby/core/string/end_with_spec.rb index 429888803c..b7a04fdefe 100644 --- a/spec/ruby/core/string/end_with_spec.rb +++ b/spec/ruby/core/string/end_with_spec.rb @@ -32,9 +32,9 @@ describe "String#end_with?" do it "ignores arguments not convertible to string" do "hello".end_with?().should be_false - lambda { "hello".end_with?(1) }.should raise_error(TypeError) - lambda { "hello".end_with?(["o"]) }.should raise_error(TypeError) - lambda { "hello".end_with?(1, nil, "o") }.should raise_error(TypeError) + -> { "hello".end_with?(1) }.should raise_error(TypeError) + -> { "hello".end_with?(["o"]) }.should raise_error(TypeError) + -> { "hello".end_with?(1, nil, "o") }.should raise_error(TypeError) end it "uses only the needed arguments" do @@ -49,7 +49,7 @@ describe "String#end_with?" do it "raises an Encoding::CompatibilityError if the encodings are incompatible" do pat = "ア".encode Encoding::EUC_JP - lambda do + -> do "あれ".end_with?(pat) end.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/core/string/force_encoding_spec.rb b/spec/ruby/core/string/force_encoding_spec.rb index 7a5503de56..56d9b1e9bc 100644 --- a/spec/ruby/core/string/force_encoding_spec.rb +++ b/spec/ruby/core/string/force_encoding_spec.rb @@ -40,11 +40,11 @@ describe "String#force_encoding" do obj = mock("force_encoding") obj.should_receive(:to_str).and_return(1) - lambda { "abc".force_encoding(obj) }.should raise_error(TypeError) + -> { "abc".force_encoding(obj) }.should raise_error(TypeError) end it "raises a TypeError if passed nil" do - lambda { "abc".force_encoding(nil) }.should raise_error(TypeError) + -> { "abc".force_encoding(nil) }.should raise_error(TypeError) end it "returns self" do @@ -66,6 +66,6 @@ describe "String#force_encoding" do it "raises a #{frozen_error_class} if self is frozen" do str = "abcd".freeze - lambda { str.force_encoding(str.encoding) }.should raise_error(frozen_error_class) + -> { str.force_encoding(str.encoding) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/getbyte_spec.rb b/spec/ruby/core/string/getbyte_spec.rb index 84286ada92..27b7d826ea 100644 --- a/spec/ruby/core/string/getbyte_spec.rb +++ b/spec/ruby/core/string/getbyte_spec.rb @@ -59,11 +59,11 @@ describe "String#getbyte" do end it "raises an ArgumentError unless given one argument" do - lambda { "glark".getbyte }.should raise_error(ArgumentError) - lambda { "food".getbyte(0,0) }.should raise_error(ArgumentError) + -> { "glark".getbyte }.should raise_error(ArgumentError) + -> { "food".getbyte(0,0) }.should raise_error(ArgumentError) end it "raises a TypeError unless its argument can be coerced into an Integer" do - lambda { "a".getbyte('a') }.should raise_error(TypeError) + -> { "a".getbyte('a') }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb index 29b65c72a7..cd66a4f875 100644 --- a/spec/ruby/core/string/gsub_spec.rb +++ b/spec/ruby/core/string/gsub_spec.rb @@ -214,9 +214,9 @@ describe "String#gsub with pattern and replacement" do end it "raises a TypeError when pattern can't be converted to a string" do - lambda { "hello".gsub([], "x") }.should raise_error(TypeError) - lambda { "hello".gsub(Object.new, "x") }.should raise_error(TypeError) - lambda { "hello".gsub(nil, "x") }.should raise_error(TypeError) + -> { "hello".gsub([], "x") }.should raise_error(TypeError) + -> { "hello".gsub(Object.new, "x") }.should raise_error(TypeError) + -> { "hello".gsub(nil, "x") }.should raise_error(TypeError) end it "tries to convert replacement to a string using to_str" do @@ -227,9 +227,9 @@ describe "String#gsub with pattern and replacement" do end it "raises a TypeError when replacement can't be converted to a string" do - lambda { "hello".gsub(/[aeiou]/, []) }.should raise_error(TypeError) - lambda { "hello".gsub(/[aeiou]/, Object.new) }.should raise_error(TypeError) - lambda { "hello".gsub(/[aeiou]/, nil) }.should raise_error(TypeError) + -> { "hello".gsub(/[aeiou]/, []) }.should raise_error(TypeError) + -> { "hello".gsub(/[aeiou]/, Object.new) }.should raise_error(TypeError) + -> { "hello".gsub(/[aeiou]/, nil) }.should raise_error(TypeError) end it "returns subclass instances when called on a subclass" do @@ -298,7 +298,7 @@ describe "String#gsub with pattern and Hash" do it "uses the hash's value set from default_proc for missing keys" do hsh = {} - hsh.default_proc = lambda { |k,v| 'lamb' } + hsh.default_proc = -> k, v { 'lamb' } "food!".gsub(/./, hsh).should == "lamblamblamblamblamb" end @@ -387,7 +387,7 @@ describe "String#gsub! with pattern and Hash" do it "uses the hash's value set from default_proc for missing keys" do hsh = {} - hsh.default_proc = lambda { |k,v| 'lamb' } + hsh.default_proc = -> k, v { 'lamb' } "food!".gsub!(/./, hsh).should == "lamblamblamblamblamb" end @@ -536,8 +536,8 @@ describe "String#gsub with pattern and block" do s = "hllëllo" s2 = "hellö" - lambda { s.gsub(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError) - lambda { s2.gsub(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError) + -> { s.gsub(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError) + -> { s2.gsub(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError) end it "replaces the incompatible part properly even if the encodings are not compatible" do @@ -549,7 +549,7 @@ describe "String#gsub with pattern and block" do not_supported_on :opal do it "raises an ArgumentError if encoding is not valid" do x92 = [0x92].pack('C').force_encoding('utf-8') - lambda { "a#{x92}b".gsub(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError) + -> { "a#{x92}b".gsub(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError) end end end @@ -607,9 +607,9 @@ describe "String#gsub! with pattern and replacement" do s = "hello" s.freeze - lambda { s.gsub!(/ROAR/, "x") }.should raise_error(frozen_error_class) - lambda { s.gsub!(/e/, "e") }.should raise_error(frozen_error_class) - lambda { s.gsub!(/[aeiou]/, '*') }.should raise_error(frozen_error_class) + -> { s.gsub!(/ROAR/, "x") }.should raise_error(frozen_error_class) + -> { s.gsub!(/e/, "e") }.should raise_error(frozen_error_class) + -> { s.gsub!(/[aeiou]/, '*') }.should raise_error(frozen_error_class) end end @@ -644,9 +644,9 @@ describe "String#gsub! with pattern and block" do s = "hello" s.freeze - lambda { s.gsub!(/ROAR/) { "x" } }.should raise_error(frozen_error_class) - lambda { s.gsub!(/e/) { "e" } }.should raise_error(frozen_error_class) - lambda { s.gsub!(/[aeiou]/) { '*' } }.should raise_error(frozen_error_class) + -> { s.gsub!(/ROAR/) { "x" } }.should raise_error(frozen_error_class) + -> { s.gsub!(/e/) { "e" } }.should raise_error(frozen_error_class) + -> { s.gsub!(/[aeiou]/) { '*' } }.should raise_error(frozen_error_class) end it "uses the compatible encoding if they are compatible" do @@ -661,8 +661,8 @@ describe "String#gsub! with pattern and block" do s = "hllëllo" s2 = "hellö" - lambda { s.gsub!(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError) - lambda { s2.gsub!(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError) + -> { s.gsub!(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError) + -> { s2.gsub!(/l/) { |bar| "Русский".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError) end it "replaces the incompatible part properly even if the encodings are not compatible" do @@ -674,7 +674,7 @@ describe "String#gsub! with pattern and block" do not_supported_on :opal do it "raises an ArgumentError if encoding is not valid" do x92 = [0x92].pack('C').force_encoding('utf-8') - lambda { "a#{x92}b".gsub!(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError) + -> { "a#{x92}b".gsub!(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/string/include_spec.rb b/spec/ruby/core/string/include_spec.rb index 03ef3ba802..e32eb17c29 100644 --- a/spec/ruby/core/string/include_spec.rb +++ b/spec/ruby/core/string/include_spec.rb @@ -21,14 +21,14 @@ describe "String#include? with String" do end it "raises a TypeError if other can't be converted to string" do - lambda { "hello".include?([]) }.should raise_error(TypeError) - lambda { "hello".include?('h'.ord) }.should raise_error(TypeError) - lambda { "hello".include?(mock('x')) }.should raise_error(TypeError) + -> { "hello".include?([]) }.should raise_error(TypeError) + -> { "hello".include?('h'.ord) }.should raise_error(TypeError) + -> { "hello".include?(mock('x')) }.should raise_error(TypeError) end it "raises an Encoding::CompatibilityError if the encodings are incompatible" do pat = "ア".encode Encoding::EUC_JP - lambda do + -> do "あれ".include?(pat) end.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/core/string/index_spec.rb b/spec/ruby/core/string/index_spec.rb index fb5f4e75e7..ca62911db0 100644 --- a/spec/ruby/core/string/index_spec.rb +++ b/spec/ruby/core/string/index_spec.rb @@ -4,15 +4,15 @@ require_relative 'fixtures/classes' describe "String#index" do it "raises a TypeError if passed nil" do - lambda { "abc".index nil }.should raise_error(TypeError) + -> { "abc".index nil }.should raise_error(TypeError) end it "raises a TypeError if passed a boolean" do - lambda { "abc".index true }.should raise_error(TypeError) + -> { "abc".index true }.should raise_error(TypeError) end it "raises a TypeError if passed a Symbol" do - lambda { "abc".index :a }.should raise_error(TypeError) + -> { "abc".index :a }.should raise_error(TypeError) end it "calls #to_str to convert the first argument" do @@ -28,7 +28,7 @@ describe "String#index" do end it "raises a TypeError if passed a Fixnum" do - lambda { "abc".index 97 }.should raise_error(TypeError) + -> { "abc".index 97 }.should raise_error(TypeError) end end @@ -154,7 +154,7 @@ describe "String#index with String" do it "raises an Encoding::CompatibilityError if the encodings are incompatible" do char = "れ".encode Encoding::EUC_JP - lambda do + -> do "あれ".index char end.should raise_error(Encoding::CompatibilityError) end @@ -305,7 +305,7 @@ describe "String#index with Regexp" do it "raises an Encoding::CompatibilityError if the encodings are incompatible" do re = Regexp.new "れ".encode(Encoding::EUC_JP) - lambda do + -> do "あれ".index re end.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/core/string/insert_spec.rb b/spec/ruby/core/string/insert_spec.rb index d5b9026f3d..588b8ab272 100644 --- a/spec/ruby/core/string/insert_spec.rb +++ b/spec/ruby/core/string/insert_spec.rb @@ -23,8 +23,8 @@ describe "String#insert with index, other" do end it "raises an IndexError if the index is beyond string" do - lambda { "abcd".insert(5, 'X') }.should raise_error(IndexError) - lambda { "abcd".insert(-6, 'X') }.should raise_error(IndexError) + -> { "abcd".insert(5, 'X') }.should raise_error(IndexError) + -> { "abcd".insert(-6, 'X') }.should raise_error(IndexError) end it "converts index to an integer using to_int" do @@ -52,15 +52,15 @@ describe "String#insert with index, other" do end it "raises a TypeError if other can't be converted to string" do - lambda { "abcd".insert(-6, Object.new)}.should raise_error(TypeError) - lambda { "abcd".insert(-6, []) }.should raise_error(TypeError) - lambda { "abcd".insert(-6, mock('x')) }.should raise_error(TypeError) + -> { "abcd".insert(-6, Object.new)}.should raise_error(TypeError) + -> { "abcd".insert(-6, []) }.should raise_error(TypeError) + -> { "abcd".insert(-6, mock('x')) }.should raise_error(TypeError) end it "raises a #{frozen_error_class} if self is frozen" do str = "abcd".freeze - lambda { str.insert(4, '') }.should raise_error(frozen_error_class) - lambda { str.insert(4, 'X') }.should raise_error(frozen_error_class) + -> { str.insert(4, '') }.should raise_error(frozen_error_class) + -> { str.insert(4, 'X') }.should raise_error(frozen_error_class) end it "inserts a character into a multibyte encoded string" do @@ -75,7 +75,7 @@ describe "String#insert with index, other" do it "raises an Encoding::CompatibilityError if the encodings are incompatible" do pat = "ア".encode Encoding::EUC_JP - lambda do + -> do "あれ".insert 0, pat end.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/core/string/ljust_spec.rb b/spec/ruby/core/string/ljust_spec.rb index a8160c727b..ed4cb86859 100644 --- a/spec/ruby/core/string/ljust_spec.rb +++ b/spec/ruby/core/string/ljust_spec.rb @@ -49,10 +49,10 @@ describe "String#ljust with length, padding" do end it "raises a TypeError when length can't be converted to an integer" do - lambda { "hello".ljust("x") }.should raise_error(TypeError) - lambda { "hello".ljust("x", "y") }.should raise_error(TypeError) - lambda { "hello".ljust([]) }.should raise_error(TypeError) - lambda { "hello".ljust(mock('x')) }.should raise_error(TypeError) + -> { "hello".ljust("x") }.should raise_error(TypeError) + -> { "hello".ljust("x", "y") }.should raise_error(TypeError) + -> { "hello".ljust([]) }.should raise_error(TypeError) + -> { "hello".ljust(mock('x')) }.should raise_error(TypeError) end it "tries to convert padstr to a string using to_str" do @@ -63,13 +63,13 @@ describe "String#ljust with length, padding" do end it "raises a TypeError when padstr can't be converted" do - lambda { "hello".ljust(20, []) }.should raise_error(TypeError) - lambda { "hello".ljust(20, Object.new)}.should raise_error(TypeError) - lambda { "hello".ljust(20, mock('x')) }.should raise_error(TypeError) + -> { "hello".ljust(20, []) }.should raise_error(TypeError) + -> { "hello".ljust(20, Object.new)}.should raise_error(TypeError) + -> { "hello".ljust(20, mock('x')) }.should raise_error(TypeError) end it "raises an ArgumentError when padstr is empty" do - lambda { "hello".ljust(10, '') }.should raise_error(ArgumentError) + -> { "hello".ljust(10, '') }.should raise_error(ArgumentError) end it "returns subclass instances when called on subclasses" do @@ -106,7 +106,7 @@ describe "String#ljust with length, padding" do it "raises an Encoding::CompatibilityError if the encodings are incompatible" do pat = "ア".encode Encoding::EUC_JP - lambda do + -> do "あれ".ljust 5, pat end.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/core/string/lstrip_spec.rb b/spec/ruby/core/string/lstrip_spec.rb index ecfc89dd6b..7f9363d398 100644 --- a/spec/ruby/core/string/lstrip_spec.rb +++ b/spec/ruby/core/string/lstrip_spec.rb @@ -39,12 +39,12 @@ describe "String#lstrip!" do end it "raises a #{frozen_error_class} on a frozen instance that is modified" do - lambda { " hello ".freeze.lstrip! }.should raise_error(frozen_error_class) + -> { " hello ".freeze.lstrip! }.should raise_error(frozen_error_class) end # see [ruby-core:23657] it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do - lambda { "hello".freeze.lstrip! }.should raise_error(frozen_error_class) - lambda { "".freeze.lstrip! }.should raise_error(frozen_error_class) + -> { "hello".freeze.lstrip! }.should raise_error(frozen_error_class) + -> { "".freeze.lstrip! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/match_spec.rb b/spec/ruby/core/string/match_spec.rb index c5505fd382..78b94baa44 100644 --- a/spec/ruby/core/string/match_spec.rb +++ b/spec/ruby/core/string/match_spec.rb @@ -19,8 +19,8 @@ describe "String#=~" do end it "raises a TypeError if a obj is a string" do - lambda { "some string" =~ "another string" }.should raise_error(TypeError) - lambda { "a" =~ StringSpecs::MyString.new("b") }.should raise_error(TypeError) + -> { "some string" =~ "another string" }.should raise_error(TypeError) + -> { "a" =~ StringSpecs::MyString.new("b") }.should raise_error(TypeError) end it "invokes obj.=~ with self if obj is neither a string nor regexp" do @@ -107,9 +107,9 @@ describe "String#match" do end it "raises a TypeError if pattern is not a regexp or a string" do - lambda { 'hello'.match(10) }.should raise_error(TypeError) + -> { 'hello'.match(10) }.should raise_error(TypeError) not_supported_on :opal do - lambda { 'hello'.match(:ell) }.should raise_error(TypeError) + -> { 'hello'.match(:ell) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb index fc4972b9d7..0ac0963403 100644 --- a/spec/ruby/core/string/modulo_spec.rb +++ b/spec/ruby/core/string/modulo_spec.rb @@ -4,7 +4,7 @@ require_relative '../../shared/hash/key_error' describe "String#%" do context "when key is missing from passed-in hash" do - it_behaves_like :key_error, -> (obj, key) { "%{#{key}}" % obj }, { a: 5 } + it_behaves_like :key_error, -> obj, key { "%{#{key}}" % obj }, { a: 5 } end it "formats multiple expressions" do @@ -32,7 +32,7 @@ describe "String#%" do end it "raises if a compatible encoding can't be found" do - lambda { "hello %s".encode("utf-8") % "world".encode("UTF-16LE") }.should raise_error(Encoding::CompatibilityError) + -> { "hello %s".encode("utf-8") % "world".encode("UTF-16LE") }.should raise_error(Encoding::CompatibilityError) end end @@ -45,8 +45,8 @@ describe "String#%" do ruby_version_is "2.5" do it "raises an error if single % appears at the end" do - lambda { ("%" % []) }.should raise_error(ArgumentError) - lambda { ("foo%" % [])}.should raise_error(ArgumentError) + -> { ("%" % []) }.should raise_error(ArgumentError) + -> { ("foo%" % [])}.should raise_error(ArgumentError) end end @@ -63,18 +63,18 @@ describe "String#%" do end it "raises an error if single % appears anywhere else" do - lambda { (" % " % []) }.should raise_error(ArgumentError) - lambda { ("foo%quux" % []) }.should raise_error(ArgumentError) + -> { (" % " % []) }.should raise_error(ArgumentError) + -> { ("foo%quux" % []) }.should raise_error(ArgumentError) end it "raises an error if NULL or \\n appear anywhere else in the format string" do begin old_debug, $DEBUG = $DEBUG, false - lambda { "%.\n3f" % 1.2 }.should raise_error(ArgumentError) - lambda { "%.3\nf" % 1.2 }.should raise_error(ArgumentError) - lambda { "%.\03f" % 1.2 }.should raise_error(ArgumentError) - lambda { "%.3\0f" % 1.2 }.should raise_error(ArgumentError) + -> { "%.\n3f" % 1.2 }.should raise_error(ArgumentError) + -> { "%.3\nf" % 1.2 }.should raise_error(ArgumentError) + -> { "%.\03f" % 1.2 }.should raise_error(ArgumentError) + -> { "%.3\0f" % 1.2 }.should raise_error(ArgumentError) ensure $DEBUG = old_debug end @@ -99,8 +99,8 @@ describe "String#%" do s = $stderr $stderr = IOStub.new - lambda { "" % [1, 2, 3] }.should raise_error(ArgumentError) - lambda { "%s" % [1, 2, 3] }.should raise_error(ArgumentError) + -> { "" % [1, 2, 3] }.should raise_error(ArgumentError) + -> { "%s" % [1, 2, 3] }.should raise_error(ArgumentError) ensure $DEBUG = old_debug $stderr = s @@ -125,21 +125,21 @@ describe "String#%" do end it "raises an ArgumentError when given invalid argument specifiers" do - lambda { "%1" % [] }.should raise_error(ArgumentError) - lambda { "%+" % [] }.should raise_error(ArgumentError) - lambda { "%-" % [] }.should raise_error(ArgumentError) - lambda { "%#" % [] }.should raise_error(ArgumentError) - lambda { "%0" % [] }.should raise_error(ArgumentError) - lambda { "%*" % [] }.should raise_error(ArgumentError) - lambda { "%." % [] }.should raise_error(ArgumentError) - lambda { "%_" % [] }.should raise_error(ArgumentError) - lambda { "%0$s" % "x" }.should raise_error(ArgumentError) - lambda { "%*0$s" % [5, "x"] }.should raise_error(ArgumentError) - lambda { "%*1$.*0$1$s" % [1, 2, 3] }.should raise_error(ArgumentError) + -> { "%1" % [] }.should raise_error(ArgumentError) + -> { "%+" % [] }.should raise_error(ArgumentError) + -> { "%-" % [] }.should raise_error(ArgumentError) + -> { "%#" % [] }.should raise_error(ArgumentError) + -> { "%0" % [] }.should raise_error(ArgumentError) + -> { "%*" % [] }.should raise_error(ArgumentError) + -> { "%." % [] }.should raise_error(ArgumentError) + -> { "%_" % [] }.should raise_error(ArgumentError) + -> { "%0$s" % "x" }.should raise_error(ArgumentError) + -> { "%*0$s" % [5, "x"] }.should raise_error(ArgumentError) + -> { "%*1$.*0$1$s" % [1, 2, 3] }.should raise_error(ArgumentError) end it "raises an ArgumentError when multiple positional argument tokens are given for one format specifier" do - lambda { "%1$1$s" % "foo" }.should raise_error(ArgumentError) + -> { "%1$1$s" % "foo" }.should raise_error(ArgumentError) end it "respects positional arguments and precision tokens given for one format specifier" do @@ -155,36 +155,36 @@ describe "String#%" do end it "raises an ArgumentError when multiple width star tokens are given for one format specifier" do - lambda { "%**s" % [5, 5, 5] }.should raise_error(ArgumentError) + -> { "%**s" % [5, 5, 5] }.should raise_error(ArgumentError) end it "raises an ArgumentError when a width star token is seen after a width token" do - lambda { "%5*s" % [5, 5] }.should raise_error(ArgumentError) + -> { "%5*s" % [5, 5] }.should raise_error(ArgumentError) end it "raises an ArgumentError when multiple precision tokens are given" do - lambda { "%.5.5s" % 5 }.should raise_error(ArgumentError) - lambda { "%.5.*s" % [5, 5] }.should raise_error(ArgumentError) - lambda { "%.*.5s" % [5, 5] }.should raise_error(ArgumentError) + -> { "%.5.5s" % 5 }.should raise_error(ArgumentError) + -> { "%.5.*s" % [5, 5] }.should raise_error(ArgumentError) + -> { "%.*.5s" % [5, 5] }.should raise_error(ArgumentError) end it "raises an ArgumentError when there are less arguments than format specifiers" do ("foo" % []).should == "foo" - lambda { "%s" % [] }.should raise_error(ArgumentError) - lambda { "%s %s" % [1] }.should raise_error(ArgumentError) + -> { "%s" % [] }.should raise_error(ArgumentError) + -> { "%s %s" % [1] }.should raise_error(ArgumentError) end it "raises an ArgumentError when absolute and relative argument numbers are mixed" do - lambda { "%s %1$s" % "foo" }.should raise_error(ArgumentError) - lambda { "%1$s %s" % "foo" }.should raise_error(ArgumentError) + -> { "%s %1$s" % "foo" }.should raise_error(ArgumentError) + -> { "%1$s %s" % "foo" }.should raise_error(ArgumentError) - lambda { "%s %2$s" % ["foo", "bar"] }.should raise_error(ArgumentError) - lambda { "%2$s %s" % ["foo", "bar"] }.should raise_error(ArgumentError) + -> { "%s %2$s" % ["foo", "bar"] }.should raise_error(ArgumentError) + -> { "%2$s %s" % ["foo", "bar"] }.should raise_error(ArgumentError) - lambda { "%*2$s" % [5, 5, 5] }.should raise_error(ArgumentError) - lambda { "%*.*2$s" % [5, 5, 5] }.should raise_error(ArgumentError) - lambda { "%*2$.*2$s" % [5, 5, 5] }.should raise_error(ArgumentError) - lambda { "%*.*2$s" % [5, 5, 5] }.should raise_error(ArgumentError) + -> { "%*2$s" % [5, 5, 5] }.should raise_error(ArgumentError) + -> { "%*.*2$s" % [5, 5, 5] }.should raise_error(ArgumentError) + -> { "%*2$.*2$s" % [5, 5, 5] }.should raise_error(ArgumentError) + -> { "%*.*2$s" % [5, 5, 5] }.should raise_error(ArgumentError) end it "allows reuse of the one argument multiple via absolute argument numbers" do @@ -193,13 +193,13 @@ describe "String#%" do end it "always interprets an array argument as a list of argument parameters" do - lambda { "%p" % [] }.should raise_error(ArgumentError) + -> { "%p" % [] }.should raise_error(ArgumentError) ("%p" % [1]).should == "1" ("%p %p" % [1, 2]).should == "1 2" end it "always interprets an array subclass argument as a list of argument parameters" do - lambda { "%p" % StringSpecs::MyArray[] }.should raise_error(ArgumentError) + -> { "%p" % StringSpecs::MyArray[] }.should raise_error(ArgumentError) ("%p" % StringSpecs::MyArray[1]).should == "1" ("%p %p" % StringSpecs::MyArray[1, 2]).should == "1 2" end @@ -270,7 +270,7 @@ describe "String#%" do x = mock("string modulo to_ary") x.should_receive(:to_ary).and_return("x") - lambda { "%s" % x }.should raise_error(TypeError) + -> { "%s" % x }.should raise_error(TypeError) end it "tries to convert the argument to Array by calling #to_ary" do @@ -377,7 +377,7 @@ describe "String#%" do ("%*c" % [10, 3]).should == " \003" ("%c" % 42).should == "*" - lambda { "%c" % Object }.should raise_error(TypeError) + -> { "%c" % Object }.should raise_error(TypeError) end it "supports single character strings as argument for %c" do @@ -385,7 +385,7 @@ describe "String#%" do end it "raises an exception for multiple character strings as argument for %c" do - lambda { "%c" % 'AA' }.should raise_error(ArgumentError) + -> { "%c" % 'AA' }.should raise_error(ArgumentError) end it "calls to_str on argument for %c formats" do @@ -619,7 +619,7 @@ describe "String#%" do # MRI crashes on this one. # See http://groups.google.com/group/ruby-core-google/t/c285c18cd94c216d it "raises an ArgumentError for huge precisions for %s" do - block = lambda { "%.25555555555555555555555555555555555555s" % "hello world" } + block = -> { "%.25555555555555555555555555555555555555s" % "hello world" } block.should raise_error(ArgumentError) end @@ -712,19 +712,19 @@ describe "String#%" do (format % "0b1101").should == (format % Kernel.Integer("0b1101")) (format % "0b1101_0000").should == (format % Kernel.Integer("0b1101_0000")) (format % "0777").should == (format % Kernel.Integer("0777")) - lambda { + -> { # see [ruby-core:14139] for more details (format % "0777").should == (format % Kernel.Integer("0777")) }.should_not raise_error(ArgumentError) - lambda { format % "0__7_7_7" }.should raise_error(ArgumentError) + -> { format % "0__7_7_7" }.should raise_error(ArgumentError) - lambda { format % "" }.should raise_error(ArgumentError) - lambda { format % "x" }.should raise_error(ArgumentError) - lambda { format % "5x" }.should raise_error(ArgumentError) - lambda { format % "08" }.should raise_error(ArgumentError) - lambda { format % "0b2" }.should raise_error(ArgumentError) - lambda { format % "123__456" }.should raise_error(ArgumentError) + -> { format % "" }.should raise_error(ArgumentError) + -> { format % "x" }.should raise_error(ArgumentError) + -> { format % "5x" }.should raise_error(ArgumentError) + -> { format % "08" }.should raise_error(ArgumentError) + -> { format % "0b2" }.should raise_error(ArgumentError) + -> { format % "123__456" }.should raise_error(ArgumentError) obj = mock('5') obj.should_receive(:to_i).and_return(5) @@ -757,15 +757,15 @@ describe "String#%" do (format % "0777").should == (format % 777) - lambda { format % "" }.should raise_error(ArgumentError) - lambda { format % "x" }.should raise_error(ArgumentError) - lambda { format % "." }.should raise_error(ArgumentError) - lambda { format % "10." }.should raise_error(ArgumentError) - lambda { format % "5x" }.should raise_error(ArgumentError) - lambda { format % "0b1" }.should raise_error(ArgumentError) - lambda { format % "10e10.5" }.should raise_error(ArgumentError) - lambda { format % "10__10" }.should raise_error(ArgumentError) - lambda { format % "10.10__10" }.should raise_error(ArgumentError) + -> { format % "" }.should raise_error(ArgumentError) + -> { format % "x" }.should raise_error(ArgumentError) + -> { format % "." }.should raise_error(ArgumentError) + -> { format % "10." }.should raise_error(ArgumentError) + -> { format % "5x" }.should raise_error(ArgumentError) + -> { format % "0b1" }.should raise_error(ArgumentError) + -> { format % "10e10.5" }.should raise_error(ArgumentError) + -> { format % "10__10" }.should raise_error(ArgumentError) + -> { format % "10.10__10" }.should raise_error(ArgumentError) obj = mock('5.0') obj.should_receive(:to_f).and_return(5.0) @@ -787,7 +787,7 @@ describe "String#%" do end it "should raise ArgumentError if no hash given" do - lambda {"%{foo}" % []}.should raise_error(ArgumentError) + -> {"%{foo}" % []}.should raise_error(ArgumentError) end end @@ -797,11 +797,11 @@ describe "String#%" do end it "raises KeyError if key is missing from passed-in hash" do - lambda {"%<foo>d" % {}}.should raise_error(KeyError) + -> {"%<foo>d" % {}}.should raise_error(KeyError) end it "should raise ArgumentError if no hash given" do - lambda {"%<foo>" % []}.should raise_error(ArgumentError) + -> {"%<foo>" % []}.should raise_error(ArgumentError) end end end diff --git a/spec/ruby/core/string/multiply_spec.rb b/spec/ruby/core/string/multiply_spec.rb index 7d887fd93a..c15f670c46 100644 --- a/spec/ruby/core/string/multiply_spec.rb +++ b/spec/ruby/core/string/multiply_spec.rb @@ -3,5 +3,5 @@ require_relative 'fixtures/classes' require_relative '../../shared/string/times' describe "String#*" do - it_behaves_like :string_times, :*, ->(str, times) { str * times } + it_behaves_like :string_times, :*, -> str, times { str * times } end diff --git a/spec/ruby/core/string/new_spec.rb b/spec/ruby/core/string/new_spec.rb index f65daf2dd2..ca678f5323 100644 --- a/spec/ruby/core/string/new_spec.rb +++ b/spec/ruby/core/string/new_spec.rb @@ -51,8 +51,8 @@ describe "String.new" do end it "raises TypeError on inconvertible object" do - lambda { String.new 5 }.should raise_error(TypeError) - lambda { String.new nil }.should raise_error(TypeError) + -> { String.new 5 }.should raise_error(TypeError) + -> { String.new nil }.should raise_error(TypeError) end it "returns a binary String" do diff --git a/spec/ruby/core/string/ord_spec.rb b/spec/ruby/core/string/ord_spec.rb index 63f9815ea9..0f5a3f6a37 100644 --- a/spec/ruby/core/string/ord_spec.rb +++ b/spec/ruby/core/string/ord_spec.rb @@ -23,6 +23,6 @@ describe "String#ord" do end it "raises an ArgumentError if called on an empty String" do - lambda { ''.ord }.should raise_error(ArgumentError) + -> { ''.ord }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/partition_spec.rb b/spec/ruby/core/string/partition_spec.rb index f7ab5f85aa..996368d6a4 100644 --- a/spec/ruby/core/string/partition_spec.rb +++ b/spec/ruby/core/string/partition_spec.rb @@ -28,8 +28,8 @@ describe "String#partition with String" do end it "raises an error if not convertible to string" do - lambda{ "hello".partition(5) }.should raise_error(TypeError) - lambda{ "hello".partition(nil) }.should raise_error(TypeError) + ->{ "hello".partition(5) }.should raise_error(TypeError) + ->{ "hello".partition(nil) }.should raise_error(TypeError) end it "takes precedence over a given block" do diff --git a/spec/ruby/core/string/percent_spec.rb b/spec/ruby/core/string/percent_spec.rb index e701def344..e3460522b1 100644 --- a/spec/ruby/core/string/percent_spec.rb +++ b/spec/ruby/core/string/percent_spec.rb @@ -3,11 +3,11 @@ require_relative '../kernel/shared/sprintf' require_relative '../kernel/shared/sprintf_encoding' describe "String#%" do - it_behaves_like :kernel_sprintf, -> (format, *args) { + it_behaves_like :kernel_sprintf, -> format, *args { format % args } - it_behaves_like :kernel_sprintf_encoding, -> (format, *args) { + it_behaves_like :kernel_sprintf_encoding, -> format, *args { format % args } end diff --git a/spec/ruby/core/string/plus_spec.rb b/spec/ruby/core/string/plus_spec.rb index a9f287a82b..b8e3bf0a4b 100644 --- a/spec/ruby/core/string/plus_spec.rb +++ b/spec/ruby/core/string/plus_spec.rb @@ -18,8 +18,8 @@ describe "String#+" do end it "raises a TypeError when given any object that fails #to_str" do - lambda { "" + Object.new }.should raise_error(TypeError) - lambda { "" + 65 }.should raise_error(TypeError) + -> { "" + Object.new }.should raise_error(TypeError) + -> { "" + 65 }.should raise_error(TypeError) end it "doesn't return subclass instances" do diff --git a/spec/ruby/core/string/prepend_spec.rb b/spec/ruby/core/string/prepend_spec.rb index e2c29de836..485c578e2d 100644 --- a/spec/ruby/core/string/prepend_spec.rb +++ b/spec/ruby/core/string/prepend_spec.rb @@ -16,16 +16,16 @@ describe "String#prepend" do end it "raises a TypeError if the given argument can't be converted to a String" do - lambda { "hello ".prepend [] }.should raise_error(TypeError) - lambda { 'hello '.prepend mock('x') }.should raise_error(TypeError) + -> { "hello ".prepend [] }.should raise_error(TypeError) + -> { 'hello '.prepend mock('x') }.should raise_error(TypeError) end it "raises a #{frozen_error_class} when self is frozen" do a = "hello" a.freeze - lambda { a.prepend "" }.should raise_error(frozen_error_class) - lambda { a.prepend "test" }.should raise_error(frozen_error_class) + -> { a.prepend "" }.should raise_error(frozen_error_class) + -> { a.prepend "test" }.should raise_error(frozen_error_class) end it "works when given a subclass instance" do diff --git a/spec/ruby/core/string/reverse_spec.rb b/spec/ruby/core/string/reverse_spec.rb index f2a8b64d47..3941ea0521 100644 --- a/spec/ruby/core/string/reverse_spec.rb +++ b/spec/ruby/core/string/reverse_spec.rb @@ -31,13 +31,13 @@ describe "String#reverse!" do end it "raises a #{frozen_error_class} on a frozen instance that is modified" do - lambda { "anna".freeze.reverse! }.should raise_error(frozen_error_class) - lambda { "hello".freeze.reverse! }.should raise_error(frozen_error_class) + -> { "anna".freeze.reverse! }.should raise_error(frozen_error_class) + -> { "hello".freeze.reverse! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do - lambda { "".freeze.reverse! }.should raise_error(frozen_error_class) + -> { "".freeze.reverse! }.should raise_error(frozen_error_class) end it "reverses a string with multi byte characters" do diff --git a/spec/ruby/core/string/rindex_spec.rb b/spec/ruby/core/string/rindex_spec.rb index f74c0115cc..e021486bc2 100644 --- a/spec/ruby/core/string/rindex_spec.rb +++ b/spec/ruby/core/string/rindex_spec.rb @@ -6,15 +6,15 @@ require_relative 'fixtures/utf-8-encoding' describe "String#rindex with object" do it "raises a TypeError if obj isn't a String, Fixnum or Regexp" do not_supported_on :opal do - lambda { "hello".rindex(:sym) }.should raise_error(TypeError) + -> { "hello".rindex(:sym) }.should raise_error(TypeError) end - lambda { "hello".rindex(mock('x')) }.should raise_error(TypeError) + -> { "hello".rindex(mock('x')) }.should raise_error(TypeError) end it "doesn't try to convert obj to an integer via to_int" do obj = mock('x') obj.should_not_receive(:to_int) - lambda { "hello".rindex(obj) }.should raise_error(TypeError) + -> { "hello".rindex(obj) }.should raise_error(TypeError) end it "tries to convert obj to a string via to_str" do @@ -190,7 +190,7 @@ describe "String#rindex with String" do end it "raises a TypeError when given offset is nil" do - lambda { "str".rindex("st", nil) }.should raise_error(TypeError) + -> { "str".rindex("st", nil) }.should raise_error(TypeError) end end @@ -344,7 +344,7 @@ describe "String#rindex with Regexp" do end it "raises a TypeError when given offset is nil" do - lambda { "str".rindex(/../, nil) }.should raise_error(TypeError) + -> { "str".rindex(/../, nil) }.should raise_error(TypeError) end it "returns the reverse character index of a multibyte character" do @@ -359,7 +359,7 @@ describe "String#rindex with Regexp" do it "raises an Encoding::CompatibilityError if the encodings are incompatible" do re = Regexp.new "れ".encode(Encoding::EUC_JP) - lambda do + -> do "あれ".rindex re end.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/core/string/rjust_spec.rb b/spec/ruby/core/string/rjust_spec.rb index 2821b018e8..1ba298e8f3 100644 --- a/spec/ruby/core/string/rjust_spec.rb +++ b/spec/ruby/core/string/rjust_spec.rb @@ -49,10 +49,10 @@ describe "String#rjust with length, padding" do end it "raises a TypeError when length can't be converted to an integer" do - lambda { "hello".rjust("x") }.should raise_error(TypeError) - lambda { "hello".rjust("x", "y") }.should raise_error(TypeError) - lambda { "hello".rjust([]) }.should raise_error(TypeError) - lambda { "hello".rjust(mock('x')) }.should raise_error(TypeError) + -> { "hello".rjust("x") }.should raise_error(TypeError) + -> { "hello".rjust("x", "y") }.should raise_error(TypeError) + -> { "hello".rjust([]) }.should raise_error(TypeError) + -> { "hello".rjust(mock('x')) }.should raise_error(TypeError) end it "tries to convert padstr to a string using to_str" do @@ -63,13 +63,13 @@ describe "String#rjust with length, padding" do end it "raises a TypeError when padstr can't be converted" do - lambda { "hello".rjust(20, []) }.should raise_error(TypeError) - lambda { "hello".rjust(20, Object.new)}.should raise_error(TypeError) - lambda { "hello".rjust(20, mock('x')) }.should raise_error(TypeError) + -> { "hello".rjust(20, []) }.should raise_error(TypeError) + -> { "hello".rjust(20, Object.new)}.should raise_error(TypeError) + -> { "hello".rjust(20, mock('x')) }.should raise_error(TypeError) end it "raises an ArgumentError when padstr is empty" do - lambda { "hello".rjust(10, '') }.should raise_error(ArgumentError) + -> { "hello".rjust(10, '') }.should raise_error(ArgumentError) end it "returns subclass instances when called on subclasses" do @@ -106,7 +106,7 @@ describe "String#rjust with length, padding" do it "raises an Encoding::CompatibilityError if the encodings are incompatible" do pat = "ア".encode Encoding::EUC_JP - lambda do + -> do "あれ".rjust 5, pat end.should raise_error(Encoding::CompatibilityError) end diff --git a/spec/ruby/core/string/rpartition_spec.rb b/spec/ruby/core/string/rpartition_spec.rb index a5222e0a2a..c6428636f6 100644 --- a/spec/ruby/core/string/rpartition_spec.rb +++ b/spec/ruby/core/string/rpartition_spec.rb @@ -27,7 +27,7 @@ describe "String#rpartition with String" do end it "raises an error if not convertible to string" do - lambda{ "hello".rpartition(5) }.should raise_error(TypeError) - lambda{ "hello".rpartition(nil) }.should raise_error(TypeError) + ->{ "hello".rpartition(5) }.should raise_error(TypeError) + ->{ "hello".rpartition(nil) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/string/rstrip_spec.rb b/spec/ruby/core/string/rstrip_spec.rb index 6376e5df33..2f32836e54 100644 --- a/spec/ruby/core/string/rstrip_spec.rb +++ b/spec/ruby/core/string/rstrip_spec.rb @@ -41,12 +41,12 @@ describe "String#rstrip!" do end it "raises a #{frozen_error_class} on a frozen instance that is modified" do - lambda { " hello ".freeze.rstrip! }.should raise_error(frozen_error_class) + -> { " hello ".freeze.rstrip! }.should raise_error(frozen_error_class) end # see [ruby-core:23666] it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do - lambda { "hello".freeze.rstrip! }.should raise_error(frozen_error_class) - lambda { "".freeze.rstrip! }.should raise_error(frozen_error_class) + -> { "hello".freeze.rstrip! }.should raise_error(frozen_error_class) + -> { "".freeze.rstrip! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/scan_spec.rb b/spec/ruby/core/string/scan_spec.rb index ac82f5e236..06400fc745 100644 --- a/spec/ruby/core/string/scan_spec.rb +++ b/spec/ruby/core/string/scan_spec.rb @@ -58,11 +58,11 @@ describe "String#scan" do end it "raises a TypeError if pattern isn't a Regexp and can't be converted to a String" do - lambda { "cruel world".scan(5) }.should raise_error(TypeError) + -> { "cruel world".scan(5) }.should raise_error(TypeError) not_supported_on :opal do - lambda { "cruel world".scan(:test) }.should raise_error(TypeError) + -> { "cruel world".scan(:test) }.should raise_error(TypeError) end - lambda { "cruel world".scan(mock('x')) }.should raise_error(TypeError) + -> { "cruel world".scan(mock('x')) }.should raise_error(TypeError) end it "taints the results if the String argument is tainted" do diff --git a/spec/ruby/core/string/scrub_spec.rb b/spec/ruby/core/string/scrub_spec.rb index 92e7641f0b..390035ef30 100644 --- a/spec/ruby/core/string/scrub_spec.rb +++ b/spec/ruby/core/string/scrub_spec.rb @@ -47,14 +47,14 @@ describe "String#scrub with a custom replacement" do it "raises ArgumentError for replacements with an invalid encoding" do x81 = [0x81].pack('C').force_encoding('utf-8') xE4 = [0xE4].pack('C').force_encoding('utf-8') - block = lambda { "foo#{x81}".scrub(xE4) } + block = -> { "foo#{x81}".scrub(xE4) } block.should raise_error(ArgumentError) end it "raises TypeError when a non String replacement is given" do x81 = [0x81].pack('C').force_encoding('utf-8') - block = lambda { "foo#{x81}".scrub(1) } + block = -> { "foo#{x81}".scrub(1) } block.should raise_error(TypeError) end diff --git a/spec/ruby/core/string/setbyte_spec.rb b/spec/ruby/core/string/setbyte_spec.rb index 3f2e03f8a8..6912b1b66f 100644 --- a/spec/ruby/core/string/setbyte_spec.rb +++ b/spec/ruby/core/string/setbyte_spec.rb @@ -51,11 +51,11 @@ describe "String#setbyte" do end it "raises an IndexError if the index is greater than the String bytesize" do - lambda { "?".setbyte(1, 97) }.should raise_error(IndexError) + -> { "?".setbyte(1, 97) }.should raise_error(IndexError) end it "raises an IndexError if the negative index is greater magnitude than the String bytesize" do - lambda { "???".setbyte(-5, 97) }.should raise_error(IndexError) + -> { "???".setbyte(-5, 97) }.should raise_error(IndexError) end it "sets a byte at an index greater than String size" do @@ -78,11 +78,11 @@ describe "String#setbyte" do it "raises a #{frozen_error_class} if self is frozen" do str = "cold".freeze str.frozen?.should be_true - lambda { str.setbyte(3,96) }.should raise_error(frozen_error_class) + -> { str.setbyte(3,96) }.should raise_error(frozen_error_class) end it "raises a TypeError unless the second argument is an Integer" do - lambda { "a".setbyte(0,'a') }.should raise_error(TypeError) + -> { "a".setbyte(0,'a') }.should raise_error(TypeError) end it "calls #to_int to convert the index" do diff --git a/spec/ruby/core/string/shared/codepoints.rb b/spec/ruby/core/string/shared/codepoints.rb index 84a0e3ae39..e94a57f48e 100644 --- a/spec/ruby/core/string/shared/codepoints.rb +++ b/spec/ruby/core/string/shared/codepoints.rb @@ -9,7 +9,7 @@ describe :string_codepoints, shared: true do it "raises an ArgumentError when self has an invalid encoding and a method is called on the returned Enumerator" do s = "\xDF".force_encoding(Encoding::UTF_8) s.valid_encoding?.should be_false - lambda { s.send(@method).to_a }.should raise_error(ArgumentError) + -> { s.send(@method).to_a }.should raise_error(ArgumentError) end it "yields each codepoint to the block if one is given" do @@ -23,7 +23,7 @@ describe :string_codepoints, shared: true do it "raises an ArgumentError if self's encoding is invalid and a block is given" do s = "\xDF".force_encoding(Encoding::UTF_8) s.valid_encoding?.should be_false - lambda { s.send(@method) { } }.should raise_error(ArgumentError) + -> { s.send(@method) { } }.should raise_error(ArgumentError) end it "yields codepoints as Fixnums" do diff --git a/spec/ruby/core/string/shared/concat.rb b/spec/ruby/core/string/shared/concat.rb index 0a87410f2f..53a8bc23fb 100644 --- a/spec/ruby/core/string/shared/concat.rb +++ b/spec/ruby/core/string/shared/concat.rb @@ -13,16 +13,16 @@ describe :string_concat, shared: true do end it "raises a TypeError if the given argument can't be converted to a String" do - lambda { 'hello '.send(@method, []) }.should raise_error(TypeError) - lambda { 'hello '.send(@method, mock('x')) }.should raise_error(TypeError) + -> { 'hello '.send(@method, []) }.should raise_error(TypeError) + -> { 'hello '.send(@method, mock('x')) }.should raise_error(TypeError) end it "raises a #{frozen_error_class} when self is frozen" do a = "hello" a.freeze - lambda { a.send(@method, "") }.should raise_error(frozen_error_class) - lambda { a.send(@method, "test") }.should raise_error(frozen_error_class) + -> { a.send(@method, "") }.should raise_error(frozen_error_class) + -> { a.send(@method, "test") }.should raise_error(frozen_error_class) end it "returns a String when given a subclass instance" do @@ -71,28 +71,28 @@ describe :string_concat, shared: true do end it "raises RangeError if the argument is an invalid codepoint for self's encoding" do - lambda { "".encode(Encoding::US_ASCII).send(@method, 256) }.should raise_error(RangeError) - lambda { "".encode(Encoding::EUC_JP).send(@method, 0x81) }.should raise_error(RangeError) + -> { "".encode(Encoding::US_ASCII).send(@method, 256) }.should raise_error(RangeError) + -> { "".encode(Encoding::EUC_JP).send(@method, 0x81) }.should raise_error(RangeError) end it "raises RangeError if the argument is negative" do - lambda { "".send(@method, -200) }.should raise_error(RangeError) - lambda { "".send(@method, -bignum_value) }.should raise_error(RangeError) + -> { "".send(@method, -200) }.should raise_error(RangeError) + -> { "".send(@method, -bignum_value) }.should raise_error(RangeError) end it "doesn't call to_int on its argument" do x = mock('x') x.should_not_receive(:to_int) - lambda { "".send(@method, x) }.should raise_error(TypeError) + -> { "".send(@method, x) }.should raise_error(TypeError) end it "raises a #{frozen_error_class} when self is frozen" do a = "hello" a.freeze - lambda { a.send(@method, 0) }.should raise_error(frozen_error_class) - lambda { a.send(@method, 33) }.should raise_error(frozen_error_class) + -> { a.send(@method, 0) }.should raise_error(frozen_error_class) + -> { a.send(@method, 33) }.should raise_error(frozen_error_class) end end end @@ -112,7 +112,7 @@ describe :string_concat_encoding, shared: true do end it "raises Encoding::CompatibilityError if neither are empty" do - lambda { "x".encode("UTF-16LE").send(@method, "y".encode("UTF-8")) }.should raise_error(Encoding::CompatibilityError) + -> { "x".encode("UTF-16LE").send(@method, "y".encode("UTF-8")) }.should raise_error(Encoding::CompatibilityError) end end @@ -130,7 +130,7 @@ describe :string_concat_encoding, shared: true do end it "raises Encoding::CompatibilityError if neither are empty" do - lambda { "x".encode("UTF-8").send(@method, "y".encode("UTF-16LE")) }.should raise_error(Encoding::CompatibilityError) + -> { "x".encode("UTF-8").send(@method, "y".encode("UTF-16LE")) }.should raise_error(Encoding::CompatibilityError) end end @@ -148,7 +148,7 @@ describe :string_concat_encoding, shared: true do end it "raises Encoding::CompatibilityError if neither are ASCII-only" do - lambda { "\u00E9".encode("UTF-8").send(@method, "\u00E9".encode("ISO-8859-1")) }.should raise_error(Encoding::CompatibilityError) + -> { "\u00E9".encode("UTF-8").send(@method, "\u00E9".encode("ISO-8859-1")) }.should raise_error(Encoding::CompatibilityError) end end diff --git a/spec/ruby/core/string/shared/each_line.rb b/spec/ruby/core/string/shared/each_line.rb index 86c966e50b..241a90eee3 100644 --- a/spec/ruby/core/string/shared/each_line.rb +++ b/spec/ruby/core/string/shared/each_line.rb @@ -133,8 +133,8 @@ describe :string_each_line, shared: true do end it "raises a TypeError when the separator can't be converted to a string" do - lambda { "hello world".send(@method, false) {} }.should raise_error(TypeError) - lambda { "hello world".send(@method, mock('x')) {} }.should raise_error(TypeError) + -> { "hello world".send(@method, false) {} }.should raise_error(TypeError) + -> { "hello world".send(@method, mock('x')) {} }.should raise_error(TypeError) end it "accepts a string separator" do @@ -142,7 +142,7 @@ describe :string_each_line, shared: true do end it "raises a TypeError when the separator is a symbol" do - lambda { "hello world".send(@method, :o).to_a }.should raise_error(TypeError) + -> { "hello world".send(@method, :o).to_a }.should raise_error(TypeError) end context "when `chomp` keyword argument is passed" do diff --git a/spec/ruby/core/string/shared/encode.rb b/spec/ruby/core/string/shared/encode.rb index d13db1945e..b5a8bf9b72 100644 --- a/spec/ruby/core/string/shared/encode.rb +++ b/spec/ruby/core/string/shared/encode.rb @@ -8,7 +8,7 @@ describe :string_encode, shared: true do end it "transcodes a 7-bit String despite no generic converting being available" do - lambda do + -> do Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY end.should raise_error(Encoding::ConverterNotFoundError) @@ -21,7 +21,7 @@ describe :string_encode, shared: true do it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do Encoding.default_internal = Encoding::Emacs_Mule str = [0x80].pack('C').force_encoding Encoding::BINARY - lambda { str.send(@method) }.should raise_error(Encoding::ConverterNotFoundError) + -> { str.send(@method) }.should raise_error(Encoding::ConverterNotFoundError) end end @@ -51,7 +51,7 @@ describe :string_encode, shared: true do end it "transcodes a 7-bit String despite no generic converting being available" do - lambda do + -> do Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY end.should raise_error(Encoding::ConverterNotFoundError) @@ -61,13 +61,13 @@ describe :string_encode, shared: true do it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do str = [0x80].pack('C').force_encoding Encoding::BINARY - lambda do + -> do str.send(@method, Encoding::Emacs_Mule) end.should raise_error(Encoding::ConverterNotFoundError) end it "raises an Encoding::ConverterNotFoundError for an invalid encoding" do - lambda do + -> do "abc".send(@method, "xyz") end.should raise_error(Encoding::ConverterNotFoundError) end @@ -96,7 +96,7 @@ describe :string_encode, shared: true do it "raises an Encoding::ConverterNotFoundError when no conversion is possible despite 'invalid: :replace, undef: :replace'" do Encoding.default_internal = Encoding::Emacs_Mule str = [0x80].pack('C').force_encoding Encoding::BINARY - lambda do + -> do str.send(@method, invalid: :replace, undef: :replace) end.should raise_error(Encoding::ConverterNotFoundError) end @@ -242,6 +242,6 @@ describe :string_encode, shared: true do end it "raises ArgumentError if the value of the :xml option is not :text or :attr" do - lambda { ''.send(@method, "UTF-8", xml: :other) }.should raise_error(ArgumentError) + -> { ''.send(@method, "UTF-8", xml: :other) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/shared/replace.rb b/spec/ruby/core/string/shared/replace.rb index a583b88b5a..f13afb3f95 100644 --- a/spec/ruby/core/string/shared/replace.rb +++ b/spec/ruby/core/string/shared/replace.rb @@ -57,19 +57,19 @@ describe :string_replace, shared: true do end it "raises a TypeError if other can't be converted to string" do - lambda { "hello".send(@method, 123) }.should raise_error(TypeError) - lambda { "hello".send(@method, []) }.should raise_error(TypeError) - lambda { "hello".send(@method, mock('x')) }.should raise_error(TypeError) + -> { "hello".send(@method, 123) }.should raise_error(TypeError) + -> { "hello".send(@method, []) }.should raise_error(TypeError) + -> { "hello".send(@method, mock('x')) }.should raise_error(TypeError) end it "raises a #{frozen_error_class} on a frozen instance that is modified" do a = "hello".freeze - lambda { a.send(@method, "world") }.should raise_error(frozen_error_class) + -> { a.send(@method, "world") }.should raise_error(frozen_error_class) end # see [ruby-core:23666] it "raises a #{frozen_error_class} on a frozen instance when self-replacing" do a = "hello".freeze - lambda { a.send(@method, a) }.should raise_error(frozen_error_class) + -> { a.send(@method, a) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb index 697fa2e530..ef7a8787ce 100644 --- a/spec/ruby/core/string/shared/slice.rb +++ b/spec/ruby/core/string/shared/slice.rb @@ -21,17 +21,17 @@ describe :string_slice, shared: true do end it "raises a TypeError if the given index is nil" do - lambda { "hello".send(@method, nil) }.should raise_error(TypeError) + -> { "hello".send(@method, nil) }.should raise_error(TypeError) end it "raises a TypeError if the given index can't be converted to an Integer" do - lambda { "hello".send(@method, mock('x')) }.should raise_error(TypeError) - lambda { "hello".send(@method, {}) }.should raise_error(TypeError) - lambda { "hello".send(@method, []) }.should raise_error(TypeError) + -> { "hello".send(@method, mock('x')) }.should raise_error(TypeError) + -> { "hello".send(@method, {}) }.should raise_error(TypeError) + -> { "hello".send(@method, []) }.should raise_error(TypeError) end it "raises a RangeError if the index is too big" do - lambda { "hello".send(@method, bignum_value) }.should raise_error(RangeError) + -> { "hello".send(@method, bignum_value) }.should raise_error(RangeError) end end @@ -140,23 +140,23 @@ describe :string_slice_index_length, shared: true do end it "raises a TypeError when idx or length can't be converted to an integer" do - lambda { "hello".send(@method, mock('x'), 0) }.should raise_error(TypeError) - lambda { "hello".send(@method, 0, mock('x')) }.should raise_error(TypeError) + -> { "hello".send(@method, mock('x'), 0) }.should raise_error(TypeError) + -> { "hello".send(@method, 0, mock('x')) }.should raise_error(TypeError) # I'm deliberately including this here. # It means that str.send(@method, other, idx) isn't supported. - lambda { "hello".send(@method, "", 0) }.should raise_error(TypeError) + -> { "hello".send(@method, "", 0) }.should raise_error(TypeError) end it "raises a TypeError when the given index or the given length is nil" do - lambda { "hello".send(@method, 1, nil) }.should raise_error(TypeError) - lambda { "hello".send(@method, nil, 1) }.should raise_error(TypeError) - lambda { "hello".send(@method, nil, nil) }.should raise_error(TypeError) + -> { "hello".send(@method, 1, nil) }.should raise_error(TypeError) + -> { "hello".send(@method, nil, 1) }.should raise_error(TypeError) + -> { "hello".send(@method, nil, nil) }.should raise_error(TypeError) end it "raises a RangeError if the index or length is too big" do - lambda { "hello".send(@method, bignum_value, 1) }.should raise_error(RangeError) - lambda { "hello".send(@method, 0, bignum_value) }.should raise_error(RangeError) + -> { "hello".send(@method, bignum_value, 1) }.should raise_error(RangeError) + -> { "hello".send(@method, 0, bignum_value) }.should raise_error(RangeError) end it "returns subclass instances" do @@ -399,13 +399,13 @@ describe :string_slice_regexp_index, shared: true do end it "raises a TypeError when the given index can't be converted to Integer" do - lambda { "hello".send(@method, /(.)(.)(.)/, mock('x')) }.should raise_error(TypeError) - lambda { "hello".send(@method, /(.)(.)(.)/, {}) }.should raise_error(TypeError) - lambda { "hello".send(@method, /(.)(.)(.)/, []) }.should raise_error(TypeError) + -> { "hello".send(@method, /(.)(.)(.)/, mock('x')) }.should raise_error(TypeError) + -> { "hello".send(@method, /(.)(.)(.)/, {}) }.should raise_error(TypeError) + -> { "hello".send(@method, /(.)(.)(.)/, []) }.should raise_error(TypeError) end it "raises a TypeError when the given index is nil" do - lambda { "hello".send(@method, /(.)(.)(.)/, nil) }.should raise_error(TypeError) + -> { "hello".send(@method, /(.)(.)(.)/, nil) }.should raise_error(TypeError) end it "returns subclass instances" do @@ -460,7 +460,7 @@ describe :string_slice_string, shared: true do o = mock('x') o.should_not_receive(:to_str) - lambda { "hello".send(@method, o) }.should raise_error(TypeError) + -> { "hello".send(@method, o) }.should raise_error(TypeError) end it "returns a subclass instance when given a subclass instance" do @@ -520,19 +520,19 @@ describe :string_slice_regexp_group, shared: true do end it "raises an IndexError if there is no capture for the given name" do - lambda do + -> do "hello there".send(@method, /[aeiou](.)\1/, 'non') end.should raise_error(IndexError) end it "raises a TypeError when the given name is not a String" do - lambda { "hello".send(@method, /(?<q>.)/, mock('x')) }.should raise_error(TypeError) - lambda { "hello".send(@method, /(?<q>.)/, {}) }.should raise_error(TypeError) - lambda { "hello".send(@method, /(?<q>.)/, []) }.should raise_error(TypeError) + -> { "hello".send(@method, /(?<q>.)/, mock('x')) }.should raise_error(TypeError) + -> { "hello".send(@method, /(?<q>.)/, {}) }.should raise_error(TypeError) + -> { "hello".send(@method, /(?<q>.)/, []) }.should raise_error(TypeError) end it "raises an IndexError when given the empty String as a group name" do - lambda { "hello".send(@method, /(?<q>)/, '') }.should raise_error(IndexError) + -> { "hello".send(@method, /(?<q>)/, '') }.should raise_error(IndexError) end it "returns subclass instances" do @@ -552,6 +552,6 @@ end describe :string_slice_symbol, shared: true do it "raises TypeError" do - lambda { 'hello'.send(@method, :hello) }.should raise_error(TypeError) + -> { 'hello'.send(@method, :hello) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/string/shared/succ.rb b/spec/ruby/core/string/shared/succ.rb index 0ab659864d..31b4a8b5dd 100644 --- a/spec/ruby/core/string/shared/succ.rb +++ b/spec/ruby/core/string/shared/succ.rb @@ -82,7 +82,7 @@ describe :string_succ_bang, shared: true do end it "raises a #{frozen_error_class} if self is frozen" do - lambda { "".freeze.send(@method) }.should raise_error(frozen_error_class) - lambda { "abcd".freeze.send(@method) }.should raise_error(frozen_error_class) + -> { "".freeze.send(@method) }.should raise_error(frozen_error_class) + -> { "abcd".freeze.send(@method) }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/slice_spec.rb b/spec/ruby/core/string/slice_spec.rb index e969f85937..2af663117c 100644 --- a/spec/ruby/core/string/slice_spec.rb +++ b/spec/ruby/core/string/slice_spec.rb @@ -54,9 +54,9 @@ describe "String#slice! with index" do end it "raises a #{frozen_error_class} if self is frozen" do - lambda { "hello".freeze.slice!(1) }.should raise_error(frozen_error_class) - lambda { "hello".freeze.slice!(10) }.should raise_error(frozen_error_class) - lambda { "".freeze.slice!(0) }.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(1) }.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(10) }.should raise_error(frozen_error_class) + -> { "".freeze.slice!(0) }.should raise_error(frozen_error_class) end it "calls to_int on index" do @@ -118,13 +118,13 @@ describe "String#slice! with index, length" do end it "raises a #{frozen_error_class} if self is frozen" do - lambda { "hello".freeze.slice!(1, 2) }.should raise_error(frozen_error_class) - lambda { "hello".freeze.slice!(10, 3) }.should raise_error(frozen_error_class) - lambda { "hello".freeze.slice!(-10, 3)}.should raise_error(frozen_error_class) - lambda { "hello".freeze.slice!(4, -3) }.should raise_error(frozen_error_class) - lambda { "hello".freeze.slice!(10, 3) }.should raise_error(frozen_error_class) - lambda { "hello".freeze.slice!(-10, 3)}.should raise_error(frozen_error_class) - lambda { "hello".freeze.slice!(4, -3) }.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(1, 2) }.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(10, 3) }.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(-10, 3)}.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(4, -3) }.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(10, 3) }.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(-10, 3)}.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(4, -3) }.should raise_error(frozen_error_class) end it "calls to_int on idx and length" do @@ -245,12 +245,12 @@ describe "String#slice! Range" do it "raises a #{frozen_error_class} on a frozen instance that is modified" do - lambda { "hello".freeze.slice!(1..3) }.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(1..3) }.should raise_error(frozen_error_class) end # see redmine #1551 it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do - lambda { "hello".freeze.slice!(10..20)}.should raise_error(frozen_error_class) + -> { "hello".freeze.slice!(10..20)}.should raise_error(frozen_error_class) end end @@ -313,11 +313,11 @@ describe "String#slice! with Regexp" do end it "raises a #{frozen_error_class} on a frozen instance that is modified" do - lambda { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(frozen_error_class) + -> { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(frozen_error_class) end it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do - lambda { "this is a string".freeze.slice!(/zzz/) }.should raise_error(frozen_error_class) + -> { "this is a string".freeze.slice!(/zzz/) }.should raise_error(frozen_error_class) end end @@ -403,9 +403,9 @@ describe "String#slice! with Regexp, index" do end it "raises a #{frozen_error_class} if self is frozen" do - lambda { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(frozen_error_class) - lambda { "this is a string".freeze.slice!(/zzz/, 0)}.should raise_error(frozen_error_class) - lambda { "this is a string".freeze.slice!(/(.)/, 2)}.should raise_error(frozen_error_class) + -> { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(frozen_error_class) + -> { "this is a string".freeze.slice!(/zzz/, 0)}.should raise_error(frozen_error_class) + -> { "this is a string".freeze.slice!(/(.)/, 2)}.should raise_error(frozen_error_class) end end @@ -448,7 +448,7 @@ describe "String#slice! with String" do o = mock('x') o.should_not_receive(:to_str) - lambda { "hello".slice!(o) }.should raise_error(TypeError) + -> { "hello".slice!(o) }.should raise_error(TypeError) end it "returns a subclass instance when given a subclass instance" do @@ -459,8 +459,8 @@ describe "String#slice! with String" do end it "raises a #{frozen_error_class} if self is frozen" do - lambda { "hello hello".freeze.slice!('llo') }.should raise_error(frozen_error_class) - lambda { "this is a string".freeze.slice!('zzz')}.should raise_error(frozen_error_class) - lambda { "this is a string".freeze.slice!('zzz')}.should raise_error(frozen_error_class) + -> { "hello hello".freeze.slice!('llo') }.should raise_error(frozen_error_class) + -> { "this is a string".freeze.slice!('zzz')}.should raise_error(frozen_error_class) + -> { "this is a string".freeze.slice!('zzz')}.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb index 6c666deb6c..655f0dae76 100644 --- a/spec/ruby/core/string/split_spec.rb +++ b/spec/ruby/core/string/split_spec.rb @@ -9,7 +9,7 @@ describe "String#split with String" do broken_str.force_encoding('binary') broken_str.chop! broken_str.force_encoding('utf-8') - lambda { str.split(broken_str) }.should raise_error(ArgumentError) + -> { str.split(broken_str) }.should raise_error(ArgumentError) end it "splits on multibyte characters" do @@ -316,8 +316,8 @@ describe "String#split with Regexp" do end it "returns a type error if limit can't be converted to an integer" do - lambda {"1.2.3.4".split(".", "three")}.should raise_error(TypeError) - lambda {"1.2.3.4".split(".", nil) }.should raise_error(TypeError) + -> {"1.2.3.4".split(".", "three")}.should raise_error(TypeError) + -> {"1.2.3.4".split(".", nil) }.should raise_error(TypeError) end it "doesn't set $~" do @@ -400,7 +400,7 @@ describe "String#split with Regexp" do broken_str.force_encoding('binary') broken_str.chop! broken_str.force_encoding('utf-8') - lambda{ broken_str.split(/\r\n|\r|\n/) }.should raise_error(ArgumentError) + ->{ broken_str.split(/\r\n|\r|\n/) }.should raise_error(ArgumentError) end ruby_version_is "2.6" do diff --git a/spec/ruby/core/string/squeeze_spec.rb b/spec/ruby/core/string/squeeze_spec.rb index 391b356227..bcc320bb5b 100644 --- a/spec/ruby/core/string/squeeze_spec.rb +++ b/spec/ruby/core/string/squeeze_spec.rb @@ -50,8 +50,8 @@ describe "String#squeeze" do it "raises an ArgumentError when the parameter is out of sequence" do s = "--subbookkeeper--" - lambda { s.squeeze("e-b") }.should raise_error(ArgumentError) - lambda { s.squeeze("^e-b") }.should raise_error(ArgumentError) + -> { s.squeeze("e-b") }.should raise_error(ArgumentError) + -> { s.squeeze("^e-b") }.should raise_error(ArgumentError) end it "taints the result when self is tainted" do @@ -73,9 +73,9 @@ describe "String#squeeze" do end it "raises a TypeError when one set arg can't be converted to a string" do - lambda { "hello world".squeeze([]) }.should raise_error(TypeError) - lambda { "hello world".squeeze(Object.new)}.should raise_error(TypeError) - lambda { "hello world".squeeze(mock('x')) }.should raise_error(TypeError) + -> { "hello world".squeeze([]) }.should raise_error(TypeError) + -> { "hello world".squeeze(Object.new)}.should raise_error(TypeError) + -> { "hello world".squeeze(mock('x')) }.should raise_error(TypeError) end it "returns subclass instances when called on a subclass" do @@ -99,15 +99,15 @@ describe "String#squeeze!" do it "raises an ArgumentError when the parameter is out of sequence" do s = "--subbookkeeper--" - lambda { s.squeeze!("e-b") }.should raise_error(ArgumentError) - lambda { s.squeeze!("^e-b") }.should raise_error(ArgumentError) + -> { s.squeeze!("e-b") }.should raise_error(ArgumentError) + -> { s.squeeze!("^e-b") }.should raise_error(ArgumentError) end it "raises a #{frozen_error_class} when self is frozen" do a = "yellow moon" a.freeze - lambda { a.squeeze!("") }.should raise_error(frozen_error_class) - lambda { a.squeeze! }.should raise_error(frozen_error_class) + -> { a.squeeze!("") }.should raise_error(frozen_error_class) + -> { a.squeeze! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/start_with_spec.rb b/spec/ruby/core/string/start_with_spec.rb index 4e12c1a445..f66ec55266 100644 --- a/spec/ruby/core/string/start_with_spec.rb +++ b/spec/ruby/core/string/start_with_spec.rb @@ -28,9 +28,9 @@ describe "String#start_with?" do it "ignores arguments not convertible to string" do "hello".start_with?().should be_false - lambda { "hello".start_with?(1) }.should raise_error(TypeError) - lambda { "hello".start_with?(["h"]) }.should raise_error(TypeError) - lambda { "hello".start_with?(1, nil, "h") }.should raise_error(TypeError) + -> { "hello".start_with?(1) }.should raise_error(TypeError) + -> { "hello".start_with?(["h"]) }.should raise_error(TypeError) + -> { "hello".start_with?(1, nil, "h") }.should raise_error(TypeError) end it "uses only the needed arguments" do diff --git a/spec/ruby/core/string/strip_spec.rb b/spec/ruby/core/string/strip_spec.rb index 54dec794fa..c205746483 100644 --- a/spec/ruby/core/string/strip_spec.rb +++ b/spec/ruby/core/string/strip_spec.rb @@ -49,12 +49,12 @@ describe "String#strip!" do end it "raises a #{frozen_error_class} on a frozen instance that is modified" do - lambda { " hello ".freeze.strip! }.should raise_error(frozen_error_class) + -> { " hello ".freeze.strip! }.should raise_error(frozen_error_class) end # see #1552 it "raises a #{frozen_error_class} on a frozen instance that would not be modified" do - lambda {"hello".freeze.strip! }.should raise_error(frozen_error_class) - lambda {"".freeze.strip! }.should raise_error(frozen_error_class) + -> {"hello".freeze.strip! }.should raise_error(frozen_error_class) + -> {"".freeze.strip! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/sub_spec.rb b/spec/ruby/core/string/sub_spec.rb index 901d1596c5..630f0d6b70 100644 --- a/spec/ruby/core/string/sub_spec.rb +++ b/spec/ruby/core/string/sub_spec.rb @@ -166,16 +166,16 @@ describe "String#sub with pattern, replacement" do not_supported_on :opal do it "raises a TypeError when pattern is a Symbol" do - lambda { "hello".sub(:woot, "x") }.should raise_error(TypeError) + -> { "hello".sub(:woot, "x") }.should raise_error(TypeError) end end it "raises a TypeError when pattern is an Array" do - lambda { "hello".sub([], "x") }.should raise_error(TypeError) + -> { "hello".sub([], "x") }.should raise_error(TypeError) end it "raises a TypeError when pattern can't be converted to a string" do - lambda { "hello".sub(Object.new, nil) }.should raise_error(TypeError) + -> { "hello".sub(Object.new, nil) }.should raise_error(TypeError) end it "tries to convert replacement to a string using to_str" do @@ -186,8 +186,8 @@ describe "String#sub with pattern, replacement" do end it "raises a TypeError when replacement can't be converted to a string" do - lambda { "hello".sub(/[aeiou]/, []) }.should raise_error(TypeError) - lambda { "hello".sub(/[aeiou]/, 99) }.should raise_error(TypeError) + -> { "hello".sub(/[aeiou]/, []) }.should raise_error(TypeError) + -> { "hello".sub(/[aeiou]/, 99) }.should raise_error(TypeError) end it "returns subclass instances when called on a subclass" do @@ -330,9 +330,9 @@ describe "String#sub! with pattern, replacement" do s = "hello" s.freeze - lambda { s.sub!(/ROAR/, "x") }.should raise_error(frozen_error_class) - lambda { s.sub!(/e/, "e") }.should raise_error(frozen_error_class) - lambda { s.sub!(/[aeiou]/, '*') }.should raise_error(frozen_error_class) + -> { s.sub!(/ROAR/, "x") }.should raise_error(frozen_error_class) + -> { s.sub!(/e/, "e") }.should raise_error(frozen_error_class) + -> { s.sub!(/[aeiou]/, '*') }.should raise_error(frozen_error_class) end end @@ -376,16 +376,16 @@ describe "String#sub! with pattern and block" do it "raises a RuntimeError if the string is modified while substituting" do str = "hello" - lambda { str.sub!(//) { str << 'x' } }.should raise_error(RuntimeError) + -> { str.sub!(//) { str << 'x' } }.should raise_error(RuntimeError) end it "raises a #{frozen_error_class} when self is frozen" do s = "hello" s.freeze - lambda { s.sub!(/ROAR/) { "x" } }.should raise_error(frozen_error_class) - lambda { s.sub!(/e/) { "e" } }.should raise_error(frozen_error_class) - lambda { s.sub!(/[aeiou]/) { '*' } }.should raise_error(frozen_error_class) + -> { s.sub!(/ROAR/) { "x" } }.should raise_error(frozen_error_class) + -> { s.sub!(/e/) { "e" } }.should raise_error(frozen_error_class) + -> { s.sub!(/[aeiou]/) { '*' } }.should raise_error(frozen_error_class) end end @@ -428,7 +428,7 @@ describe "String#sub with pattern and Hash" do it "uses the hash's value set from default_proc for missing keys" do hsh = {} - hsh.default_proc = lambda { |k,v| 'lamb' } + hsh.default_proc = -> k, v { 'lamb' } "food!".sub(/./, hsh).should == "lambood!" end @@ -513,7 +513,7 @@ describe "String#sub! with pattern and Hash" do it "uses the hash's value set from default_proc for missing keys" do hsh = {} - hsh.default_proc = lambda { |k,v| 'lamb' } + hsh.default_proc = -> k, v { 'lamb' } "food!".sub!(/./, hsh).should == "lambood!" end @@ -560,12 +560,12 @@ end describe "String#sub with pattern and without replacement and block" do it "raises a ArgumentError" do - lambda { "abca".sub(/a/) }.should raise_error(ArgumentError) + -> { "abca".sub(/a/) }.should raise_error(ArgumentError) end end describe "String#sub! with pattern and without replacement and block" do it "raises a ArgumentError" do - lambda { "abca".sub!(/a/) }.should raise_error(ArgumentError) + -> { "abca".sub!(/a/) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb index c35751859e..95edcec7d1 100644 --- a/spec/ruby/core/string/swapcase_spec.rb +++ b/spec/ruby/core/string/swapcase_spec.rb @@ -45,7 +45,7 @@ describe "String#swapcase" do end it "does not allow any other additional option" do - lambda { "aiS".swapcase(:turkic, :ascii) }.should raise_error(ArgumentError) + -> { "aiS".swapcase(:turkic, :ascii) }.should raise_error(ArgumentError) end end @@ -59,16 +59,16 @@ describe "String#swapcase" do end it "does not allow any other additional option" do - lambda { "aiS".swapcase(:lithuanian, :ascii) }.should raise_error(ArgumentError) + -> { "aiS".swapcase(:lithuanian, :ascii) }.should raise_error(ArgumentError) end end it "does not allow the :fold option for upcasing" do - lambda { "abc".swapcase(:fold) }.should raise_error(ArgumentError) + -> { "abc".swapcase(:fold) }.should raise_error(ArgumentError) end it "does not allow invalid options" do - lambda { "abc".swapcase(:invalid_option) }.should raise_error(ArgumentError) + -> { "abc".swapcase(:invalid_option) }.should raise_error(ArgumentError) end it "returns subclass instances when called on a subclass" do @@ -124,7 +124,7 @@ describe "String#swapcase!" do end it "does not allow any other additional option" do - lambda { a = "aiS"; a.swapcase!(:turkic, :ascii) }.should raise_error(ArgumentError) + -> { a = "aiS"; a.swapcase!(:turkic, :ascii) }.should raise_error(ArgumentError) end end @@ -142,16 +142,16 @@ describe "String#swapcase!" do end it "does not allow any other additional option" do - lambda { a = "aiS"; a.swapcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError) + -> { a = "aiS"; a.swapcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError) end end it "does not allow the :fold option for upcasing" do - lambda { a = "abc"; a.swapcase!(:fold) }.should raise_error(ArgumentError) + -> { a = "abc"; a.swapcase!(:fold) }.should raise_error(ArgumentError) end it "does not allow invalid options" do - lambda { a = "abc"; a.swapcase!(:invalid_option) }.should raise_error(ArgumentError) + -> { a = "abc"; a.swapcase!(:invalid_option) }.should raise_error(ArgumentError) end it "returns nil if no modifications were made" do @@ -165,7 +165,7 @@ describe "String#swapcase!" do it "raises a #{frozen_error_class} when self is frozen" do ["", "hello"].each do |a| a.freeze - lambda { a.swapcase! }.should raise_error(frozen_error_class) + -> { a.swapcase! }.should raise_error(frozen_error_class) end end end diff --git a/spec/ruby/core/string/to_i_spec.rb b/spec/ruby/core/string/to_i_spec.rb index f86d3a43a7..a37be47778 100644 --- a/spec/ruby/core/string/to_i_spec.rb +++ b/spec/ruby/core/string/to_i_spec.rb @@ -126,9 +126,9 @@ describe "String#to_i" do end it "raises an ArgumentError for illegal bases (1, < 0 or > 36)" do - lambda { "".to_i(1) }.should raise_error(ArgumentError) - lambda { "".to_i(-1) }.should raise_error(ArgumentError) - lambda { "".to_i(37) }.should raise_error(ArgumentError) + -> { "".to_i(1) }.should raise_error(ArgumentError) + -> { "".to_i(-1) }.should raise_error(ArgumentError) + -> { "".to_i(37) }.should raise_error(ArgumentError) end it "returns a Fixnum for long strings with trailing spaces" do diff --git a/spec/ruby/core/string/tr_s_spec.rb b/spec/ruby/core/string/tr_s_spec.rb index b05211abc4..4380f2d548 100644 --- a/spec/ruby/core/string/tr_s_spec.rb +++ b/spec/ruby/core/string/tr_s_spec.rb @@ -127,8 +127,8 @@ describe "String#tr_s!" do it "raises a #{frozen_error_class} if self is frozen" do s = "hello".freeze - lambda { s.tr_s!("el", "ar") }.should raise_error(frozen_error_class) - lambda { s.tr_s!("l", "r") }.should raise_error(frozen_error_class) - lambda { s.tr_s!("", "") }.should raise_error(frozen_error_class) + -> { s.tr_s!("el", "ar") }.should raise_error(frozen_error_class) + -> { s.tr_s!("l", "r") }.should raise_error(frozen_error_class) + -> { s.tr_s!("", "") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/tr_spec.rb b/spec/ruby/core/string/tr_spec.rb index 8a33dd24f5..721ebab51c 100644 --- a/spec/ruby/core/string/tr_spec.rb +++ b/spec/ruby/core/string/tr_spec.rb @@ -22,11 +22,11 @@ describe "String#tr" do end it "raises an ArgumentError a descending range in the replacement as containing just the start character" do - lambda { "hello".tr("a-y", "z-b") }.should raise_error(ArgumentError) + -> { "hello".tr("a-y", "z-b") }.should raise_error(ArgumentError) end it "raises an ArgumentError a descending range in the source as empty" do - lambda { "hello".tr("l-a", "z") }.should raise_error(ArgumentError) + -> { "hello".tr("l-a", "z") }.should raise_error(ArgumentError) end it "translates chars not in from_string when it starts with a ^" do @@ -122,8 +122,8 @@ describe "String#tr!" do it "raises a #{frozen_error_class} if self is frozen" do s = "abcdefghijklmnopqR".freeze - lambda { s.tr!("cdefg", "12") }.should raise_error(frozen_error_class) - lambda { s.tr!("R", "S") }.should raise_error(frozen_error_class) - lambda { s.tr!("", "") }.should raise_error(frozen_error_class) + -> { s.tr!("cdefg", "12") }.should raise_error(frozen_error_class) + -> { s.tr!("R", "S") }.should raise_error(frozen_error_class) + -> { s.tr!("", "") }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/try_convert_spec.rb b/spec/ruby/core/string/try_convert_spec.rb index 629817110e..84415c4a75 100644 --- a/spec/ruby/core/string/try_convert_spec.rb +++ b/spec/ruby/core/string/try_convert_spec.rb @@ -39,12 +39,12 @@ describe "String.try_convert" do it "sends #to_str to the argument and raises TypeError if it's not a kind of String" do obj = mock("to_str") obj.should_receive(:to_str).and_return(Object.new) - lambda { String.try_convert obj }.should raise_error(TypeError) + -> { String.try_convert obj }.should raise_error(TypeError) end it "does not rescue exceptions raised by #to_str" do obj = mock("to_str") obj.should_receive(:to_str).and_raise(RuntimeError) - lambda { String.try_convert obj }.should raise_error(RuntimeError) + -> { String.try_convert obj }.should raise_error(RuntimeError) end end diff --git a/spec/ruby/core/string/unicode_normalize_spec.rb b/spec/ruby/core/string/unicode_normalize_spec.rb index 7a4662e0b8..6de7533fc7 100644 --- a/spec/ruby/core/string/unicode_normalize_spec.rb +++ b/spec/ruby/core/string/unicode_normalize_spec.rb @@ -48,13 +48,13 @@ describe "String#unicode_normalize" do end it "raises an Encoding::CompatibilityError if string is not in an unicode encoding" do - lambda do + -> do [0xE0].pack('C').force_encoding("ISO-8859-1").unicode_normalize(:nfd) end.should raise_error(Encoding::CompatibilityError) end it "raises an ArgumentError if the specified form is invalid" do - lambda { + -> { @angstrom.unicode_normalize(:invalid_form) }.should raise_error(ArgumentError) end @@ -101,14 +101,14 @@ describe "String#unicode_normalize!" do end it "raises an Encoding::CompatibilityError if the string is not in an unicode encoding" do - lambda { + -> { [0xE0].pack('C').force_encoding("ISO-8859-1").unicode_normalize! }.should raise_error(Encoding::CompatibilityError) end it "raises an ArgumentError if the specified form is invalid" do ohm = "\u2126" - lambda { + -> { ohm.unicode_normalize!(:invalid_form) }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/string/unicode_normalized_spec.rb b/spec/ruby/core/string/unicode_normalized_spec.rb index d383c0a91e..25c810a98f 100644 --- a/spec/ruby/core/string/unicode_normalized_spec.rb +++ b/spec/ruby/core/string/unicode_normalized_spec.rb @@ -37,11 +37,11 @@ describe "String#unicode_normalized?" do end it "raises an Encoding::CompatibilityError if the string is not in an unicode encoding" do - lambda { @nfc_normalized_str.force_encoding("ISO-8859-1").unicode_normalized? }.should raise_error(Encoding::CompatibilityError) + -> { @nfc_normalized_str.force_encoding("ISO-8859-1").unicode_normalized? }.should raise_error(Encoding::CompatibilityError) end it "raises an ArgumentError if the specified form is invalid" do - lambda { @nfc_normalized_str.unicode_normalized?(:invalid_form) }.should raise_error(ArgumentError) + -> { @nfc_normalized_str.unicode_normalized?(:invalid_form) }.should raise_error(ArgumentError) end it "returns true if str is in Unicode normalization form (nfc)" do diff --git a/spec/ruby/core/string/unpack/at_spec.rb b/spec/ruby/core/string/unpack/at_spec.rb index d8e55a1020..70b2389d69 100644 --- a/spec/ruby/core/string/unpack/at_spec.rb +++ b/spec/ruby/core/string/unpack/at_spec.rb @@ -24,6 +24,6 @@ describe "String#unpack with format '@'" do end it "raises an ArgumentError if the count exceeds the size of the String" do - lambda { "\x01\x02\x03\x04".unpack("C2@5C") }.should raise_error(ArgumentError) + -> { "\x01\x02\x03\x04".unpack("C2@5C") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/unpack/p_spec.rb b/spec/ruby/core/string/unpack/p_spec.rb index 136e32adfd..a544bc29c1 100644 --- a/spec/ruby/core/string/unpack/p_spec.rb +++ b/spec/ruby/core/string/unpack/p_spec.rb @@ -15,7 +15,7 @@ describe "String#unpack with format 'P'" do packed = ["hello"].pack("P") packed.unpack("P5").should == ["hello"] packed.dup.unpack("P5").should == ["hello"] - lambda { packed.to_sym.to_s.unpack("P5") }.should raise_error(ArgumentError, /no associated pointer/) + -> { packed.to_sym.to_s.unpack("P5") }.should raise_error(ArgumentError, /no associated pointer/) end it "taints the unpacked string" do @@ -43,7 +43,7 @@ describe "String#unpack with format 'p'" do packed = ["hello"].pack("p") packed.unpack("p").should == ["hello"] packed.dup.unpack("p").should == ["hello"] - lambda { packed.to_sym.to_s.unpack("p") }.should raise_error(ArgumentError, /no associated pointer/) + -> { packed.to_sym.to_s.unpack("p") }.should raise_error(ArgumentError, /no associated pointer/) end it "taints the unpacked string" do diff --git a/spec/ruby/core/string/unpack/percent_spec.rb b/spec/ruby/core/string/unpack/percent_spec.rb index f0684d4cbc..0e27663195 100644 --- a/spec/ruby/core/string/unpack/percent_spec.rb +++ b/spec/ruby/core/string/unpack/percent_spec.rb @@ -2,6 +2,6 @@ require_relative '../../../spec_helper' describe "String#unpack with format '%'" do it "raises an Argument Error" do - lambda { "abc".unpack("%") }.should raise_error(ArgumentError) + -> { "abc".unpack("%") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/unpack/shared/basic.rb b/spec/ruby/core/string/unpack/shared/basic.rb index 0ecbf615af..332e39d8d1 100644 --- a/spec/ruby/core/string/unpack/shared/basic.rb +++ b/spec/ruby/core/string/unpack/shared/basic.rb @@ -10,20 +10,20 @@ describe :string_unpack_basic, shared: true do end it "raises a TypeError when passed nil" do - lambda { "abc".unpack(nil) }.should raise_error(TypeError) + -> { "abc".unpack(nil) }.should raise_error(TypeError) end it "raises a TypeError when passed an Integer" do - lambda { "abc".unpack(1) }.should raise_error(TypeError) + -> { "abc".unpack(1) }.should raise_error(TypeError) end end describe :string_unpack_no_platform, shared: true do it "raises an ArgumentError when the format modifier is '_'" do - lambda { "abcdefgh".unpack(unpack_format("_")) }.should raise_error(ArgumentError) + -> { "abcdefgh".unpack(unpack_format("_")) }.should raise_error(ArgumentError) end it "raises an ArgumentError when the format modifier is '!'" do - lambda { "abcdefgh".unpack(unpack_format("!")) }.should raise_error(ArgumentError) + -> { "abcdefgh".unpack(unpack_format("!")) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/unpack/u_spec.rb b/spec/ruby/core/string/unpack/u_spec.rb index 8db6de1ab3..7845e6d5f2 100644 --- a/spec/ruby/core/string/unpack/u_spec.rb +++ b/spec/ruby/core/string/unpack/u_spec.rb @@ -12,11 +12,11 @@ describe "String#unpack with format 'U'" do it_behaves_like :string_unpack_taint, 'U' it "raises ArgumentError on a malformed byte sequence" do - lambda { "\xE3".unpack('U') }.should raise_error(ArgumentError) + -> { "\xE3".unpack('U') }.should raise_error(ArgumentError) end it "raises ArgumentError on a malformed byte sequence and doesn't continue when used with the * modifier" do - lambda { "\xE3".unpack('U*') }.should raise_error(ArgumentError) + -> { "\xE3".unpack('U*') }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/unpack/x_spec.rb b/spec/ruby/core/string/unpack/x_spec.rb index 5adcb720d1..5e248de77e 100644 --- a/spec/ruby/core/string/unpack/x_spec.rb +++ b/spec/ruby/core/string/unpack/x_spec.rb @@ -24,11 +24,11 @@ describe "String#unpack with format 'X'" do end it "raises an ArgumentError when passed the '*' modifier if the remaining bytes exceed the bytes from the index to the start of the String" do - lambda { "abcd".unpack("CX*C") }.should raise_error(ArgumentError) + -> { "abcd".unpack("CX*C") }.should raise_error(ArgumentError) end it "raises an ArgumentError if the count exceeds the bytes from current index to the start of the String" do - lambda { "\x01\x02\x03\x04".unpack("C3X4C") }.should raise_error(ArgumentError) + -> { "\x01\x02\x03\x04".unpack("C3X4C") }.should raise_error(ArgumentError) end end @@ -57,6 +57,6 @@ describe "String#unpack with format 'x'" do end it "raises an ArgumentError if the count exceeds the size of the String" do - lambda { "\x01\x02\x03\x04".unpack("C2x3C") }.should raise_error(ArgumentError) + -> { "\x01\x02\x03\x04".unpack("C2x3C") }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb index eb736ebfa1..72aacd88a9 100644 --- a/spec/ruby/core/string/upcase_spec.rb +++ b/spec/ruby/core/string/upcase_spec.rb @@ -39,7 +39,7 @@ describe "String#upcase" do end it "does not allow any other additional option" do - lambda { "i".upcase(:turkic, :ascii) }.should raise_error(ArgumentError) + -> { "i".upcase(:turkic, :ascii) }.should raise_error(ArgumentError) end end @@ -53,16 +53,16 @@ describe "String#upcase" do end it "does not allow any other additional option" do - lambda { "iß".upcase(:lithuanian, :ascii) }.should raise_error(ArgumentError) + -> { "iß".upcase(:lithuanian, :ascii) }.should raise_error(ArgumentError) end end it "does not allow the :fold option for upcasing" do - lambda { "abc".upcase(:fold) }.should raise_error(ArgumentError) + -> { "abc".upcase(:fold) }.should raise_error(ArgumentError) end it "does not allow invalid options" do - lambda { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError) + -> { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError) end it "taints result when self is tainted" do @@ -123,7 +123,7 @@ describe "String#upcase!" do end it "does not allow any other additional option" do - lambda { a = "i"; a.upcase!(:turkic, :ascii) }.should raise_error(ArgumentError) + -> { a = "i"; a.upcase!(:turkic, :ascii) }.should raise_error(ArgumentError) end end @@ -141,16 +141,16 @@ describe "String#upcase!" do end it "does not allow any other additional option" do - lambda { a = "iß"; a.upcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError) + -> { a = "iß"; a.upcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError) end end it "does not allow the :fold option for upcasing" do - lambda { a = "abc"; a.upcase!(:fold) }.should raise_error(ArgumentError) + -> { a = "abc"; a.upcase!(:fold) }.should raise_error(ArgumentError) end it "does not allow invalid options" do - lambda { a = "abc"; a.upcase!(:invalid_option) }.should raise_error(ArgumentError) + -> { a = "abc"; a.upcase!(:invalid_option) }.should raise_error(ArgumentError) end it "returns nil if no modifications were made" do @@ -160,7 +160,7 @@ describe "String#upcase!" do end it "raises a #{frozen_error_class} when self is frozen" do - lambda { "HeLlo".freeze.upcase! }.should raise_error(frozen_error_class) - lambda { "HELLO".freeze.upcase! }.should raise_error(frozen_error_class) + -> { "HeLlo".freeze.upcase! }.should raise_error(frozen_error_class) + -> { "HELLO".freeze.upcase! }.should raise_error(frozen_error_class) end end diff --git a/spec/ruby/core/string/upto_spec.rb b/spec/ruby/core/string/upto_spec.rb index 3748a6fdeb..b988613a80 100644 --- a/spec/ruby/core/string/upto_spec.rb +++ b/spec/ruby/core/string/upto_spec.rb @@ -53,13 +53,13 @@ describe "String#upto" do end it "raises a TypeError if other can't be converted to a string" do - lambda { "abc".upto(123) { } }.should raise_error(TypeError) - lambda { "abc".upto(mock('x')){ } }.should raise_error(TypeError) + -> { "abc".upto(123) { } }.should raise_error(TypeError) + -> { "abc".upto(mock('x')){ } }.should raise_error(TypeError) end it "does not work with symbols" do - lambda { "a".upto(:c).to_a }.should raise_error(TypeError) + -> { "a".upto(:c).to_a }.should raise_error(TypeError) end it "returns non-alphabetic characters in the ASCII range for single letters" do diff --git a/spec/ruby/core/struct/dig_spec.rb b/spec/ruby/core/struct/dig_spec.rb index c7c979fabe..4e39e5a4ef 100644 --- a/spec/ruby/core/struct/dig_spec.rb +++ b/spec/ruby/core/struct/dig_spec.rb @@ -20,13 +20,13 @@ describe "Struct#dig" do it "raises a TypeError if any intermediate step does not respond to #dig" do instance = @klass.new(1) - lambda { + -> { instance.dig(:a, 3) }.should raise_error(TypeError) end it "raises an ArgumentError if no arguments provided" do - lambda { @instance.dig }.should raise_error(ArgumentError) + -> { @instance.dig }.should raise_error(ArgumentError) end it "calls #dig on any intermediate step with the rest of the sequence as arguments" do diff --git a/spec/ruby/core/struct/element_reference_spec.rb b/spec/ruby/core/struct/element_reference_spec.rb index 28706a65aa..0f6d547f66 100644 --- a/spec/ruby/core/struct/element_reference_spec.rb +++ b/spec/ruby/core/struct/element_reference_spec.rb @@ -26,20 +26,20 @@ describe "Struct#[]" do it "fails when it does not know about the requested attribute" do car = StructClasses::Car.new('Ford', 'Ranger') - lambda { car[3] }.should raise_error(IndexError) - lambda { car[-4] }.should raise_error(IndexError) - lambda { car[:body] }.should raise_error(NameError) - lambda { car['wheels'] }.should raise_error(NameError) + -> { car[3] }.should raise_error(IndexError) + -> { car[-4] }.should raise_error(IndexError) + -> { car[:body] }.should raise_error(NameError) + -> { car['wheels'] }.should raise_error(NameError) end it "fails if passed too many arguments" do car = StructClasses::Car.new('Ford', 'Ranger') - lambda { car[:make, :model] }.should raise_error(ArgumentError) + -> { car[:make, :model] }.should raise_error(ArgumentError) end it "fails if not passed a string, symbol, or integer" do car = StructClasses::Car.new('Ford', 'Ranger') - lambda { car[Object.new] }.should raise_error(TypeError) + -> { car[Object.new] }.should raise_error(TypeError) end it "returns attribute names that contain hyphens" do diff --git a/spec/ruby/core/struct/element_set_spec.rb b/spec/ruby/core/struct/element_set_spec.rb index 246e7cf3c2..6ba7b081a9 100644 --- a/spec/ruby/core/struct/element_set_spec.rb +++ b/spec/ruby/core/struct/element_set_spec.rb @@ -21,9 +21,9 @@ describe "Struct#[]=" do it "fails when trying to assign attributes which don't exist" do car = StructClasses::Car.new('Ford', 'Ranger') - lambda { car[:something] = true }.should raise_error(NameError) - lambda { car[3] = true }.should raise_error(IndexError) - lambda { car[-4] = true }.should raise_error(IndexError) - lambda { car[Object.new] = true }.should raise_error(TypeError) + -> { car[:something] = true }.should raise_error(NameError) + -> { car[3] = true }.should raise_error(IndexError) + -> { car[-4] = true }.should raise_error(IndexError) + -> { car[Object.new] = true }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/struct/new_spec.rb b/spec/ruby/core/struct/new_spec.rb index 01231e85fb..f888106950 100644 --- a/spec/ruby/core/struct/new_spec.rb +++ b/spec/ruby/core/struct/new_spec.rb @@ -13,7 +13,7 @@ describe "Struct.new" do first.should == Struct::Person second = nil - lambda { + -> { second = Struct.new('Person', :hair, :sex) }.should complain(/redefining constant/) second.should == Struct::Person @@ -49,35 +49,35 @@ describe "Struct.new" do it "fails with invalid constant name as first argument" do - lambda { Struct.new('animal', :name, :legs, :eyeballs) }.should raise_error(NameError) + -> { Struct.new('animal', :name, :legs, :eyeballs) }.should raise_error(NameError) end it "raises a TypeError if object doesn't respond to to_sym" do - lambda { Struct.new(:animal, mock('giraffe')) }.should raise_error(TypeError) - lambda { Struct.new(:animal, 1.0) }.should raise_error(TypeError) - lambda { Struct.new(:animal, Time.now) }.should raise_error(TypeError) - lambda { Struct.new(:animal, Class) }.should raise_error(TypeError) - lambda { Struct.new(:animal, nil) }.should raise_error(TypeError) - lambda { Struct.new(:animal, true) }.should raise_error(TypeError) - lambda { Struct.new(:animal, ['chris', 'evan']) }.should raise_error(TypeError) + -> { Struct.new(:animal, mock('giraffe')) }.should raise_error(TypeError) + -> { Struct.new(:animal, 1.0) }.should raise_error(TypeError) + -> { Struct.new(:animal, Time.now) }.should raise_error(TypeError) + -> { Struct.new(:animal, Class) }.should raise_error(TypeError) + -> { Struct.new(:animal, nil) }.should raise_error(TypeError) + -> { Struct.new(:animal, true) }.should raise_error(TypeError) + -> { Struct.new(:animal, ['chris', 'evan']) }.should raise_error(TypeError) end ruby_version_is ""..."2.5" do it "raises a TypeError if an argument is a Hash" do - lambda { Struct.new(:animal, { name: 'chris' }) }.should raise_error(TypeError) + -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(TypeError) end end ruby_version_is "2.5" do it "raises a ArgumentError if passed a Hash with an unknown key" do - lambda { Struct.new(:animal, { name: 'chris' }) }.should raise_error(ArgumentError) + -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(ArgumentError) end end it "raises a TypeError if object is not a Symbol" do obj = mock(':ruby') def obj.to_sym() :ruby end - lambda { Struct.new(:animal, obj) }.should raise_error(TypeError) + -> { Struct.new(:animal, obj) }.should raise_error(TypeError) end it "processes passed block with instance_eval" do @@ -128,7 +128,7 @@ describe "Struct.new" do end it "fails with too many arguments" do - lambda { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError) + -> { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError) end it "passes a hash as a normal argument" do diff --git a/spec/ruby/core/struct/struct_spec.rb b/spec/ruby/core/struct/struct_spec.rb index 11e619dcde..8817dc1a58 100644 --- a/spec/ruby/core/struct/struct_spec.rb +++ b/spec/ruby/core/struct/struct_spec.rb @@ -21,7 +21,7 @@ describe "Struct anonymous class instance methods" do it "reader method should not interfere with undefined methods" do car = StructClasses::Car.new('Ford', 'Ranger') - lambda { car.something_weird }.should raise_error(NoMethodError) + -> { car.something_weird }.should raise_error(NoMethodError) end it "writer method be a synonym for []=" do diff --git a/spec/ruby/core/struct/values_at_spec.rb b/spec/ruby/core/struct/values_at_spec.rb index f9602d53f7..7e517cdb4b 100644 --- a/spec/ruby/core/struct/values_at_spec.rb +++ b/spec/ruby/core/struct/values_at_spec.rb @@ -11,6 +11,6 @@ describe "Struct#values_at" do it "fails when passed unsupported types" do car = StructClasses::Car.new('Ford', 'Ranger') - lambda { car.values_at('make') }.should raise_error(TypeError) + -> { car.values_at('make') }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/symbol/shared/slice.rb b/spec/ruby/core/symbol/shared/slice.rb index 80e1fd3ddc..478e0d80ae 100644 --- a/spec/ruby/core/symbol/shared/slice.rb +++ b/spec/ruby/core/symbol/shared/slice.rb @@ -74,21 +74,21 @@ describe :symbol_slice, shared: true do describe "and a nil length" do it "raises a TypeError" do - lambda { :symbol.send(@method, 1,nil) }.should raise_error(TypeError) + -> { :symbol.send(@method, 1,nil) }.should raise_error(TypeError) end end describe "and a length that cannot be converted into an Integer" do it "raises a TypeError when given an Array" do - lambda { :symbol.send(@method, 1,Array.new) }.should raise_error(TypeError) + -> { :symbol.send(@method, 1,Array.new) }.should raise_error(TypeError) end it "raises a TypeError when given an Hash" do - lambda { :symbol.send(@method, 1,Hash.new) }.should raise_error(TypeError) + -> { :symbol.send(@method, 1,Hash.new) }.should raise_error(TypeError) end it "raises a TypeError when given an Object" do - lambda { :symbol.send(@method, 1,Object.new) }.should raise_error(TypeError) + -> { :symbol.send(@method, 1,Object.new) }.should raise_error(TypeError) end end end @@ -101,21 +101,21 @@ describe :symbol_slice, shared: true do describe "with a nil index" do it "raises a TypeError" do - lambda { :symbol.send(@method, nil) }.should raise_error(TypeError) + -> { :symbol.send(@method, nil) }.should raise_error(TypeError) end end describe "with an index that cannot be converted into an Integer" do it "raises a TypeError when given an Array" do - lambda { :symbol.send(@method, Array.new) }.should raise_error(TypeError) + -> { :symbol.send(@method, Array.new) }.should raise_error(TypeError) end it "raises a TypeError when given an Hash" do - lambda { :symbol.send(@method, Hash.new) }.should raise_error(TypeError) + -> { :symbol.send(@method, Hash.new) }.should raise_error(TypeError) end it "raises a TypeError when given an Object" do - lambda { :symbol.send(@method, Object.new) }.should raise_error(TypeError) + -> { :symbol.send(@method, Object.new) }.should raise_error(TypeError) end end @@ -229,20 +229,20 @@ describe :symbol_slice, shared: true do describe "and an index that cannot be converted to an Integer" do it "raises a TypeError when given an Hash" do - lambda { :symbol.send(@method, /(sy)(mb)(ol)/, Hash.new) }.should raise_error(TypeError) + -> { :symbol.send(@method, /(sy)(mb)(ol)/, Hash.new) }.should raise_error(TypeError) end it "raises a TypeError when given an Array" do - lambda { :symbol.send(@method, /(sy)(mb)(ol)/, Array.new) }.should raise_error(TypeError) + -> { :symbol.send(@method, /(sy)(mb)(ol)/, Array.new) }.should raise_error(TypeError) end it "raises a TypeError when given an Object" do - lambda { :symbol.send(@method, /(sy)(mb)(ol)/, Object.new) }.should raise_error(TypeError) + -> { :symbol.send(@method, /(sy)(mb)(ol)/, Object.new) }.should raise_error(TypeError) end end it "raises a TypeError if the index is nil" do - lambda { :symbol.send(@method, /(sy)(mb)(ol)/, nil) }.should raise_error(TypeError) + -> { :symbol.send(@method, /(sy)(mb)(ol)/, nil) }.should raise_error(TypeError) end it "sets $~ to the MatchData if there is a match" do diff --git a/spec/ruby/core/symbol/symbol_spec.rb b/spec/ruby/core/symbol/symbol_spec.rb index 56ce6f4a42..cefe70bc99 100644 --- a/spec/ruby/core/symbol/symbol_spec.rb +++ b/spec/ruby/core/symbol/symbol_spec.rb @@ -6,13 +6,13 @@ describe "Symbol" do end it ".allocate raises a TypeError" do - lambda do + -> do Symbol.allocate end.should raise_error(TypeError) end it ".new is undefined" do - lambda do + -> do Symbol.new end.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb index 65f6e27be4..60e33d7cb8 100644 --- a/spec/ruby/core/symbol/to_proc_spec.rb +++ b/spec/ruby/core/symbol/to_proc_spec.rb @@ -18,7 +18,7 @@ describe "Symbol#to_proc" do end it "raises an ArgumentError when calling #call on the Proc without receiver" do - lambda { :object_id.to_proc.call }.should raise_error(ArgumentError, "no receiver given") + -> { :object_id.to_proc.call }.should raise_error(ArgumentError, "no receiver given") end it "produces a proc that always returns [[:rest]] for #parameters" do diff --git a/spec/ruby/core/thread/abort_on_exception_spec.rb b/spec/ruby/core/thread/abort_on_exception_spec.rb index 88de77b1a8..34b648ca0f 100644 --- a/spec/ruby/core/thread/abort_on_exception_spec.rb +++ b/spec/ruby/core/thread/abort_on_exception_spec.rb @@ -35,7 +35,7 @@ describe :thread_abort_on_exception, shared: true do ScratchPad << :before @thread.abort_on_exception = true if @object - lambda do + -> do ThreadSpecs.state = :run # Wait for the main thread to be interrupted sleep diff --git a/spec/ruby/core/thread/allocate_spec.rb b/spec/ruby/core/thread/allocate_spec.rb index cd9aa1ee43..cfd556812f 100644 --- a/spec/ruby/core/thread/allocate_spec.rb +++ b/spec/ruby/core/thread/allocate_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Thread.allocate" do it "raises a TypeError" do - lambda { + -> { Thread.allocate }.should raise_error(TypeError) end diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/main.rb b/spec/ruby/core/thread/backtrace/location/fixtures/main.rb index d2d14ac957..bde208a059 100644 --- a/spec/ruby/core/thread/backtrace/location/fixtures/main.rb +++ b/spec/ruby/core/thread/backtrace/location/fixtures/main.rb @@ -1,5 +1,5 @@ -def example +def backtrace_location_example caller_locations[0].path end -print example +print backtrace_location_example diff --git a/spec/ruby/core/thread/element_reference_spec.rb b/spec/ruby/core/thread/element_reference_spec.rb index 4de33e1456..85280cb287 100644 --- a/spec/ruby/core/thread/element_reference_spec.rb +++ b/spec/ruby/core/thread/element_reference_spec.rb @@ -38,7 +38,7 @@ describe "Thread#[]" do end it "raises exceptions on the wrong type of keys" do - lambda { Thread.current[nil] }.should raise_error(TypeError) - lambda { Thread.current[5] }.should raise_error(TypeError) + -> { Thread.current[nil] }.should raise_error(TypeError) + -> { Thread.current[5] }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/thread/element_set_spec.rb b/spec/ruby/core/thread/element_set_spec.rb index c109468a5e..d974b5e1c7 100644 --- a/spec/ruby/core/thread/element_set_spec.rb +++ b/spec/ruby/core/thread/element_set_spec.rb @@ -17,8 +17,8 @@ describe "Thread#[]=" do end it "raises exceptions on the wrong type of keys" do - lambda { Thread.current[nil] = true }.should raise_error(TypeError) - lambda { Thread.current[5] = true }.should raise_error(TypeError) + -> { Thread.current[nil] = true }.should raise_error(TypeError) + -> { Thread.current[5] = true }.should raise_error(TypeError) end it "is not shared across fibers" do diff --git a/spec/ruby/core/thread/exclusive_spec.rb b/spec/ruby/core/thread/exclusive_spec.rb index 9de427fb52..a96ebe749d 100644 --- a/spec/ruby/core/thread/exclusive_spec.rb +++ b/spec/ruby/core/thread/exclusive_spec.rb @@ -28,7 +28,7 @@ describe "Thread.exclusive" do q1.pop.should == :ready - lambda { Thread.exclusive { } }.should block_caller + -> { Thread.exclusive { } }.should block_caller q2.push :done t.join @@ -36,7 +36,7 @@ describe "Thread.exclusive" do it "is not recursive" do Thread.exclusive do - lambda { Thread.exclusive { } }.should raise_error(ThreadError) + -> { Thread.exclusive { } }.should raise_error(ThreadError) end end end diff --git a/spec/ruby/core/thread/fixtures/classes.rb b/spec/ruby/core/thread/fixtures/classes.rb index 601e515e3e..c1f15935ee 100644 --- a/spec/ruby/core/thread/fixtures/classes.rb +++ b/spec/ruby/core/thread/fixtures/classes.rb @@ -1,10 +1,3 @@ -unless defined? Channel - require 'thread' - class Channel < Queue - alias receive shift - end -end - module ThreadSpecs class SubThread < Thread @@ -188,7 +181,7 @@ module ThreadSpecs def self.join_dying_thread_with_outer_ensure(kill_method_name=:kill) t = dying_thread_with_outer_ensure(kill_method_name) { yield } - lambda { t.join }.should raise_error(RuntimeError, "In dying thread") + -> { t.join }.should raise_error(RuntimeError, "In dying thread") return t end diff --git a/spec/ruby/core/thread/initialize_spec.rb b/spec/ruby/core/thread/initialize_spec.rb index 80e058a120..4fca900cd8 100644 --- a/spec/ruby/core/thread/initialize_spec.rb +++ b/spec/ruby/core/thread/initialize_spec.rb @@ -15,7 +15,7 @@ describe "Thread#initialize" do end it "raises a ThreadError" do - lambda { + -> { @t.instance_eval do initialize {} end diff --git a/spec/ruby/core/thread/join_spec.rb b/spec/ruby/core/thread/join_spec.rb index f60f91e436..f3c5cdc1ed 100644 --- a/spec/ruby/core/thread/join_spec.rb +++ b/spec/ruby/core/thread/join_spec.rb @@ -19,28 +19,28 @@ describe "Thread#join" do t.join(0).should equal(t) t.join(0.0).should equal(t) t.join(nil).should equal(t) - lambda { t.join(:foo) }.should raise_error TypeError - lambda { t.join("bar") }.should raise_error TypeError + -> { t.join(:foo) }.should raise_error TypeError + -> { t.join("bar") }.should raise_error TypeError end it "returns nil if it is not finished when given a timeout" do - c = Channel.new - t = Thread.new { c.receive } + q = Queue.new + t = Thread.new { q.pop } begin t.join(0).should == nil ensure - c << true + q << true end t.join.should == t end it "accepts a floating point timeout length" do - c = Channel.new - t = Thread.new { c.receive } + q = Queue.new + t = Thread.new { q.pop } begin t.join(0.01).should == nil ensure - c << true + q << true end t.join.should == t end @@ -50,7 +50,7 @@ describe "Thread#join" do Thread.current.report_on_exception = false raise NotImplementedError.new("Just kidding") } - lambda { t.join }.should raise_error(NotImplementedError) + -> { t.join }.should raise_error(NotImplementedError) end it "returns the dead thread" do @@ -60,6 +60,6 @@ describe "Thread#join" do it "raises any uncaught exception encountered in ensure block" do t = ThreadSpecs.dying_thread_ensures { raise NotImplementedError.new("Just kidding") } - lambda { t.join }.should raise_error(NotImplementedError) + -> { t.join }.should raise_error(NotImplementedError) end end diff --git a/spec/ruby/core/thread/key_spec.rb b/spec/ruby/core/thread/key_spec.rb index c4ed0f9c0d..6940cf5f28 100644 --- a/spec/ruby/core/thread/key_spec.rb +++ b/spec/ruby/core/thread/key_spec.rb @@ -17,8 +17,8 @@ describe "Thread#key?" do end it "raises exceptions on the wrong type of keys" do - lambda { Thread.current.key? nil }.should raise_error(TypeError) - lambda { Thread.current.key? 5 }.should raise_error(TypeError) + -> { Thread.current.key? nil }.should raise_error(TypeError) + -> { Thread.current.key? 5 }.should raise_error(TypeError) end it "is not shared across fibers" do diff --git a/spec/ruby/core/thread/list_spec.rb b/spec/ruby/core/thread/list_spec.rb index 80dd15c6ca..a0bf831856 100644 --- a/spec/ruby/core/thread/list_spec.rb +++ b/spec/ruby/core/thread/list_spec.rb @@ -25,13 +25,13 @@ describe "Thread.list" do end it "includes waiting threads" do - c = Channel.new - t = Thread.new { c.receive } + q = Queue.new + t = Thread.new { q.pop } begin Thread.pass while t.status and t.status != 'sleep' Thread.list.should include(t) ensure - c << nil + q << nil t.join end end diff --git a/spec/ruby/core/thread/name_spec.rb b/spec/ruby/core/thread/name_spec.rb index adb2d08fae..9b3d2f4b09 100644 --- a/spec/ruby/core/thread/name_spec.rb +++ b/spec/ruby/core/thread/name_spec.rb @@ -34,7 +34,7 @@ describe "Thread#name=" do end it "raises an ArgumentError if the name includes a null byte" do - lambda { + -> { @thread.name = "new thread\0name" }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/thread/new_spec.rb b/spec/ruby/core/thread/new_spec.rb index 80929035c7..3a57149381 100644 --- a/spec/ruby/core/thread/new_spec.rb +++ b/spec/ruby/core/thread/new_spec.rb @@ -3,10 +3,10 @@ require_relative 'fixtures/classes' describe "Thread.new" do it "creates a thread executing the given block" do - c = Channel.new - Thread.new { c << true }.join - c << false - c.receive.should == true + q = Queue.new + Thread.new { q << true }.join + q << false + q.pop.should == true end it "can pass arguments to the thread block" do @@ -18,7 +18,7 @@ describe "Thread.new" do end it "raises an exception when not given a block" do - lambda { Thread.new }.should raise_error(ThreadError) + -> { Thread.new }.should raise_error(ThreadError) end it "creates a subclass of thread calls super with a block in initialize" do @@ -34,7 +34,7 @@ describe "Thread.new" do end end - lambda { + -> { c.new }.should raise_error(ThreadError) end diff --git a/spec/ruby/core/thread/priority_spec.rb b/spec/ruby/core/thread/priority_spec.rb index 5da6216b53..e13ad478b5 100644 --- a/spec/ruby/core/thread/priority_spec.rb +++ b/spec/ruby/core/thread/priority_spec.rb @@ -59,7 +59,7 @@ describe "Thread#priority=" do describe "when set with a non-integer" do it "raises a type error" do - lambda{ @thread.priority = Object.new }.should raise_error(TypeError) + ->{ @thread.priority = Object.new }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/thread/shared/exit.rb b/spec/ruby/core/thread/shared/exit.rb index 4686b7b28b..40dc478947 100644 --- a/spec/ruby/core/thread/shared/exit.rb +++ b/spec/ruby/core/thread/shared/exit.rb @@ -116,7 +116,7 @@ describe :thread_exit, shared: true do it "propagates inner exception to Thread.join if there is an outer ensure clause" do thread = ThreadSpecs.dying_thread_with_outer_ensure(@method) { } - lambda { thread.join }.should raise_error(RuntimeError, "In dying thread") + -> { thread.join }.should raise_error(RuntimeError, "In dying thread") end it "runs all outer ensure clauses even if inner ensure clause raises exception" do diff --git a/spec/ruby/core/thread/shared/start.rb b/spec/ruby/core/thread/shared/start.rb index 80ce063a0e..2ba926bf00 100644 --- a/spec/ruby/core/thread/shared/start.rb +++ b/spec/ruby/core/thread/shared/start.rb @@ -4,7 +4,7 @@ describe :thread_start, shared: true do end it "raises an ArgumentError if not passed a block" do - lambda { + -> { Thread.send(@method) }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/thread/shared/wakeup.rb b/spec/ruby/core/thread/shared/wakeup.rb index 71838d88e5..f111edf0fd 100644 --- a/spec/ruby/core/thread/shared/wakeup.rb +++ b/spec/ruby/core/thread/shared/wakeup.rb @@ -56,6 +56,6 @@ describe :thread_wakeup, shared: true do it "raises a ThreadError when trying to wake up a dead thread" do t = Thread.new { 1 } t.join - lambda { t.send @method }.should raise_error(ThreadError) + -> { t.send @method }.should raise_error(ThreadError) end end diff --git a/spec/ruby/core/thread/value_spec.rb b/spec/ruby/core/thread/value_spec.rb index 30b12db125..30e43abd1a 100644 --- a/spec/ruby/core/thread/value_spec.rb +++ b/spec/ruby/core/thread/value_spec.rb @@ -11,11 +11,21 @@ describe "Thread#value" do Thread.current.report_on_exception = false raise "Hello" } - lambda { t.value }.should raise_error(RuntimeError, "Hello") + -> { t.value }.should raise_error(RuntimeError, "Hello") end it "is nil for a killed thread" do t = Thread.new { Thread.current.exit } t.value.should == nil end + + it "returns when the thread finished" do + q = Queue.new + t = Thread.new { + q.pop + } + -> { t.value }.should block_caller + q.push :result + t.value.should == :result + end end diff --git a/spec/ruby/core/threadgroup/add_spec.rb b/spec/ruby/core/threadgroup/add_spec.rb index 5d1354e65f..2921c1ab22 100644 --- a/spec/ruby/core/threadgroup/add_spec.rb +++ b/spec/ruby/core/threadgroup/add_spec.rb @@ -1,15 +1,14 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' describe "ThreadGroup#add" do before :each do - @chan1,@chan2 = Channel.new,Channel.new - @thread = Thread.new { @chan1 << :go; @chan2.receive } - @chan1.receive + @q1, @q2 = Queue.new, Queue.new + @thread = Thread.new { @q1 << :go; @q2.pop } + @q1.pop end after :each do - @chan2 << :done + @q2 << :done @thread.join end diff --git a/spec/ruby/core/threadgroup/enclose_spec.rb b/spec/ruby/core/threadgroup/enclose_spec.rb index d4a4359c66..dd9a7a362d 100644 --- a/spec/ruby/core/threadgroup/enclose_spec.rb +++ b/spec/ruby/core/threadgroup/enclose_spec.rb @@ -1,15 +1,14 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' describe "ThreadGroup#enclose" do before :each do - @chan1,@chan2 = Channel.new,Channel.new - @thread = Thread.new { @chan1 << :go; @chan2.receive } - @chan1.receive + @q1, @q2 = Queue.new, Queue.new + @thread = Thread.new { @q1 << :go; @q2.pop } + @q1.pop end after :each do - @chan2 << :done + @q2 << :done @thread.join end @@ -18,7 +17,7 @@ describe "ThreadGroup#enclose" do default_group = @thread.group thread_group.add(@thread) thread_group.enclose - lambda do + -> do default_group.add(@thread) end.should raise_error(ThreadError) end diff --git a/spec/ruby/core/threadgroup/fixtures/classes.rb b/spec/ruby/core/threadgroup/fixtures/classes.rb deleted file mode 100644 index 7dfe5e92d1..0000000000 --- a/spec/ruby/core/threadgroup/fixtures/classes.rb +++ /dev/null @@ -1,6 +0,0 @@ -unless defined? Channel - require 'thread' - class Channel < Queue - alias receive shift - end -end diff --git a/spec/ruby/core/threadgroup/list_spec.rb b/spec/ruby/core/threadgroup/list_spec.rb index 5f2281af8d..b2ac64324a 100644 --- a/spec/ruby/core/threadgroup/list_spec.rb +++ b/spec/ruby/core/threadgroup/list_spec.rb @@ -1,17 +1,16 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' describe "ThreadGroup#list" do it "returns the list of threads in the group" do - chan = Channel.new - th1 = Thread.new { chan << :go; sleep } - chan.receive.should == :go + q = Queue.new + th1 = Thread.new { q << :go; sleep } + q.pop.should == :go tg = ThreadGroup.new tg.add(th1) tg.list.should include(th1) - th2 = Thread.new { chan << :go; sleep } - chan.receive.should == :go + th2 = Thread.new { q << :go; sleep } + q.pop.should == :go tg.add(th2) (tg.list & [th1, th2]).should include(th1, th2) diff --git a/spec/ruby/core/time/at_spec.rb b/spec/ruby/core/time/at_spec.rb index 1493012676..592b331a28 100644 --- a/spec/ruby/core/time/at_spec.rb +++ b/spec/ruby/core/time/at_spec.rb @@ -71,11 +71,11 @@ describe "Time.at" do describe "passed non-Time, non-Numeric" do it "raises a TypeError with a String argument" do - lambda { Time.at("0") }.should raise_error(TypeError) + -> { Time.at("0") }.should raise_error(TypeError) end it "raises a TypeError with a nil argument" do - lambda { Time.at(nil) }.should raise_error(TypeError) + -> { Time.at(nil) }.should raise_error(TypeError) end describe "with an argument that responds to #to_int" do @@ -127,20 +127,20 @@ describe "Time.at" do describe "passed [Integer, nil]" do it "raises a TypeError" do - lambda { Time.at(0, nil) }.should raise_error(TypeError) + -> { Time.at(0, nil) }.should raise_error(TypeError) end end describe "passed [Integer, String]" do it "raises a TypeError" do - lambda { Time.at(0, "0") }.should raise_error(TypeError) + -> { Time.at(0, "0") }.should raise_error(TypeError) end end describe "passed [Time, Integer]" do # #8173 it "raises a TypeError" do - lambda { Time.at(Time.now, 500000) }.should raise_error(TypeError) + -> { Time.at(Time.now, 500000) }.should raise_error(TypeError) end end @@ -178,15 +178,15 @@ describe "Time.at" do context "not supported format" do it "raises ArgumentError" do - ->() { Time.at(0, 123456, 2) }.should raise_error(ArgumentError) - ->() { Time.at(0, 123456, nil) }.should raise_error(ArgumentError) - ->() { Time.at(0, 123456, :invalid) }.should raise_error(ArgumentError) + -> { Time.at(0, 123456, 2) }.should raise_error(ArgumentError) + -> { Time.at(0, 123456, nil) }.should raise_error(ArgumentError) + -> { Time.at(0, 123456, :invalid) }.should raise_error(ArgumentError) end it "does not try to convert format to Symbol with #to_sym" do format = "usec" format.should_not_receive(:to_sym) - -> () { Time.at(0, 123456, format) }.should raise_error(ArgumentError) + -> { Time.at(0, 123456, format) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/time/getlocal_spec.rb b/spec/ruby/core/time/getlocal_spec.rb index 8b6a21bb58..7196577dab 100644 --- a/spec/ruby/core/time/getlocal_spec.rb +++ b/spec/ruby/core/time/getlocal_spec.rb @@ -77,24 +77,24 @@ describe "Time#getlocal" do it "raises ArgumentError if the String argument is not of the form (+|-)HH:MM" do t = Time.now - lambda { t.getlocal("3600") }.should raise_error(ArgumentError) + -> { t.getlocal("3600") }.should raise_error(ArgumentError) end it "raises ArgumentError if the String argument is not in an ASCII-compatible encoding" do t = Time.now - lambda { t.getlocal("-01:00".encode("UTF-16LE")) }.should raise_error(ArgumentError) + -> { t.getlocal("-01:00".encode("UTF-16LE")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the argument represents a value less than or equal to -86400 seconds" do t = Time.new t.getlocal(-86400 + 1).utc_offset.should == (-86400 + 1) - lambda { t.getlocal(-86400) }.should raise_error(ArgumentError) + -> { t.getlocal(-86400) }.should raise_error(ArgumentError) end it "raises ArgumentError if the argument represents a value greater than or equal to 86400 seconds" do t = Time.new t.getlocal(86400 - 1).utc_offset.should == (86400 - 1) - lambda { t.getlocal(86400) }.should raise_error(ArgumentError) + -> { t.getlocal(86400) }.should raise_error(ArgumentError) end ruby_version_is "2.6" do @@ -116,7 +116,7 @@ describe "Time#getlocal" do time end - lambda { + -> { Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time) }.should_not raise_error end @@ -127,7 +127,7 @@ describe "Time#getlocal" do time end - lambda { + -> { Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone) }.should raise_error(TypeError, /can't convert \w+ into an exact number/) end @@ -138,7 +138,7 @@ describe "Time#getlocal" do time end - lambda { + -> { Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time) }.should_not raise_error end @@ -158,7 +158,7 @@ describe "Time#getlocal" do [Object.new, [], {}, :"some zone"].each do |zone| time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0) - lambda { + -> { time.getlocal(zone) }.should raise_error(TypeError, /can't convert \w+ into an exact number/) end diff --git a/spec/ruby/core/time/localtime_spec.rb b/spec/ruby/core/time/localtime_spec.rb index 7942653c78..2975e112d0 100644 --- a/spec/ruby/core/time/localtime_spec.rb +++ b/spec/ruby/core/time/localtime_spec.rb @@ -32,7 +32,7 @@ describe "Time#localtime" do it "raises a RuntimeError if the time has a different time zone" do time = Time.gm(2007, 1, 9, 12, 0, 0) time.freeze - lambda { time.localtime }.should raise_error(RuntimeError) + -> { time.localtime }.should raise_error(RuntimeError) end end @@ -118,23 +118,23 @@ describe "Time#localtime" do it "raises ArgumentError if the String argument is not of the form (+|-)HH:MM" do t = Time.now - lambda { t.localtime("3600") }.should raise_error(ArgumentError) + -> { t.localtime("3600") }.should raise_error(ArgumentError) end it "raises ArgumentError if the String argument is not in an ASCII-compatible encoding" do t = Time.now - lambda { t.localtime("-01:00".encode("UTF-16LE")) }.should raise_error(ArgumentError) + -> { t.localtime("-01:00".encode("UTF-16LE")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the argument represents a value less than or equal to -86400 seconds" do t = Time.new t.localtime(-86400 + 1).utc_offset.should == (-86400 + 1) - lambda { t.localtime(-86400) }.should raise_error(ArgumentError) + -> { t.localtime(-86400) }.should raise_error(ArgumentError) end it "raises ArgumentError if the argument represents a value greater than or equal to 86400 seconds" do t = Time.new t.localtime(86400 - 1).utc_offset.should == (86400 - 1) - lambda { t.localtime(86400) }.should raise_error(ArgumentError) + -> { t.localtime(86400) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/time/minus_spec.rb b/spec/ruby/core/time/minus_spec.rb index a47e726196..e0fbf94cb0 100644 --- a/spec/ruby/core/time/minus_spec.rb +++ b/spec/ruby/core/time/minus_spec.rb @@ -20,18 +20,18 @@ describe "Time#-" do end it "raises a TypeError if given argument is a coercible String" do - lambda { Time.now - "1" }.should raise_error(TypeError) - lambda { Time.now - "0.1" }.should raise_error(TypeError) - lambda { Time.now - "1/3" }.should raise_error(TypeError) + -> { Time.now - "1" }.should raise_error(TypeError) + -> { Time.now - "0.1" }.should raise_error(TypeError) + -> { Time.now - "1/3" }.should raise_error(TypeError) end it "raises TypeError on argument that can't be coerced" do - lambda { Time.now - Object.new }.should raise_error(TypeError) - lambda { Time.now - "stuff" }.should raise_error(TypeError) + -> { Time.now - Object.new }.should raise_error(TypeError) + -> { Time.now - "stuff" }.should raise_error(TypeError) end it "raises TypeError on nil argument" do - lambda { Time.now - nil }.should raise_error(TypeError) + -> { Time.now - nil }.should raise_error(TypeError) end it "tracks microseconds" do diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb index fe0e1aea31..84e97f8082 100644 --- a/spec/ruby/core/time/new_spec.rb +++ b/spec/ruby/core/time/new_spec.rb @@ -76,42 +76,42 @@ describe "Time.new with a utc_offset argument" do # [Bug #8679], r47676 it "disallows a value for minutes greater than 59" do - lambda { + -> { Time.new(2000, 1, 1, 0, 0, 0, "+01:60") }.should raise_error(ArgumentError) - lambda { + -> { Time.new(2000, 1, 1, 0, 0, 0, "+01:99") }.should raise_error(ArgumentError) end it "raises ArgumentError if the String argument is not of the form (+|-)HH:MM" do - lambda { Time.new(2000, 1, 1, 0, 0, 0, "3600") }.should raise_error(ArgumentError) + -> { Time.new(2000, 1, 1, 0, 0, 0, "3600") }.should raise_error(ArgumentError) end it "raises ArgumentError if the hour value is greater than 23" do - lambda { Time.new(2000, 1, 1, 0, 0, 0, "+24:00") }.should raise_error(ArgumentError) + -> { Time.new(2000, 1, 1, 0, 0, 0, "+24:00") }.should raise_error(ArgumentError) end it "raises ArgumentError if the String argument is not in an ASCII-compatible encoding" do - lambda { Time.new(2000, 1, 1, 0, 0, 0, "-04:10".encode("UTF-16LE")) }.should raise_error(ArgumentError) + -> { Time.new(2000, 1, 1, 0, 0, 0, "-04:10".encode("UTF-16LE")) }.should raise_error(ArgumentError) end it "raises ArgumentError if the argument represents a value less than or equal to -86400 seconds" do Time.new(2000, 1, 1, 0, 0, 0, -86400 + 1).utc_offset.should == (-86400 + 1) - lambda { Time.new(2000, 1, 1, 0, 0, 0, -86400) }.should raise_error(ArgumentError) + -> { Time.new(2000, 1, 1, 0, 0, 0, -86400) }.should raise_error(ArgumentError) end it "raises ArgumentError if the argument represents a value greater than or equal to 86400 seconds" do Time.new(2000, 1, 1, 0, 0, 0, 86400 - 1).utc_offset.should == (86400 - 1) - lambda { Time.new(2000, 1, 1, 0, 0, 0, 86400) }.should raise_error(ArgumentError) + -> { Time.new(2000, 1, 1, 0, 0, 0, 86400) }.should raise_error(ArgumentError) end it "raises ArgumentError if the seconds argument is negative" do - lambda { Time.new(2000, 1, 1, 0, 0, -1) }.should raise_error(ArgumentError) + -> { Time.new(2000, 1, 1, 0, 0, -1) }.should raise_error(ArgumentError) end it "raises ArgumentError if the utc_offset argument is greater than or equal to 10e9" do - lambda { Time.new(2000, 1, 1, 0, 0, 0, 1000000000) }.should raise_error(ArgumentError) + -> { Time.new(2000, 1, 1, 0, 0, 0, 1000000000) }.should raise_error(ArgumentError) end end @@ -134,7 +134,7 @@ ruby_version_is "2.6" do time end - lambda { + -> { Time.new(2000, 1, 1, 12, 0, 0, zone).should be_kind_of(Time) }.should_not raise_error end @@ -145,7 +145,7 @@ ruby_version_is "2.6" do time end - lambda { + -> { Time.new(2000, 1, 1, 12, 0, 0, zone) }.should raise_error(TypeError, /can't convert \w+ into an exact number/) end @@ -156,7 +156,7 @@ ruby_version_is "2.6" do time end - lambda { + -> { Time.new(2000, 1, 1, 12, 0, 0, zone).should be_kind_of(Time) }.should_not raise_error end @@ -170,7 +170,7 @@ ruby_version_is "2.6" do Time.utc(t.year, t.mon, t.day, t.hour - 1, t.min, t.sec) end - lambda { + -> { Time.new(2000, 1, 1, 12, 0, 0, zone).should be_kind_of(Time) Time.new(2000, 1, 1, 12, 0, 0, zone).utc_offset.should == 60*60 }.should_not raise_error @@ -182,7 +182,7 @@ ruby_version_is "2.6" do Class.new(Time).utc(t.year, t.mon, t.day, t.hour - 1, t.min, t.sec) end - lambda { + -> { Time.new(2000, 1, 1, 12, 0, 0, zone).should be_kind_of(Time) Time.new(2000, 1, 1, 12, 0, 0, zone).utc_offset.should == 60*60 }.should_not raise_error @@ -194,7 +194,7 @@ ruby_version_is "2.6" do Struct.new(:to_i).new(time.to_i - 60*60) end - lambda { + -> { Time.new(2000, 1, 1, 12, 0, 0, zone).should be_kind_of(Time) Time.new(2000, 1, 1, 12, 0, 0, zone).utc_offset.should == 60*60 }.should_not raise_error @@ -220,7 +220,7 @@ ruby_version_is "2.6" do Time.utc(t.year, t.mon, t.day + 1, t.hour, t.min, t.sec) end - lambda { + -> { Time.new(2000, 1, 1, 12, 0, 0, zone) }.should raise_error(ArgumentError, "utc_offset out of range") end @@ -277,7 +277,7 @@ ruby_version_is "2.6" do zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60)) time = Time.new(2000, 1, 1, 12, 0, 0, zone) - lambda { + -> { Marshal.dump(time) }.should raise_error(NoMethodError, /undefined method `name' for/) end @@ -317,7 +317,7 @@ ruby_version_is "2.6" do it "does not call .find_timezone if passed any not string/numeric/timezone timezone argument" do [Object.new, [], {}, :"some zone"].each do |zone| - lambda { + -> { TimeSpecs::TimeWithFindTimezone.new(2000, 1, 1, 12, 0, 0, zone) }.should raise_error(TypeError, /can't convert \w+ into an exact number/) end diff --git a/spec/ruby/core/time/plus_spec.rb b/spec/ruby/core/time/plus_spec.rb index 91713b84b3..0a9984f180 100644 --- a/spec/ruby/core/time/plus_spec.rb +++ b/spec/ruby/core/time/plus_spec.rb @@ -17,9 +17,9 @@ describe "Time#+" do end it "raises a TypeError if given argument is a coercible String" do - lambda { Time.now + "1" }.should raise_error(TypeError) - lambda { Time.now + "0.1" }.should raise_error(TypeError) - lambda { Time.now + "1/3" }.should raise_error(TypeError) + -> { Time.now + "1" }.should raise_error(TypeError) + -> { Time.now + "0.1" }.should raise_error(TypeError) + -> { Time.now + "1/3" }.should raise_error(TypeError) end it "increments the time by the specified amount as rational numbers" do @@ -32,8 +32,8 @@ describe "Time#+" do end it "raises TypeError on argument that can't be coerced into Rational" do - lambda { Time.now + Object.new }.should raise_error(TypeError) - lambda { Time.now + "stuff" }.should raise_error(TypeError) + -> { Time.now + Object.new }.should raise_error(TypeError) + -> { Time.now + "stuff" }.should raise_error(TypeError) end it "returns a UTC time if self is UTC" do @@ -74,11 +74,11 @@ describe "Time#+" do end it "raises TypeError on Time argument" do - lambda { Time.now + Time.now }.should raise_error(TypeError) + -> { Time.now + Time.now }.should raise_error(TypeError) end it "raises TypeError on nil argument" do - lambda { Time.now + nil }.should raise_error(TypeError) + -> { Time.now + nil }.should raise_error(TypeError) end #see [ruby-dev:38446] diff --git a/spec/ruby/core/time/shared/gmtime.rb b/spec/ruby/core/time/shared/gmtime.rb index e684a1fd95..5ed64c2ab6 100644 --- a/spec/ruby/core/time/shared/gmtime.rb +++ b/spec/ruby/core/time/shared/gmtime.rb @@ -26,7 +26,7 @@ describe :time_gmtime, shared: true do with_timezone("CST", -6) do time = Time.now time.freeze - lambda { time.send(@method) }.should raise_error(RuntimeError) + -> { time.send(@method) }.should raise_error(RuntimeError) end end end diff --git a/spec/ruby/core/time/shared/time_params.rb b/spec/ruby/core/time/shared/time_params.rb index 39245116b0..63d0dbc120 100644 --- a/spec/ruby/core/time/shared/time_params.rb +++ b/spec/ruby/core/time/shared/time_params.rb @@ -30,7 +30,7 @@ describe :time_params, shared: true do end it "raises a TypeError if the year is nil" do - lambda { Time.send(@method, nil) }.should raise_error(TypeError) + -> { Time.send(@method, nil) }.should raise_error(TypeError) end it "accepts nil month, day, hour, minute, and second" do @@ -145,41 +145,41 @@ describe :time_params, shared: true do end it "raises an ArgumentError for out of range month" do - lambda { + -> { Time.send(@method, 2008, 13, 31, 23, 59, 59) }.should raise_error(ArgumentError) end it "raises an ArgumentError for out of range day" do - lambda { + -> { Time.send(@method, 2008, 12, 32, 23, 59, 59) }.should raise_error(ArgumentError) end it "raises an ArgumentError for out of range hour" do - lambda { + -> { Time.send(@method, 2008, 12, 31, 25, 59, 59) }.should raise_error(ArgumentError) end it "raises an ArgumentError for out of range minute" do - lambda { + -> { Time.send(@method, 2008, 12, 31, 23, 61, 59) }.should raise_error(ArgumentError) end it "raises an ArgumentError for out of range second" do - lambda { + -> { Time.send(@method, 2008, 12, 31, 23, 59, 61) }.should raise_error(ArgumentError) end it "raises ArgumentError when given 9 arguments" do - lambda { Time.send(@method, *[0]*9) }.should raise_error(ArgumentError) + -> { Time.send(@method, *[0]*9) }.should raise_error(ArgumentError) end it "raises ArgumentError when given 11 arguments" do - lambda { Time.send(@method, *[0]*11) }.should raise_error(ArgumentError) + -> { Time.send(@method, *[0]*11) }.should raise_error(ArgumentError) end it "returns subclass instances" do @@ -202,23 +202,23 @@ describe :time_params_10_arg, shared: true do end it "raises an ArgumentError for out of range values" do - lambda { + -> { Time.send(@method, 61, 59, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # sec - lambda { + -> { Time.send(@method, 59, 61, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # min - lambda { + -> { Time.send(@method, 59, 59, 25, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # hour - lambda { + -> { Time.send(@method, 59, 59, 23, 32, 12, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # day - lambda { + -> { Time.send(@method, 59, 59, 23, 31, 13, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # month end @@ -231,7 +231,7 @@ describe :time_params_microseconds, shared: true do end it "raises an ArgumentError for out of range microsecond" do - lambda { Time.send(@method, 2000, 1, 1, 20, 15, 1, 1000000) }.should raise_error(ArgumentError) + -> { Time.send(@method, 2000, 1, 1, 20, 15, 1, 1000000) }.should raise_error(ArgumentError) end it "handles fractional microseconds as a Float" do diff --git a/spec/ruby/core/time/strftime_spec.rb b/spec/ruby/core/time/strftime_spec.rb index 62f9272f32..1bd24b0538 100644 --- a/spec/ruby/core/time/strftime_spec.rb +++ b/spec/ruby/core/time/strftime_spec.rb @@ -6,14 +6,14 @@ require_relative '../../shared/time/strftime_for_time' describe "Time#strftime" do before :all do - @new_date = lambda { |y,m,d| Time.gm(y,m,d) } - @new_time = lambda { |*args| Time.gm(*args) } - @new_time_in_zone = lambda { |zone,offset,*args| + @new_date = -> y, m, d { Time.gm(y,m,d) } + @new_time = -> *args { Time.gm(*args) } + @new_time_in_zone = -> zone, offset, *args { with_timezone(zone, offset) do Time.new(*args) end } - @new_time_with_offset = lambda { |y,m,d,h,min,s,offset| + @new_time_with_offset = -> y, m, d, h, min, s, offset { Time.new(y,m,d,h,min,s,offset) } @@ -25,7 +25,7 @@ describe "Time#strftime" do # Differences with date it "requires an argument" do - lambda { @time.strftime }.should raise_error(ArgumentError) + -> { @time.strftime }.should raise_error(ArgumentError) end # %Z is zone name or empty for Time diff --git a/spec/ruby/core/time/succ_spec.rb b/spec/ruby/core/time/succ_spec.rb index 395ed67064..e68e64b0cc 100644 --- a/spec/ruby/core/time/succ_spec.rb +++ b/spec/ruby/core/time/succ_spec.rb @@ -21,7 +21,7 @@ describe "Time#succ" do end it "is obsolete" do - lambda { + -> { Time.at(100).succ }.should complain(/Time#succ is obsolete/) end diff --git a/spec/ruby/core/time/zone_spec.rb b/spec/ruby/core/time/zone_spec.rb index 45c9e852ea..907ccf9f4b 100644 --- a/spec/ruby/core/time/zone_spec.rb +++ b/spec/ruby/core/time/zone_spec.rb @@ -52,7 +52,7 @@ describe "Time#zone" do end it "doesn't raise errors for a Time with a fixed offset" do - lambda { + -> { Time.new(2001, 1, 1, 0, 0, 0, "+05:00").zone }.should_not raise_error end diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb index 6eeec1d5db..b0fe38c559 100644 --- a/spec/ruby/core/tracepoint/enable_spec.rb +++ b/spec/ruby/core/tracepoint/enable_spec.rb @@ -247,7 +247,7 @@ describe 'TracePoint#enable' do block = proc {} - lambda { + -> { trace.enable(target: block) do block.call # triggers :b_call and :b_return events end @@ -258,7 +258,7 @@ describe 'TracePoint#enable' do trace = TracePoint.new(:call) do |tp| end - lambda { + -> { trace.enable(target: Object.new) do end }.should raise_error(ArgumentError, /specified target is not supported/) @@ -269,7 +269,7 @@ describe 'TracePoint#enable' do trace = TracePoint.new(:b_call) do end - lambda { + -> { trace.enable(target: -> {}) do trace.enable(target: -> {}) do end @@ -281,7 +281,7 @@ describe 'TracePoint#enable' do trace = TracePoint.new(:b_call) do end - lambda { + -> { trace.enable do trace.enable(target: -> {}) do end @@ -293,7 +293,7 @@ describe 'TracePoint#enable' do trace = TracePoint.new(:b_call) do end - lambda { + -> { trace.enable(target: -> {}) do trace.enable do end @@ -305,7 +305,7 @@ describe 'TracePoint#enable' do trace = TracePoint.new(:b_call) do end - lambda { + -> { trace.enable(target: -> {}) do trace.disable do end @@ -404,7 +404,7 @@ describe 'TracePoint#enable' do trace = TracePoint.new(:line) do |tp| end - lambda { + -> { trace.enable(target_line: 67) do end }.should raise_error(ArgumentError, /only target_line is specified/) @@ -422,7 +422,7 @@ describe 'TracePoint#enable' do _, lineno = target.source_location target_line = lineno + 2 - lambda { + -> { trace.enable(target_line: target_line, target: target) do end }.should raise_error(ArgumentError, /target_line is specified, but line event is not specified/) @@ -432,7 +432,7 @@ describe 'TracePoint#enable' do trace = TracePoint.new(:line) do |tp| end - lambda { + -> { trace.enable(target_line: 1, target: -> { }) do end }.should raise_error(ArgumentError, /can not enable any hooks/) @@ -442,7 +442,7 @@ describe 'TracePoint#enable' do trace = TracePoint.new(:line) do |tp| end - lambda { + -> { trace.enable(target_line: Object.new, target: -> { }) do end }.should raise_error(TypeError, /no implicit conversion of \w+? into Integer/) @@ -452,7 +452,7 @@ describe 'TracePoint#enable' do trace = TracePoint.new(:line) do |tp| end - lambda { + -> { trace.enable(target_line: -2, target: -> { }) do end }.should raise_error(ArgumentError, /can not enable any hooks/) diff --git a/spec/ruby/core/tracepoint/parameters_spec.rb b/spec/ruby/core/tracepoint/parameters_spec.rb index 550b9572c0..f901c184f4 100644 --- a/spec/ruby/core/tracepoint/parameters_spec.rb +++ b/spec/ruby/core/tracepoint/parameters_spec.rb @@ -12,7 +12,7 @@ ruby_version_is "2.6" do end it 'returns the parameters of lambda block' do - f = lambda {|x, y, z| } + f = -> x, y, z { } parameters = nil TracePoint.new(:b_call) {|tp| parameters = tp.parameters }.enable do f.call(1, 2, 3) diff --git a/spec/ruby/core/true/trueclass_spec.rb b/spec/ruby/core/true/trueclass_spec.rb index 8f3c311548..02af649d09 100644 --- a/spec/ruby/core/true/trueclass_spec.rb +++ b/spec/ruby/core/true/trueclass_spec.rb @@ -2,13 +2,13 @@ require_relative '../../spec_helper' describe "TrueClass" do it ".allocate raises a TypeError" do - lambda do + -> do TrueClass.allocate end.should raise_error(TypeError) end it ".new is undefined" do - lambda do + -> do TrueClass.new end.should raise_error(NoMethodError) end diff --git a/spec/ruby/core/unboundmethod/bind_spec.rb b/spec/ruby/core/unboundmethod/bind_spec.rb index 328c356906..03aaa22e74 100644 --- a/spec/ruby/core/unboundmethod/bind_spec.rb +++ b/spec/ruby/core/unboundmethod/bind_spec.rb @@ -10,7 +10,7 @@ describe "UnboundMethod#bind" do end it "raises TypeError if object is not kind_of? the Module the method defined in" do - lambda { @normal_um.bind(UnboundMethodSpecs::B.new) }.should raise_error(TypeError) + -> { @normal_um.bind(UnboundMethodSpecs::B.new) }.should raise_error(TypeError) end it "returns Method for any object that is kind_of? the Module method was extracted from" do @@ -21,11 +21,21 @@ describe "UnboundMethod#bind" do UnboundMethodSpecs::Mod.instance_method(:from_mod).bind(Object.new).should be_kind_of(Method) end - it "returns Method returned for obj is equal to one directly returned by obj.method" do + it "the returned Method is equal to the one directly returned by obj.method" do obj = UnboundMethodSpecs::Methods.new @normal_um.bind(obj).should == obj.method(:foo) end + it "returns Method for any object kind_of? the Module the method is defined in" do + @parent_um.bind(UnboundMethodSpecs::Child1.new).should be_kind_of(Method) + @child1_um.bind(UnboundMethodSpecs::Parent.new).should be_kind_of(Method) + @child2_um.bind(UnboundMethodSpecs::Child1.new).should be_kind_of(Method) + end + + it "allows binding a Kernel method retrieved from Object on BasicObject" do + Object.instance_method(:instance_of?).bind(BasicObject.new).call(BasicObject).should == true + end + it "returns a callable method" do obj = UnboundMethodSpecs::Methods.new @normal_um.bind(obj).call.should == obj.foo @@ -46,6 +56,6 @@ describe "UnboundMethod#bind" do end end um = p.method(:singleton_method).unbind - lambda{ um.bind(other) }.should raise_error(TypeError) + ->{ um.bind(other) }.should raise_error(TypeError) end end |