diff options
Diffstat (limited to 'spec/ruby/optional/capi/enumerator_spec.rb')
| -rw-r--r-- | spec/ruby/optional/capi/enumerator_spec.rb | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/spec/ruby/optional/capi/enumerator_spec.rb b/spec/ruby/optional/capi/enumerator_spec.rb index 44634f73a1..9ed68c9063 100644 --- a/spec/ruby/optional/capi/enumerator_spec.rb +++ b/spec/ruby/optional/capi/enumerator_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../spec_helper', __FILE__) +require_relative 'spec_helper' load_extension("enumerator") @@ -36,4 +36,31 @@ describe "C-API Enumerator function" do enumerator.each {} end end + + describe "rb_enumeratorize_with_size" do + + it "enumerates the given object" do + enumerator = @s.rb_enumeratorize_with_size(@enumerable, :each) + enumerated = [] + enumerator.each { |i| enumerated << i } + enumerated.should == @enumerable + end + + it "uses the given method for enumeration" do + enumerator = @s.rb_enumeratorize_with_size(@enumerable, :awesome_each) + @enumerable.should_receive(:awesome_each) + enumerator.each {} + end + + it "passes the given arguments to the enumeration method" do + enumerator = @s.rb_enumeratorize_with_size(@enumerable, :each, :arg1, :arg2) + @enumerable.should_receive(:each).with(:arg1, :arg2) + enumerator.each {} + end + + it "uses the size function to report the size" do + enumerator = @s.rb_enumeratorize_with_size(@enumerable, :each, :arg1, :arg2) + enumerator.size.should == 7 + end + end end |
