Skip to content
This repository
Browse code

Guard Fiber and Generator specs properly

  • Loading branch information...
commit d6e6b849f43a39d442bb69b6eb592188f159be69 1 parent facded3
Evan Phoenix authored July 21, 2011 brixen committed August 15, 2011
38  library/generator/each_spec.rb
... ...
@@ -1,31 +1,33 @@
1 1
 require File.expand_path('../../../spec_helper', __FILE__)
2 2
 
3 3
 ruby_version_is ""..."1.9" do
  4
+  with_feature :generator do
4 5
 
5  
-  require File.expand_path('../fixtures/common', __FILE__)
  6
+    require File.expand_path('../fixtures/common', __FILE__)
6 7
 
7  
-  describe "Generator#each" do
8  
-    it "enumerates the elements" do
9  
-      g = GeneratorSpecs.four_elems
10  
-      result = []
  8
+    describe "Generator#each" do
  9
+      it "enumerates the elements" do
  10
+        g = GeneratorSpecs.four_elems
  11
+        result = []
11 12
 
12  
-      g.each { |element|
13  
-        result << element
14  
-      }
  13
+        g.each { |element|
  14
+          result << element
  15
+        }
15 16
 
16  
-      result.should == ['A', 'B', 'C', 'Z']
17  
-    end
  17
+        result.should == ['A', 'B', 'C', 'Z']
  18
+      end
18 19
 
19  
-    it "rewinds the generator and only then enumerates the elements" do
20  
-      g = GeneratorSpecs.four_elems
21  
-      g.next; g.next
22  
-      result = []
  20
+      it "rewinds the generator and only then enumerates the elements" do
  21
+        g = GeneratorSpecs.four_elems
  22
+        g.next; g.next
  23
+        result = []
23 24
 
24  
-      g.each { |element|
25  
-        result << element
26  
-      }
  25
+        g.each { |element|
  26
+          result << element
  27
+        }
27 28
 
28  
-      result.should == ['A', 'B', 'C', 'Z']
  29
+        result.should == ['A', 'B', 'C', 'Z']
  30
+      end
29 31
     end
30 32
   end
31 33
 end
36  library/generator/new_spec.rb
... ...
@@ -1,24 +1,26 @@
1 1
 require File.expand_path('../../../spec_helper', __FILE__)
2 2
 
3  
-ruby_version_is ""..."1.9"  do
4  
-  require 'generator'
5  
-  describe "Generator.new" do
6  
-    it "creates a new generator from an Enumerable object" do
7  
-      g = Generator.new(['A', 'B', 'C', 'Z'])
8  
-      g.should_not == nil
9  
-      g.kind_of?(Generator).should == true
10  
-    end
  3
+ruby_version_is ""..."1.9" do
  4
+  with_feature :generator do
  5
+    require 'generator'
  6
+    describe "Generator.new" do
  7
+      it "creates a new generator from an Enumerable object" do
  8
+        g = Generator.new(['A', 'B', 'C', 'Z'])
  9
+        g.should_not == nil
  10
+        g.kind_of?(Generator).should == true
  11
+      end
11 12
 
12  
-    it "creates a new generator from a block" do
13  
-      g = Generator.new { |g|
14  
-        for i in 'A'..'C'
15  
-          g.yield i
16  
-        end
17  
-        g.yield 'Z'
18  
-      }
  13
+      it "creates a new generator from a block" do
  14
+        g = Generator.new { |g|
  15
+          for i in 'A'..'C'
  16
+            g.yield i
  17
+          end
  18
+          g.yield 'Z'
  19
+        }
19 20
 
20  
-      g.should_not == nil
21  
-      g.kind_of?(Generator).should == true
  21
+        g.should_not == nil
  22
+        g.kind_of?(Generator).should == true
  23
+      end
22 24
     end
23 25
   end
24 26
 end
114  library/generator/next_spec.rb
... ...
@@ -1,77 +1,79 @@
1 1
 require File.expand_path('../../../spec_helper', __FILE__)
2 2
 
3 3
 ruby_version_is ""..."1.9" do
4  
-  require File.expand_path('../fixtures/common', __FILE__)
  4
+  with_feature :generator do
  5
+    require File.expand_path('../fixtures/common', __FILE__)
5 6
 
6  
-  describe "Generator#next?" do
7  
-    it "returns false for empty generator" do
8  
-      GeneratorSpecs.empty.next?.should == false
9  
-    end
  7
+    describe "Generator#next?" do
  8
+      it "returns false for empty generator" do
  9
+        GeneratorSpecs.empty.next?.should == false
  10
+      end
10 11
 
11  
-    it "returns true for non-empty generator" do
12  
-      g = Generator.new([1])
13  
-      g.next?.should == true
  12
+      it "returns true for non-empty generator" do
  13
+        g = Generator.new([1])
  14
+        g.next?.should == true
14 15
 
15  
-      GeneratorSpecs.two_elems.next?.should == true
  16
+        GeneratorSpecs.two_elems.next?.should == true
16 17
 
17  
-      g = Generator.new(['A', 'B', 'C', 'D', 'E', 'F'])
18  
-      g.next?.should == true
19  
-    end
  18
+        g = Generator.new(['A', 'B', 'C', 'D', 'E', 'F'])
  19
+        g.next?.should == true
  20
+      end
20 21
 
21  
-    it "returns true if the generator has not reached the end yet" do
22  
-      g = GeneratorSpecs.two_elems
23  
-      g.next
24  
-      g.next?.should == true
25  
-    end
  22
+      it "returns true if the generator has not reached the end yet" do
  23
+        g = GeneratorSpecs.two_elems
  24
+        g.next
  25
+        g.next?.should == true
  26
+      end
26 27
 
27  
-    it "returns false if the generator has reached the end" do
28  
-      g = GeneratorSpecs.two_elems
29  
-      g.next
30  
-      g.next
31  
-      g.next?.should == false
32  
-    end
  28
+      it "returns false if the generator has reached the end" do
  29
+        g = GeneratorSpecs.two_elems
  30
+        g.next
  31
+        g.next
  32
+        g.next?.should == false
  33
+      end
33 34
 
34  
-    it "returns false if end? returns true" do
35  
-      g = GeneratorSpecs.two_elems
36  
-      def g.end?; true end
37  
-      g.next?.should == false
  35
+      it "returns false if end? returns true" do
  36
+        g = GeneratorSpecs.two_elems
  37
+        def g.end?; true end
  38
+        g.next?.should == false
  39
+      end
38 40
     end
39  
-  end
40 41
 
41  
-  describe "Generator#next" do
42  
-    it "raises an EOFError on empty generator" do
43  
-      lambda { GeneratorSpecs.empty.next }.should raise_error(EOFError)
44  
-    end
  42
+    describe "Generator#next" do
  43
+      it "raises an EOFError on empty generator" do
  44
+        lambda { GeneratorSpecs.empty.next }.should raise_error(EOFError)
  45
+      end
45 46
 
46  
-    it "raises an EOFError if no elements available" do
47  
-      g = GeneratorSpecs.two_elems
48  
-      g.next;
49  
-      g.next
50  
-      lambda { g.next }.should raise_error(EOFError)
51  
-    end
  47
+      it "raises an EOFError if no elements available" do
  48
+        g = GeneratorSpecs.two_elems
  49
+        g.next;
  50
+        g.next
  51
+        lambda { g.next }.should raise_error(EOFError)
  52
+      end
52 53
 
53  
-    it "raises an EOFError if end? returns true" do
54  
-      g = GeneratorSpecs.two_elems
55  
-      def g.end?; true end
56  
-      lambda { g.next }.should raise_error(EOFError)
57  
-    end
  54
+      it "raises an EOFError if end? returns true" do
  55
+        g = GeneratorSpecs.two_elems
  56
+        def g.end?; true end
  57
+        lambda { g.next }.should raise_error(EOFError)
  58
+      end
58 59
 
59  
-    it "returns the element at the current position and moves forward" do
60  
-      g = GeneratorSpecs.two_elems
61  
-      g.index.should == 0
62  
-      g.next.should == 1
63  
-      g.index.should == 1
64  
-    end
  60
+      it "returns the element at the current position and moves forward" do
  61
+        g = GeneratorSpecs.two_elems
  62
+        g.index.should == 0
  63
+        g.next.should == 1
  64
+        g.index.should == 1
  65
+      end
65 66
 
66  
-    it "subsequent calls should return all elements in proper order" do
67  
-      g = GeneratorSpecs.four_elems
  67
+      it "subsequent calls should return all elements in proper order" do
  68
+        g = GeneratorSpecs.four_elems
68 69
 
69  
-      result = []
70  
-      while g.next?
71  
-        result << g.next
72  
-      end
  70
+        result = []
  71
+        while g.next?
  72
+          result << g.next
  73
+        end
73 74
 
74  
-      result.should == ['A', 'B', 'C', 'Z']
  75
+        result.should == ['A', 'B', 'C', 'Z']
  76
+      end
75 77
     end
76 78
   end
77 79
 end
49  library/generator/rewind_spec.rb
... ...
@@ -1,33 +1,34 @@
1 1
 require File.expand_path('../../../spec_helper', __FILE__)
2 2
 
3 3
 ruby_version_is ""..."1.9" do
  4
+  with_feature :generator do
  5
+    require File.expand_path('../fixtures/common', __FILE__)
4 6
 
5  
-  require File.expand_path('../fixtures/common', __FILE__)
  7
+    describe "Generator#rewind" do
  8
+      it "does nothing for empty generator" do
  9
+        g = GeneratorSpecs.empty
  10
+        g.index.should == 0
  11
+        g.rewind
  12
+        g.index.should == 0
  13
+      end
6 14
 
7  
-  describe "Generator#rewind" do
8  
-    it "does nothing for empty generator" do
9  
-      g = GeneratorSpecs.empty
10  
-      g.index.should == 0
11  
-      g.rewind
12  
-      g.index.should == 0
13  
-    end
14  
-
15  
-    it "rewinds the generator" do
16  
-      g = GeneratorSpecs.two_elems
17  
-      orig = g.next
18  
-      g.index.should == 1
19  
-      g.rewind
20  
-      g.index.should == 0
21  
-      g.next.should == orig
22  
-    end
  15
+      it "rewinds the generator" do
  16
+        g = GeneratorSpecs.two_elems
  17
+        orig = g.next
  18
+        g.index.should == 1
  19
+        g.rewind
  20
+        g.index.should == 0
  21
+        g.next.should == orig
  22
+      end
23 23
 
24  
-    it "rewinds the previously finished generator" do
25  
-      g = GeneratorSpecs.two_elems
26  
-      g.next; g.next
27  
-      g.rewind
28  
-      g.end?.should == false
29  
-      g.next?.should == true
30  
-      g.next.should == 1
  24
+      it "rewinds the previously finished generator" do
  25
+        g = GeneratorSpecs.two_elems
  26
+        g.next; g.next
  27
+        g.rewind
  28
+        g.end?.should == false
  29
+        g.next?.should == true
  30
+        g.next.should == 1
  31
+      end
31 32
     end
32 33
   end
33 34
 end

0 notes on commit d6e6b84

Please sign in to comment.
Something went wrong with that request. Please try again.