aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/enumerator/yielder
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/enumerator/yielder')
-rw-r--r--spec/ruby/core/enumerator/yielder/append_spec.rb35
-rw-r--r--spec/ruby/core/enumerator/yielder/initialize_spec.rb18
-rw-r--r--spec/ruby/core/enumerator/yielder/yield_spec.rb16
3 files changed, 69 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerator/yielder/append_spec.rb b/spec/ruby/core/enumerator/yielder/append_spec.rb
new file mode 100644
index 0000000000..d2313b01f4
--- /dev/null
+++ b/spec/ruby/core/enumerator/yielder/append_spec.rb
@@ -0,0 +1,35 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+
+describe "Enumerator::Yielder#<<" do
+ # TODO: There's some common behavior between yield and <<; move to a shared spec
+ it "yields the value to the block" do
+ ary = []
+ y = Enumerator::Yielder.new {|x| ary << x}
+ y << 1
+
+ ary.should == [1]
+ end
+
+ it "doesn't double-wrap Arrays" do
+ yields = []
+ y = Enumerator::Yielder.new {|args| yields << args }
+ y << [1]
+ yields.should == [[1]]
+ end
+
+ it "returns self" do
+ y = Enumerator::Yielder.new {|x| x + 1}
+ (y << 1).should equal(y)
+ end
+
+ it "requires multiple arguments" do
+ Enumerator::Yielder.instance_method(:<<).arity.should < 0
+ end
+
+ it "yields with passed arguments" do
+ yields = []
+ y = Enumerator::Yielder.new {|*args| yields << args }
+ y.<<(1, 2)
+ yields.should == [[1, 2]]
+ end
+end
diff --git a/spec/ruby/core/enumerator/yielder/initialize_spec.rb b/spec/ruby/core/enumerator/yielder/initialize_spec.rb
new file mode 100644
index 0000000000..095b6a64c6
--- /dev/null
+++ b/spec/ruby/core/enumerator/yielder/initialize_spec.rb
@@ -0,0 +1,18 @@
+# -*- encoding: us-ascii -*-
+
+require File.expand_path('../../../../spec_helper', __FILE__)
+
+describe "Enumerator::Yielder#initialize" do
+ before :each do
+ @class = Enumerator::Yielder
+ @uninitialized = @class.allocate
+ end
+
+ it "is a private method" do
+ @class.should have_private_instance_method(:initialize, false)
+ end
+
+ it "returns self when given a block" do
+ @uninitialized.send(:initialize) {}.should equal(@uninitialized)
+ end
+end
diff --git a/spec/ruby/core/enumerator/yielder/yield_spec.rb b/spec/ruby/core/enumerator/yielder/yield_spec.rb
new file mode 100644
index 0000000000..be904afef1
--- /dev/null
+++ b/spec/ruby/core/enumerator/yielder/yield_spec.rb
@@ -0,0 +1,16 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+
+describe "Enumerator::Yielder#yield" do
+ it "yields the value to the block" do
+ ary = []
+ y = Enumerator::Yielder.new {|x| ary << x}
+ y.yield 1
+
+ ary.should == [1]
+ end
+
+ it "returns the result of the block for the given value" do
+ y = Enumerator::Yielder.new {|x| x + 1}
+ y.yield(1).should == 2
+ end
+end