-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
230 changed files
with
1,887 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'shared/iterable_and_tolerating_size_increasing' | ||
|
||
describe "Array#all?" do | ||
@value_to_return = -> _ { true } | ||
it_behaves_like :array_iterable_and_tolerating_size_increasing, :all? | ||
|
||
it "ignores the block if there is an argument" do | ||
-> { | ||
['bar', 'foobar'].all?(/bar/) { false }.should == true | ||
}.should complain(/given block not used/) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,66 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'fixtures/classes' | ||
|
||
describe 'Array#intersect?' do | ||
ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/15198 | ||
describe 'when at least one element in two Arrays is the same' do | ||
it 'returns true' do | ||
[1, 2].intersect?([2, 3]).should == true | ||
[1, 2].intersect?([2, 3, 4]).should == true | ||
[2, 3, 4].intersect?([1, 2]).should == true | ||
end | ||
end | ||
|
||
describe 'when there are no elements in common between two Arrays' do | ||
it 'returns false' do | ||
[1, 2].intersect?([3, 4]).should == false | ||
[0, 1, 2].intersect?([3, 4]).should == false | ||
[3, 4].intersect?([0, 1, 2]).should == false | ||
[3, 4].intersect?([]).should == false | ||
[].intersect?([0, 1, 2]).should == false | ||
end | ||
end | ||
|
||
it "tries to convert the passed argument to an Array using #to_ary" do | ||
obj = mock('[1,2,3]') | ||
obj.should_receive(:to_ary).and_return([1, 2, 3]) | ||
|
||
[1, 2].intersect?(obj).should == true | ||
end | ||
|
||
it "determines equivalence between elements in the sense of eql?" do | ||
obj1 = mock('1') | ||
obj2 = mock('2') | ||
obj1.stub!(:hash).and_return(0) | ||
obj2.stub!(:hash).and_return(0) | ||
obj1.stub!(:eql?).and_return(true) | ||
obj2.stub!(:eql?).and_return(true) | ||
|
||
[obj1].intersect?([obj2]).should == true | ||
|
||
obj1 = mock('3') | ||
obj2 = mock('4') | ||
obj1.stub!(:hash).and_return(0) | ||
obj2.stub!(:hash).and_return(0) | ||
obj1.stub!(:eql?).and_return(false) | ||
obj2.stub!(:eql?).and_return(false) | ||
|
||
[obj1].intersect?([obj2]).should == false | ||
end | ||
|
||
it "does not call to_ary on array subclasses" do | ||
[5, 6].intersect?(ArraySpecs::ToAryArray[1, 2, 5, 6]).should == true | ||
end | ||
|
||
it "properly handles an identical item even when its #eql? isn't reflexive" do | ||
x = mock('x') | ||
x.stub!(:hash).and_return(42) | ||
x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI. | ||
|
||
[x].intersect?([x]).should == true | ||
end | ||
|
||
it "has semantic of !(a & b).empty?" do | ||
[].intersect?([]).should == false | ||
[nil].intersect?([nil]).should == true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'shared/iterable_and_tolerating_size_increasing' | ||
|
||
describe "Array#none?" do | ||
@value_to_return = -> _ { false } | ||
it_behaves_like :array_iterable_and_tolerating_size_increasing, :none? | ||
|
||
it "ignores the block if there is an argument" do | ||
-> { | ||
['bar', 'foobar'].none?(/baz/) { true }.should == true | ||
}.should complain(/given block not used/) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'shared/iterable_and_tolerating_size_increasing' | ||
|
||
describe "Array#one?" do | ||
@value_to_return = -> _ { false } | ||
it_behaves_like :array_iterable_and_tolerating_size_increasing, :one? | ||
|
||
it "ignores the block if there is an argument" do | ||
-> { | ||
['bar', 'foobar'].one?(/foo/) { false }.should == true | ||
}.should complain(/given block not used/) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.