Skip to content

Commit

Permalink
Skipping tests for BlankSlate in Ruby 1.9.
Browse files Browse the repository at this point in the history
Previous skipping logic failed for MiniTest.
  • Loading branch information
jimweirich committed Nov 29, 2011
1 parent 964c689 commit 8646475
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions test/test_blankslate.rb
Expand Up @@ -58,7 +58,7 @@ def double_late_addition


# Introduce some late methods (both module and direct) into the Object # Introduce some late methods (both module and direct) into the Object
# class. # class.
class Object class Object
include LateObject include LateObject
def another_late_addition def another_late_addition
4321 4321
Expand All @@ -82,17 +82,23 @@ def direct_global
# #
class TestBlankSlate < Test::Unit::TestCase class TestBlankSlate < Test::Unit::TestCase
if Object::const_defined?(:BasicObject) if Object::const_defined?(:BasicObject)
def self.suite def skipping?
# skip tests if :BasicObject is present true
Test::Unit::TestSuite.new(name) end
else
def skipping?
false
end end
end end


def setup def setup
return if skipping?
@skip = Object::const_defined?(:BasicObject)
@bs = BlankSlate.new @bs = BlankSlate.new
end end


def test_undefined_methods_remain_undefined def test_undefined_methods_remain_undefined
return if skipping?
assert_raise(NoMethodError) { @bs.no_such_method } assert_raise(NoMethodError) { @bs.no_such_method }
assert_raise(NoMethodError) { @bs.nil? } assert_raise(NoMethodError) { @bs.nil? }
end end
Expand All @@ -101,6 +107,7 @@ def test_undefined_methods_remain_undefined
# NOTE: NameError is acceptable because the lack of a '.' means that # NOTE: NameError is acceptable because the lack of a '.' means that
# Ruby can't tell if it is a method or a local variable. # Ruby can't tell if it is a method or a local variable.
def test_undefined_methods_remain_undefined_during_instance_eval def test_undefined_methods_remain_undefined_during_instance_eval
return if skipping?
assert_raise(NoMethodError, NameError) do assert_raise(NoMethodError, NameError) do
@bs.instance_eval do nil? end @bs.instance_eval do nil? end
end end
Expand All @@ -110,82 +117,95 @@ def test_undefined_methods_remain_undefined_during_instance_eval
end end


def test_private_methods_are_undefined def test_private_methods_are_undefined
return if skipping?
assert_raise(NoMethodError) do assert_raise(NoMethodError) do
@bs.puts "HI" @bs.puts "HI"
end end
end end

def test_targetted_private_methods_are_undefined_during_instance_eval def test_targetted_private_methods_are_undefined_during_instance_eval
return if skipping?
assert_raise(NoMethodError, NameError) do assert_raise(NoMethodError, NameError) do
@bs.instance_eval do self.puts "HI" end @bs.instance_eval do self.puts "HI" end
end end
end end

def test_untargetted_private_methods_are_defined_during_instance_eval def test_untargetted_private_methods_are_defined_during_instance_eval
oldstdout = $stdout oldstdout = $stdout
return if skipping?
$stdout = StringIO.new $stdout = StringIO.new
@bs.instance_eval do @bs.instance_eval do
puts "HI" puts "HI"
end end
ensure ensure
$stdout = oldstdout $stdout = oldstdout
end end

def test_methods_added_late_to_kernel_remain_undefined def test_methods_added_late_to_kernel_remain_undefined
return if skipping?
assert_equal 1234, nil.late_addition assert_equal 1234, nil.late_addition
assert_raise(NoMethodError) { @bs.late_addition } assert_raise(NoMethodError) { @bs.late_addition }
end end


def test_methods_added_late_to_object_remain_undefined def test_methods_added_late_to_object_remain_undefined
return if skipping?
assert_equal 4321, nil.another_late_addition assert_equal 4321, nil.another_late_addition
assert_raise(NoMethodError) { @bs.another_late_addition } assert_raise(NoMethodError) { @bs.another_late_addition }
end end

def test_methods_added_late_to_global_remain_undefined def test_methods_added_late_to_global_remain_undefined
return if skipping?
assert_equal 42, global_inclusion assert_equal 42, global_inclusion
assert_raise(NoMethodError) { @bs.global_inclusion } assert_raise(NoMethodError) { @bs.global_inclusion }
end end


def test_preload_method_added def test_preload_method_added
return if skipping?
assert Kernel.k_added_names.include?(:late_addition) assert Kernel.k_added_names.include?(:late_addition)
assert Object.o_added_names.include?(:another_late_addition) assert Object.o_added_names.include?(:another_late_addition)
end end


def test_method_defined_late_multiple_times_remain_undefined def test_method_defined_late_multiple_times_remain_undefined
return if skipping?
assert_equal 22, nil.double_late_addition assert_equal 22, nil.double_late_addition
assert_raise(NoMethodError) { @bs.double_late_addition } assert_raise(NoMethodError) { @bs.double_late_addition }
end end


def test_late_included_module_in_object_is_ok def test_late_included_module_in_object_is_ok
return if skipping?
assert_equal 33, 1.late_object assert_equal 33, 1.late_object
assert_raise(NoMethodError) { @bs.late_object } assert_raise(NoMethodError) { @bs.late_object }
end end


def test_late_included_module_in_kernel_is_ok def test_late_included_module_in_kernel_is_ok
return if skipping?
assert_raise(NoMethodError) { @bs.late_kernel } assert_raise(NoMethodError) { @bs.late_kernel }
end end


def test_revealing_previously_hidden_methods_are_callable def test_revealing_previously_hidden_methods_are_callable
return if skipping?
with_to_s = Class.new(BlankSlate) do with_to_s = Class.new(BlankSlate) do
reveal :to_s reveal :to_s
end end
assert_match /^#<.*>$/, with_to_s.new.to_s assert_match /^#<.*>$/, with_to_s.new.to_s
end end


def test_revealing_previously_hidden_methods_are_callable_with_block def test_revealing_previously_hidden_methods_are_callable_with_block
return if skipping?
Object.class_eval <<-EOS Object.class_eval <<-EOS
def given_block(&block) def given_block(&block)
block block
end end
EOS EOS

with_given_block = Class.new(BlankSlate) do with_given_block = Class.new(BlankSlate) do
reveal :given_block reveal :given_block
end end
assert_not_nil with_given_block.new.given_block {} assert_not_nil with_given_block.new.given_block {}
end end


def test_revealing_a_hidden_method_twice_is_ok def test_revealing_a_hidden_method_twice_is_ok
return if skipping?
with_to_s = Class.new(BlankSlate) do with_to_s = Class.new(BlankSlate) do
reveal :to_s reveal :to_s
reveal :to_s reveal :to_s
Expand All @@ -194,6 +214,7 @@ def test_revealing_a_hidden_method_twice_is_ok
end end


def test_revealing_unknown_hidden_method_is_an_error def test_revealing_unknown_hidden_method_is_an_error
return if skipping?
assert_raises(RuntimeError) do assert_raises(RuntimeError) do
Class.new(BlankSlate) do Class.new(BlankSlate) do
reveal :xyz reveal :xyz
Expand All @@ -202,6 +223,7 @@ def test_revealing_unknown_hidden_method_is_an_error
end end


def test_global_includes_still_work def test_global_includes_still_work
return if skipping?
assert_nothing_raised do assert_nothing_raised do
assert_equal 42, global_inclusion assert_equal 42, global_inclusion
assert_equal 42, Object.new.global_inclusion assert_equal 42, Object.new.global_inclusion
Expand All @@ -211,14 +233,15 @@ def test_global_includes_still_work
end end


def test_reveal_should_not_bind_to_an_instance def test_reveal_should_not_bind_to_an_instance
return if skipping?
with_object_id = Class.new(BlankSlate) do with_object_id = Class.new(BlankSlate) do
reveal(:object_id) reveal(:object_id)
end end


obj1 = with_object_id.new obj1 = with_object_id.new
obj2 = with_object_id.new obj2 = with_object_id.new


assert obj1.object_id != obj2.object_id, assert obj1.object_id != obj2.object_id,
"Revealed methods should not be bound to a particular instance" "Revealed methods should not be bound to a particular instance"
end end
end end
Expand Down

0 comments on commit 8646475

Please sign in to comment.