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: ed98c0538edf
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 12092a9ed7d2
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Mar 5, 2015

  1. Copy the full SHA
    4c59829 View commit details
  2. Copy the full SHA
    707f32c View commit details
  3. Merge pull request #3342 from jsyeo/min-by-optional-arg-spec

    Add specs for Enumberable#min_by optional args 🐥
    Yorick Peterse committed Mar 5, 2015
    Copy the full SHA
    12092a9 View commit details
Showing with 37 additions and 3 deletions.
  1. +34 −3 spec/ruby/core/enumerable/min_by_spec.rb
  2. +3 −0 spec/tags/ruby/core/enumerable/min_by_tags.txt
37 changes: 34 additions & 3 deletions spec/ruby/core/enumerable/min_by_spec.rb
Original file line number Diff line number Diff line change
@@ -10,8 +10,7 @@
EnumerableSpecs::Empty.new.min_by {|o| o.nonesuch }.should == nil
end


it "returns the object for whom the value returned by block is the largest" do
it "returns the object for whom the value returned by block is the smallest" do
EnumerableSpecs::Numerous.new(*%w[3 2 1]).min_by {|obj| obj.to_i }.should == '1'
EnumerableSpecs::Numerous.new(*%w[five three]).min_by {|obj| obj.length }.should == 'five'
end
@@ -28,7 +27,7 @@
EnumerableSpecs::Numerous.new(a, b, c).min_by {|obj| obj }.should == c
end

it "is able to return the maximum for enums that contain nils" do
it "is able to return the minimum for enums that contain nils" do
enum = EnumerableSpecs::Numerous.new(nil, nil, true)
enum.min_by {|o| o.nil? ? 0 : 1 }.should == nil
enum.min_by {|o| o.nil? ? 1 : 0 }.should == true
@@ -38,4 +37,36 @@
multi = EnumerableSpecs::YieldsMulti.new
multi.min_by {|e| e.size}.should == [1, 2]
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.min_by(2).should be_an_instance_of(enumerator_class)
end
end

context "with a block" do
it "returns an array containing the minimum n elements based on the block's value" do
result = @enum.min_by(3) { |i| i.to_s }
result.should == [1, 101, 20]
end

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

context "when n is negative" do
it "raises an Argument error" do
lambda { @enum.min_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/min_by_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Enumerable#min_by when called with an argument n without a block returns an enumerator
fails:Enumerable#min_by when called with an argument n with a block returns an array containing the minimum n elements based on the block's value
fails:Enumerable#min_by when called with an argument n with a block on a enumerable of length x where x < n returns an array containing the minimum n elements of length n