Skip to content
This repository

Added spec for Enumerable#count delegating to #size #129

Merged
merged 0 commits into from 8 months ago

3 participants

Iain Beeston Dirkjan Bussink NARUSE, Yui
Iain Beeston

According to the ruby documentation, Enumerable#count() is supposed to delegate to #size if #size is defined (see here), and fall back to #each if not. This isn't the behaviour in MRI (1.8 or 1.9) so far as I can tell.

core/enumerable/count_spec.rb
... ...
@@ -8,6 +8,11 @@
8 8
       @numerous = EnumerableSpecs::Numerous.new(*@elements)
9 9
     end
10 10
 
  11
+    it "delegates to size if size is defined" do
  12
+      sized_numerous = EnumerableSpecs::SizedNumerous.new(-1, @elements)
  13
+      @numerous.count.should == -1
1
Dirkjan Bussink Collaborator

Not really sure why first sized_numerous is constructed and then @numerous is used.

How about something like this?

@numerous.should_receive(:size).and_return(5)
@numerous.count.should == 5

This way also an additional fixture isn't necessary and it explicitly describes the behavior of count calling size if it exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Iain Beeston

@dbussink I've incorporated your feedback. Could you please take another look at this pull request?

Iain Beeston

It seems that the core ruby team have changed this behaviour on 2.0, so this behaviour is no longer expected. I've updated this so that it only checks on ruby versions before 2.0

NARUSE, Yui nurse merged commit 3d211b2 into from August 14, 2013
NARUSE, Yui nurse closed this August 14, 2013
Iain Beeston

@nurse I just realise this pull request no longer had any commits, because I rebased the branch it was on (it was a very old pull request). Should I reopen the pull request with the correct commits?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Sorry, commit information is not available for this pull request.

This page is out of date. Refresh to see the latest.

Showing 0 changed files with 0 additions and 0 deletions. Show diff stats Hide diff stats

Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.