[macruby-changes] [3098] MacRuby/trunk/spec/macruby/core/gcd/group_spec.rb

source_changes at macosforge.org source_changes at macosforge.org
Thu Dec 10 15:26:48 PST 2009


Revision: 3098
          http://trac.macosforge.org/projects/ruby/changeset/3098
Author:   ernest.prabhakar at gmail.com
Date:     2009-12-10 15:26:45 -0800 (Thu, 10 Dec 2009)
Log Message:
-----------
Fixed errors in Dispatch::Group spec, still have failures

Modified Paths:
--------------
    MacRuby/trunk/spec/macruby/core/gcd/group_spec.rb

Modified: MacRuby/trunk/spec/macruby/core/gcd/group_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd/group_spec.rb	2009-12-10 22:57:37 UTC (rev 3097)
+++ MacRuby/trunk/spec/macruby/core/gcd/group_spec.rb	2009-12-10 23:26:45 UTC (rev 3098)
@@ -2,15 +2,80 @@
 
 if MACOSX_VERSION >= 10.6  
   describe "Dispatch::Group" do
+    before :each do
+      @q = Dispatch::Queue.new('org.macruby.gcd_spec.group')
+      @g = Dispatch::Group.new
+      @i = 0
+    end
+    
     it "returns an instance of Group" do
-      @group = Dispatch::Group.new
-      @group.should be_kind_of(Dispatch::Group)
+      @g.should be_kind_of(Dispatch::Group)
     end
     
-    describe "#notify" do
+    it "is passed as an argument to Dispatch::Queue#async" do
+      lambda { @q.async(@g) { @i = 42 } }.should_not raise_error(ArgumentError)
+      lambda { @q.async(42) }.should raise_error(ArgumentError)
     end
+
+    describe :wait do
+
+      it "can wait forever until associated blocks have been run" do
+        @q.async(@g) { @i = 42 }
+        @g.wait(Dispatch::TIME_FOREVER)
+        @i.should == 42
+      end
+
+      it "can only wait until timeout for associated blocks to run" do
+        @i.should == 0
+        @q.async(@g) { sleep 5; @i = 42 }
+        @g.wait(0.1)
+        @i.should == 0
+      end
+
+      it "will wait forever if no timeout is specified" do
+        @q.async(@g) {sleep 0.2;  @i = 42 }
+        @g.wait
+        @i.should == 42
+      end
+
+      it "will return non-zero if it times out" do
+        @q.async(@g) {sleep 1}
+        @g.wait(0.2).should_not == 0
+      end
+
+      it "will return zero if succeeds" do
+        @g.wait(Dispatch::TIME_FOREVER).should == 0
+      end
+
+    end 
+
+    describe :notify, :shared => true do
+      it "will run a notify block on the specified queue" do
+        @g.notify(@q) { @i += 58 }
+        @q.sync {}
+        @i.should == 58
+      end
+
+      it "will run the notify block only after all associated blocks have been run" do
+        q2 = Dispatch::Queue.new('org.macruby.gcd_spec.group2')
+        @q.suspend!
+        @q.async(@g) { @i = 42 }
+        @i.should == 0
+        @g.notify(q2) { @i += 58 }
+        @i.should == 0
+        q2.suspend!
+        @q.resume!
+        @q.sync {}
+        @i.should == 42
+        q2.resume!
+        q2.sync {}
+        @i.should == 100
+      end
+    end
     
-    describe "#wait" do
+    describe "Dispatch::Group#on_completion" do
+      it_should_behave_like "notify"
     end
   end
-end
+  
+ end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091210/34704ba3/attachment.html>


More information about the macruby-changes mailing list