diff options
Diffstat (limited to 'spec/ruby/core/enumerator/each_spec.rb')
| -rw-r--r-- | spec/ruby/core/enumerator/each_spec.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/spec/ruby/core/enumerator/each_spec.rb b/spec/ruby/core/enumerator/each_spec.rb index 3af16e5587..03be53fe05 100644 --- a/spec/ruby/core/enumerator/each_spec.rb +++ b/spec/ruby/core/enumerator/each_spec.rb @@ -51,17 +51,17 @@ describe "Enumerator#each" do enum = Object.new.to_enum -> do enum.each { |e| e } - end.should raise_error(NoMethodError) + end.should.raise(NoMethodError) end it "returns self if not given arguments and not given a block" do - @enum_with_arguments.each.should equal(@enum_with_arguments) + @enum_with_arguments.each.should.equal?(@enum_with_arguments) - @enum_with_yielder.each.should equal(@enum_with_yielder) + @enum_with_yielder.each.should.equal?(@enum_with_yielder) end it "returns the same value from receiver.each if block is given" do - @enum_with_arguments.each {}.should equal(:method_returned) + @enum_with_arguments.each {}.should.equal?(:method_returned) end it "passes given arguments at initialized to receiver.each" do @@ -78,12 +78,27 @@ describe "Enumerator#each" do end it "returns the same value from receiver.each if block and arguments are given" do - @enum_with_arguments.each(:each1, :each2) {}.should equal(:method_returned) + @enum_with_arguments.each(:each1, :each2) {}.should.equal?(:method_returned) end it "returns new Enumerator if given arguments but not given a block" do ret = @enum_with_arguments.each 1 - ret.should be_an_instance_of(Enumerator) - ret.should_not equal(@enum_with_arguments) + ret.should.instance_of?(Enumerator) + ret.should_not.equal?(@enum_with_arguments) + end + + it "does not destructure yielded array values when chaining each.map" do + result = [[[1]]].each.map { |a, b| [a, b] } + result.should == [[[1], nil]] + end + + it "preserves array values yielded from the enumerator" do + result = [[1, 2]].each.map { |a| a } + result.should == [[1, 2]] + end + + it "allows destructuring to occur in the block, not the enumerator" do + result = [[1, 2]].each.map { |a, b| a } + result.should == [1] end end |
