diff --git a/core/enumerable/compact_spec.rb b/core/enumerable/compact_spec.rb new file mode 100644 index 0000000000..86e95dce08 --- /dev/null +++ b/core/enumerable/compact_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is '3.1' do + describe "Enumerable#compact" do + it 'returns array without nil elements' do + arr = EnumerableSpecs::Numerous.new(nil, 1, 2, nil, true) + arr.compact.should == [1, 2, true] + end + end +end diff --git a/core/enumerator/lazy/lazy_spec.rb b/core/enumerator/lazy/lazy_spec.rb index cde9b31066..683dfb81d7 100644 --- a/core/enumerator/lazy/lazy_spec.rb +++ b/core/enumerator/lazy/lazy_spec.rb @@ -16,6 +16,10 @@ ] lazy_methods += [:chunk_while, :uniq] + ruby_version_is '3.1' do + lazy_methods += [:compact] + end + Enumerator::Lazy.instance_methods(false).should include(*lazy_methods) end end @@ -26,3 +30,13 @@ lazy.lazy.should equal(lazy) end end + +ruby_version_is '3.1' do + describe "Enumerator::Lazy#compact" do + it 'returns array without nil elements' do + arr = [1, nil, 3, false, 5].to_enum.lazy.compact + arr.should be_an_instance_of(Enumerator::Lazy) + arr.force.should == [1, 3, false, 5] + end + end +end