diff options
Diffstat (limited to 'spec/ruby/core/enumerable/one_spec.rb')
-rw-r--r-- | spec/ruby/core/enumerable/one_spec.rb | 123 |
1 files changed, 56 insertions, 67 deletions
diff --git a/spec/ruby/core/enumerable/one_spec.rb b/spec/ruby/core/enumerable/one_spec.rb index 2ae8b3efa4..46a10d68eb 100644 --- a/spec/ruby/core/enumerable/one_spec.rb +++ b/spec/ruby/core/enumerable/one_spec.rb @@ -20,15 +20,6 @@ describe "Enumerable#one?" do -> { {}.one?(1, 2, 3) }.should raise_error(ArgumentError) end - ruby_version_is ""..."2.5" do - it "raises an ArgumentError when any arguments provided" do - -> { @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 -> { EnumerableSpecs::ThrowingEach.new.one? @@ -93,77 +84,75 @@ describe "Enumerable#one?" do 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 == 1 } - @enum1.one?(pattern).should == true - pattern.yielded.should == [[0], [1], [2], [-1]] - end + describe 'when given a pattern argument' do + it "calls `===` on the pattern the return value " do + pattern = EnumerableSpecs::Pattern.new { |x| x == 1 } + @enum1.one?(pattern).should == true + pattern.yielded.should == [[0], [1], [2], [-1]] + end - # may raise an exception in future versions - ruby_version_is ""..."2.6" do - it "ignores block" do - @enum2.one?(NilClass) { raise }.should == true - [1, 2, nil].one?(NilClass) { raise }.should == true - {a: 1}.one?(Array) { raise }.should == true - end + # may raise an exception in future versions + ruby_version_is ""..."2.6" do + it "ignores block" do + @enum2.one?(NilClass) { raise }.should == true + [1, 2, nil].one?(NilClass) { raise }.should == true + {a: 1}.one?(Array) { raise }.should == true end + end - it "always returns false on empty enumeration" do - @empty.one?(Integer).should == false - [].one?(Integer).should == false - {}.one?(NilClass).should == false - end + it "always returns false on empty enumeration" do + @empty.one?(Integer).should == false + [].one?(Integer).should == false + {}.one?(NilClass).should == false + end - it "does not hide exceptions out of #each" do - -> { - EnumerableSpecs::ThrowingEach.new.one?(Integer) - }.should raise_error(RuntimeError) - end + it "does not hide exceptions out of #each" do + -> { + EnumerableSpecs::ThrowingEach.new.one?(Integer) + }.should raise_error(RuntimeError) + end - it "returns true if the pattern returns a truthy value only once" do - @enum2.one?(NilClass).should == true - pattern = EnumerableSpecs::Pattern.new { |x| x == 2 } - @enum1.one?(pattern).should == true + it "returns true if the pattern returns a truthy value only once" do + @enum2.one?(NilClass).should == true + pattern = EnumerableSpecs::Pattern.new { |x| x == 2 } + @enum1.one?(pattern).should == true - [1, 2, 42, 3].one?(pattern).should == true + [1, 2, 42, 3].one?(pattern).should == true - pattern = EnumerableSpecs::Pattern.new { |x| x == [:b, 2] } - {a: 1, b: 2}.one?(pattern).should == true - end + pattern = EnumerableSpecs::Pattern.new { |x| x == [:b, 2] } + {a: 1, b: 2}.one?(pattern).should == true + end - it "returns false if the pattern returns a truthy value more than once" do - pattern = EnumerableSpecs::Pattern.new { |x| !x } - @enum2.one?(pattern).should == false - pattern.yielded.should == [[nil], [false]] + it "returns false if the pattern returns a truthy value more than once" do + pattern = EnumerableSpecs::Pattern.new { |x| !x } + @enum2.one?(pattern).should == false + pattern.yielded.should == [[nil], [false]] - [1, 2, 3].one?(Integer).should == false - {a: 1, b: 2}.one?(Array).should == false - end + [1, 2, 3].one?(Integer).should == false + {a: 1, b: 2}.one?(Array).should == false + end - it "returns false if the pattern never returns a truthy value" do - pattern = EnumerableSpecs::Pattern.new { |x| nil } - @enum1.one?(pattern).should == false - pattern.yielded.should == [[0], [1], [2], [-1]] + it "returns false if the pattern never returns a truthy value" do + pattern = EnumerableSpecs::Pattern.new { |x| nil } + @enum1.one?(pattern).should == false + pattern.yielded.should == [[0], [1], [2], [-1]] - [1, 2, 3].one?(pattern).should == false - {a: 1}.one?(pattern).should == false - end + [1, 2, 3].one?(pattern).should == false + {a: 1}.one?(pattern).should == false + end - it "does not hide exceptions out of pattern#===" do - pattern = EnumerableSpecs::Pattern.new { raise "from pattern" } - -> { - @enum.one?(pattern) - }.should raise_error(RuntimeError) - end + it "does not hide exceptions out of pattern#===" do + pattern = EnumerableSpecs::Pattern.new { raise "from pattern" } + -> { + @enum.one?(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.one?(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.one?(pattern).should == false + pattern.yielded.should == [[[1, 2]], [[3, 4, 5]], [[6, 7, 8, 9]]] end end end |