Skip to content
This repository
Browse code

Array specs refactor to use common specs to check behavior when no bl…

…ock is given
  • Loading branch information...
commit 8fb6ab75a49a54ae884afa4e01b69a2dba16d84c 1 parent 152abab
David Calavera authored
7  core/array/delete_if_spec.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require File.dirname(__FILE__) + '/../../spec_helper'
2 2
 require File.dirname(__FILE__) + '/fixtures/classes'
  3
+require File.dirname(__FILE__) + '/shared/enumeratorize'
3 4
 
4 5
 describe "Array#delete_if" do
5 6
   before do
@@ -16,11 +17,7 @@
16 17
     @a.delete_if{ true }.equal?(@a).should be_true
17 18
   end
18 19
 
19  
-  ruby_version_is "" ... "1.8.7" do
20  
-    it "raises a LocalJumpError if no block given" do
21  
-      lambda { @a.delete_if }.should raise_error(LocalJumpError)
22  
-    end
23  
-  end
  20
+  it_behaves_like :enumeratorize, :delete_if
24 21
 
25 22
   ruby_version_is '1.8.7' do
26 23
     it "returns an Enumerator if no block given, and the enumerator can modify the original array" do
13  core/array/each_index_spec.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require File.dirname(__FILE__) + '/../../spec_helper'
2 2
 require File.dirname(__FILE__) + '/fixtures/classes'
  3
+require File.dirname(__FILE__) + '/shared/enumeratorize'
3 4
 
4 5
 # Modifying a collection while the contents are being iterated
5 6
 # gives undefined behavior. See
@@ -21,15 +22,5 @@
21 22
     a.each_index { |i| }.should equal(a)
22 23
   end
23 24
 
24  
-  ruby_version_is '' ... '1.8.7' do
25  
-    it 'raises a LocalJumpError if no block given' do
26  
-      lambda{ [1,2].each_index }.should raise_error(LocalJumpError)
27  
-    end
28  
-  end
29  
-
30  
-  ruby_version_is '1.8.7' do
31  
-    it 'returns an Enumerator if no block given' do
32  
-      [1,2].each_index.should be_kind_of(enumerator_class)
33  
-    end
34  
-  end
  25
+  it_behaves_like :enumeratorize, :each_index
35 26
 end
13  core/array/each_spec.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require File.dirname(__FILE__) + '/../../spec_helper'
2 2
 require File.dirname(__FILE__) + '/fixtures/classes'
  3
+require File.dirname(__FILE__) + '/shared/enumeratorize'
3 4
 
4 5
 # Modifying a collection while the contents are being iterated
5 6
 # gives undefined behavior. See
@@ -25,15 +26,5 @@
25 26
     b.should == [2, nil, 4]
26 27
   end
27 28
 
28  
-  ruby_version_is '' ... '1.8.7' do
29  
-    it 'raises a LocalJumpError if no block given' do
30  
-      lambda{ [1,2].each }.should raise_error(LocalJumpError)
31  
-    end
32  
-  end
33  
-
34  
-  ruby_version_is '1.8.7' do
35  
-    it 'returns an Enumerator if no block given' do
36  
-      [1,2].each.should be_kind_of(enumerator_class)
37  
-    end
38  
-  end
  29
+  it_behaves_like :enumeratorize, :each
39 30
 end
25  core/array/reject_spec.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require File.dirname(__FILE__) + '/../../spec_helper'
2 2
 require File.dirname(__FILE__) + '/fixtures/classes'
  3
+require File.dirname(__FILE__) + '/shared/enumeratorize'
3 4
 
4 5
 describe "Array#reject" do
5 6
   it "returns a new array without elements for which block is true" do
@@ -34,17 +35,7 @@
34 35
     end
35 36
   end
36 37
   
37  
-  ruby_version_is '' ... '1.8.7' do
38  
-    it 'raises a LocalJumpError if no block given' do
39  
-      lambda{ [1,2].reject }.should raise_error(LocalJumpError)
40  
-    end
41  
-  end
42  
-  ruby_version_is '1.8.7' do
43  
-    it 'returns an Enumerator if no block given' do
44  
-      [1,2].reject.should be_kind_of(enumerator_class)
45  
-    end
46  
-  end
47  
-  
  38
+  it_behaves_like :enumeratorize, :reject 
48 39
 end
49 40
 
50 41
 describe "Array#reject!" do
@@ -105,15 +96,5 @@
105 96
     end
106 97
   end
107 98
   
108  
-  ruby_version_is '' ... '1.8.7' do
109  
-    it 'raises a LocalJumpError if no block given' do
110  
-      lambda{ [1,2].reject! }.should raise_error(LocalJumpError)
111  
-    end
112  
-  end
113  
-  ruby_version_is '1.8.7' do
114  
-    it 'returns an Enumerator if no block given' do
115  
-      [1,2].reject!.should be_kind_of(enumerator_class)
116  
-    end
117  
-  end
118  
-  
  99
+  it_behaves_like :enumeratorize, :reject!
119 100
 end
13  core/array/reverse_each_spec.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require File.dirname(__FILE__) + '/../../spec_helper'
2 2
 require File.dirname(__FILE__) + '/fixtures/classes'
  3
+require File.dirname(__FILE__) + '/shared/enumeratorize'
3 4
 
4 5
 # Modifying a collection while the contents are being iterated
5 6
 # gives undefined behavior. See
@@ -32,15 +33,5 @@
32 33
     ScratchPad.recorded.should == [array, array, array, array, array, 3.0, 'two', 1]
33 34
   end
34 35
 
35  
-  ruby_version_is '' ... '1.8.7' do
36  
-    it 'raises a LocalJumpError if no block given' do
37  
-      lambda{ [1,2].reverse_each }.should raise_error(LocalJumpError)
38  
-    end
39  
-  end
40  
-
41  
-  ruby_version_is '1.8.7' do
42  
-    it 'returns an Enumerator if no block given' do
43  
-      [1,2].reverse_each.should be_kind_of(enumerator_class)
44  
-    end
45  
-  end
  36
+  it_behaves_like :enumeratorize, :reverse_each
46 37
 end
7  core/array/select_spec.rb
... ...
@@ -1,12 +1,9 @@
1 1
 require File.dirname(__FILE__) + '/../../spec_helper'
2 2
 require File.dirname(__FILE__) + '/fixtures/classes'
  3
+require File.dirname(__FILE__) + '/shared/enumeratorize'
3 4
 
4 5
 describe "Array#select" do
5  
-  ruby_version_is "1.8.7" do
6  
-    it "returns an instance of Enumerator if no block given" do
7  
-      [1, 2].select.should be_kind_of(enumerator_class)
8  
-    end
9  
-  end
  6
+  it_behaves_like :enumeratorize, :select
10 7
 
11 8
   it "returns a new array of elements for which block is true" do
12 9
     [1, 3, 4, 5, 6, 9].select { |i| i % ((i + 1) / 2) == 0}.should == [1, 4, 6]
12  core/array/shared/enumeratorize.rb
... ...
@@ -0,0 +1,12 @@
  1
+describe :enumeratorize, :shared => true do
  2
+  ruby_version_is '' ... '1.8.7' do
  3
+    it 'raises a LocalJumpError if no block given' do
  4
+      lambda{ [1,2].send(@method) }.should raise_error(LocalJumpError)
  5
+    end
  6
+  end
  7
+  ruby_version_is '1.8.7' do
  8
+    it 'returns an Enumerator if no block given' do
  9
+      [1,2].send(@method).should be_kind_of(enumerator_class)
  10
+    end
  11
+  end
  12
+end

0 notes on commit 8fb6ab7

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