1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/core/enumerable/shared/include.rb
eregon 1d15d5f080 Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-20 20:18:52 +00:00

34 lines
1.5 KiB
Ruby

describe :enumerable_include, shared: true do
it "returns true if any element == argument for numbers" do
class EnumerableSpecIncludeP; def ==(obj) obj == 5; end; end
elements = (0..5).to_a
EnumerableSpecs::Numerous.new(*elements).send(@method,5).should == true
EnumerableSpecs::Numerous.new(*elements).send(@method,10).should == false
EnumerableSpecs::Numerous.new(*elements).send(@method,EnumerableSpecIncludeP.new).should == true
end
it "returns true if any element == argument for other objects" do
class EnumerableSpecIncludeP11; def ==(obj); obj == '11'; end; end
elements = ('0'..'5').to_a + [EnumerableSpecIncludeP11.new]
EnumerableSpecs::Numerous.new(*elements).send(@method,'5').should == true
EnumerableSpecs::Numerous.new(*elements).send(@method,'10').should == false
EnumerableSpecs::Numerous.new(*elements).send(@method,EnumerableSpecIncludeP11.new).should == true
EnumerableSpecs::Numerous.new(*elements).send(@method,'11').should == true
end
it "returns true if any member of enum equals obj when == compare different classes (legacy rubycon)" do
# equality is tested with ==
EnumerableSpecs::Numerous.new(2,4,6,8,10).send(@method, 2.0).should == true
EnumerableSpecs::Numerous.new(2,4,[6,8],10).send(@method, [6, 8]).should == true
EnumerableSpecs::Numerous.new(2,4,[6,8],10).send(@method, [6.0, 8.0]).should == true
end
it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
multi.send(@method, [1,2]).should be_true
end
end