Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Skipping tests for BlankSlate in Ruby 1.9.

Previous skipping logic failed for MiniTest.
  • Loading branch information...
commit 86464757d1323acad704f35eb0120ba114091244 1 parent 964c689
Jim Weirich jimweirich authored

Showing 1 changed file with 35 additions and 12 deletions. Show diff stats Hide diff stats

  1. +35 12 test/test_blankslate.rb
47 test/test_blankslate.rb
@@ -58,7 +58,7 @@ def double_late_addition
58 58
59 59 # Introduce some late methods (both module and direct) into the Object
60 60 # class.
61   -class Object
  61 +class Object
62 62 include LateObject
63 63 def another_late_addition
64 64 4321
@@ -82,17 +82,23 @@ def direct_global
82 82 #
83 83 class TestBlankSlate < Test::Unit::TestCase
84 84 if Object::const_defined?(:BasicObject)
85   - def self.suite
86   - # skip tests if :BasicObject is present
87   - Test::Unit::TestSuite.new(name)
  85 + def skipping?
  86 + true
  87 + end
  88 + else
  89 + def skipping?
  90 + false
88 91 end
89 92 end
90 93
91 94 def setup
  95 + return if skipping?
  96 + @skip = Object::const_defined?(:BasicObject)
92 97 @bs = BlankSlate.new
93 98 end
94 99
95 100 def test_undefined_methods_remain_undefined
  101 + return if skipping?
96 102 assert_raise(NoMethodError) { @bs.no_such_method }
97 103 assert_raise(NoMethodError) { @bs.nil? }
98 104 end
@@ -101,6 +107,7 @@ def test_undefined_methods_remain_undefined
101 107 # NOTE: NameError is acceptable because the lack of a '.' means that
102 108 # Ruby can't tell if it is a method or a local variable.
103 109 def test_undefined_methods_remain_undefined_during_instance_eval
  110 + return if skipping?
104 111 assert_raise(NoMethodError, NameError) do
105 112 @bs.instance_eval do nil? end
106 113 end
@@ -110,62 +117,73 @@ def test_undefined_methods_remain_undefined_during_instance_eval
110 117 end
111 118
112 119 def test_private_methods_are_undefined
  120 + return if skipping?
113 121 assert_raise(NoMethodError) do
114 122 @bs.puts "HI"
115 123 end
116 124 end
117   -
  125 +
118 126 def test_targetted_private_methods_are_undefined_during_instance_eval
  127 + return if skipping?
119 128 assert_raise(NoMethodError, NameError) do
120 129 @bs.instance_eval do self.puts "HI" end
121 130 end
122 131 end
123   -
  132 +
124 133 def test_untargetted_private_methods_are_defined_during_instance_eval
125 134 oldstdout = $stdout
  135 + return if skipping?
126 136 $stdout = StringIO.new
127   - @bs.instance_eval do
  137 + @bs.instance_eval do
128 138 puts "HI"
129 139 end
130 140 ensure
131 141 $stdout = oldstdout
132 142 end
133   -
  143 +
134 144 def test_methods_added_late_to_kernel_remain_undefined
  145 + return if skipping?
135 146 assert_equal 1234, nil.late_addition
136 147 assert_raise(NoMethodError) { @bs.late_addition }
137 148 end
138 149
139 150 def test_methods_added_late_to_object_remain_undefined
  151 + return if skipping?
140 152 assert_equal 4321, nil.another_late_addition
141 153 assert_raise(NoMethodError) { @bs.another_late_addition }
142 154 end
143   -
  155 +
144 156 def test_methods_added_late_to_global_remain_undefined
  157 + return if skipping?
145 158 assert_equal 42, global_inclusion
146 159 assert_raise(NoMethodError) { @bs.global_inclusion }
147 160 end
148 161
149 162 def test_preload_method_added
  163 + return if skipping?
150 164 assert Kernel.k_added_names.include?(:late_addition)
151 165 assert Object.o_added_names.include?(:another_late_addition)
152 166 end
153 167
154 168 def test_method_defined_late_multiple_times_remain_undefined
  169 + return if skipping?
155 170 assert_equal 22, nil.double_late_addition
156 171 assert_raise(NoMethodError) { @bs.double_late_addition }
157 172 end
158 173
159 174 def test_late_included_module_in_object_is_ok
  175 + return if skipping?
160 176 assert_equal 33, 1.late_object
161 177 assert_raise(NoMethodError) { @bs.late_object }
162 178 end
163 179
164 180 def test_late_included_module_in_kernel_is_ok
  181 + return if skipping?
165 182 assert_raise(NoMethodError) { @bs.late_kernel }
166 183 end
167 184
168 185 def test_revealing_previously_hidden_methods_are_callable
  186 + return if skipping?
169 187 with_to_s = Class.new(BlankSlate) do
170 188 reveal :to_s
171 189 end
@@ -173,12 +191,13 @@ def test_revealing_previously_hidden_methods_are_callable
173 191 end
174 192
175 193 def test_revealing_previously_hidden_methods_are_callable_with_block
  194 + return if skipping?
176 195 Object.class_eval <<-EOS
177 196 def given_block(&block)
178 197 block
179   - end
  198 + end
180 199 EOS
181   -
  200 +
182 201 with_given_block = Class.new(BlankSlate) do
183 202 reveal :given_block
184 203 end
@@ -186,6 +205,7 @@ def given_block(&block)
186 205 end
187 206
188 207 def test_revealing_a_hidden_method_twice_is_ok
  208 + return if skipping?
189 209 with_to_s = Class.new(BlankSlate) do
190 210 reveal :to_s
191 211 reveal :to_s
@@ -194,6 +214,7 @@ def test_revealing_a_hidden_method_twice_is_ok
194 214 end
195 215
196 216 def test_revealing_unknown_hidden_method_is_an_error
  217 + return if skipping?
197 218 assert_raises(RuntimeError) do
198 219 Class.new(BlankSlate) do
199 220 reveal :xyz
@@ -202,6 +223,7 @@ def test_revealing_unknown_hidden_method_is_an_error
202 223 end
203 224
204 225 def test_global_includes_still_work
  226 + return if skipping?
205 227 assert_nothing_raised do
206 228 assert_equal 42, global_inclusion
207 229 assert_equal 42, Object.new.global_inclusion
@@ -211,6 +233,7 @@ def test_global_includes_still_work
211 233 end
212 234
213 235 def test_reveal_should_not_bind_to_an_instance
  236 + return if skipping?
214 237 with_object_id = Class.new(BlankSlate) do
215 238 reveal(:object_id)
216 239 end
@@ -218,7 +241,7 @@ def test_reveal_should_not_bind_to_an_instance
218 241 obj1 = with_object_id.new
219 242 obj2 = with_object_id.new
220 243
221   - assert obj1.object_id != obj2.object_id,
  244 + assert obj1.object_id != obj2.object_id,
222 245 "Revealed methods should not be bound to a particular instance"
223 246 end
224 247 end

0 comments on commit 8646475

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