Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d929857ffb2a
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f7ba17ee50ce
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Mar 7, 2015

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c303425 View commit details
  2. Merge pull request #3346 from jsyeo/max-by-optional-arg-spec

    Add specs for Enumerable#max_by optional arg
    Yorick Peterse committed Mar 7, 2015
    Copy the full SHA
    f7ba17e View commit details
Showing with 35 additions and 0 deletions.
  1. +32 −0 spec/ruby/core/enumerable/max_by_spec.rb
  2. +3 −0 spec/tags/ruby/core/enumerable/max_by_tags.txt
32 changes: 32 additions & 0 deletions spec/ruby/core/enumerable/max_by_spec.rb
Original file line number Diff line number Diff line change
@@ -37,4 +37,36 @@
multi = EnumerableSpecs::YieldsMulti.new
multi.max_by {|e| e.size}.should == [6, 7, 8, 9]
end

context "when called with an argument n" do
before :each do
@enum = EnumerableSpecs::Numerous.new(101, 55, 1, 20, 33, 500, 60)
end

context "without a block" do
it "returns an enumerator" do
@enum.max_by(2).should be_an_instance_of(enumerator_class)
end
end

context "with a block" do
it "returns an array containing the maximum n elements based on the block's value" do
result = @enum.max_by(3) { |i| i.to_s }
result.should == [60, 55, 500]
end

context "on a enumerable of length x where x < n" do
it "returns an array containing the maximum n elements of length n" do
result = @enum.max_by(500) { |i| i.to_s }
result.length.should == 7
end
end

context "when n is negative" do
it "raises an ArgumentError" do
lambda { @enum.max_by(-1) { |i| i.to_s } }.should raise_error(ArgumentError)
end
end
end
end
end
3 changes: 3 additions & 0 deletions spec/tags/ruby/core/enumerable/max_by_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Enumerable#max_by when called with an argument n without a block returns an enumerator
fails:Enumerable#max_by when called with an argument n with a block returns an array containing the maximum n elements based on the block's value
fails:Enumerable#max_by when called with an argument n with a block on a enumerable of length x where x < n returns an array containing the maximum n elements of length n