diff options
Diffstat (limited to 'spec/ruby/core/enumerable/any_spec.rb')
-rw-r--r-- | spec/ruby/core/enumerable/any_spec.rb | 109 |
1 files changed, 49 insertions, 60 deletions
diff --git a/spec/ruby/core/enumerable/any_spec.rb b/spec/ruby/core/enumerable/any_spec.rb index c800fe2d4b..0202506d10 100644 --- a/spec/ruby/core/enumerable/any_spec.rb +++ b/spec/ruby/core/enumerable/any_spec.rb @@ -26,15 +26,6 @@ describe "Enumerable#any?" do -> { {}.any?(1, 2, 3) }.should raise_error(ArgumentError) end - ruby_version_is ""..."2.5" do - it "raises an ArgumentError when any arguments provided" do - -> { @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 -> { EnumerableSpecs::ThrowingEach.new.any? @@ -147,68 +138,66 @@ describe "Enumerable#any?" do end end - ruby_version_is "2.5" do - describe 'when given a pattern argument' do - it "calls `===` on the pattern the return value " do - pattern = EnumerableSpecs::Pattern.new { |x| x == 2 } - @enum1.any?(pattern).should == true - pattern.yielded.should == [[0], [1], [2]] - end + describe 'when given a pattern argument' do + it "calls `===` on the pattern the return value " do + pattern = EnumerableSpecs::Pattern.new { |x| x == 2 } + @enum1.any?(pattern).should == true + pattern.yielded.should == [[0], [1], [2]] + end - # may raise an exception in future versions - ruby_version_is ""..."2.6" do - it "ignores block" do - @enum2.any?(NilClass) { raise }.should == true - [1, 2, nil].any?(NilClass) { raise }.should == true - {a: 1}.any?(Array) { raise }.should == true - end + # may raise an exception in future versions + ruby_version_is ""..."2.6" do + it "ignores block" do + @enum2.any?(NilClass) { raise }.should == true + [1, 2, nil].any?(NilClass) { raise }.should == true + {a: 1}.any?(Array) { raise }.should == true end + end - it "always returns false on empty enumeration" do - @empty.any?(Integer).should == false - [].any?(Integer).should == false - {}.any?(NilClass).should == false - end + it "always returns false on empty enumeration" do + @empty.any?(Integer).should == false + [].any?(Integer).should == false + {}.any?(NilClass).should == false + end - it "does not hide exceptions out of #each" do - -> { - EnumerableSpecs::ThrowingEach.new.any?(Integer) - }.should raise_error(RuntimeError) - end + it "does not hide exceptions out of #each" do + -> { + EnumerableSpecs::ThrowingEach.new.any?(Integer) + }.should raise_error(RuntimeError) + end - it "returns true if the pattern ever returns a truthy value" do - @enum2.any?(NilClass).should == true - pattern = EnumerableSpecs::Pattern.new { |x| 42 } - @enum.any?(pattern).should == true + it "returns true if the pattern ever returns a truthy value" do + @enum2.any?(NilClass).should == true + pattern = EnumerableSpecs::Pattern.new { |x| 42 } + @enum.any?(pattern).should == true - [1, 42, 3].any?(pattern).should == true + [1, 42, 3].any?(pattern).should == true - pattern = EnumerableSpecs::Pattern.new { |x| x == [:b, 2] } - {a: 1, b: 2}.any?(pattern).should == true - end + pattern = EnumerableSpecs::Pattern.new { |x| x == [:b, 2] } + {a: 1, b: 2}.any?(pattern).should == true + end - it "returns false if the block never returns other than false or nil" do - pattern = EnumerableSpecs::Pattern.new { |x| nil } - @enum1.any?(pattern).should == false - pattern.yielded.should == [[0], [1], [2], [-1]] + it "returns false if the block never returns other than false or nil" do + pattern = EnumerableSpecs::Pattern.new { |x| nil } + @enum1.any?(pattern).should == false + pattern.yielded.should == [[0], [1], [2], [-1]] - [1, 2, 3].any?(pattern).should == false - {a: 1}.any?(pattern).should == false - end + [1, 2, 3].any?(pattern).should == false + {a: 1}.any?(pattern).should == false + end - it "does not hide exceptions out of pattern#===" do - pattern = EnumerableSpecs::Pattern.new { raise "from pattern" } - -> { - @enum.any?(pattern) - }.should raise_error(RuntimeError) - end + it "does not hide exceptions out of pattern#===" do + pattern = EnumerableSpecs::Pattern.new { raise "from pattern" } + -> { + @enum.any?(pattern) + }.should raise_error(RuntimeError) + end - it "calls the pattern with gathered array when yielded with multiple arguments" do - multi = EnumerableSpecs::YieldsMulti.new - pattern = EnumerableSpecs::Pattern.new { false } - multi.any?(pattern).should == false - pattern.yielded.should == [[[1, 2]], [[3, 4, 5]], [[6, 7, 8, 9]]] - end + it "calls the pattern with gathered array when yielded with multiple arguments" do + multi = EnumerableSpecs::YieldsMulti.new + pattern = EnumerableSpecs::Pattern.new { false } + multi.any?(pattern).should == false + pattern.yielded.should == [[[1, 2]], [[3, 4, 5]], [[6, 7, 8, 9]]] end end end |