1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
require 'test_helper'
class ClassExtensionsTest < Minitest::Test
class Dog
def wag
end
def method_missing(sym, *args, &block)
if sym == :bark
:woof
else
super
end
end
def responds_to?(sym)
sym == :bark || super
end
end
def test_class_directly_defines_method
assert Dog.flexmock_defined?(:wag)
end
def test_class_indirectly_defines_method
assert ! Dog.flexmock_defined?(:bark)
end
def test_class_does_not_define_method
assert ! Dog.flexmock_defined?(:jump)
end
def test_singleton_class_directly_defines_method
obj = Dog.new
obj.singleton_class.class_eval do
define_method(:jump) { }
end
assert obj.singleton_class.flexmock_defined?(:jump)
end
def test_flexmock_defined_the_method_through_a_partial_mock
obj = Dog.new
FlexMock.use(obj) do |mock|
mock.should_receive(:jump)
assert obj.singleton_class.method_defined?(:jump)
assert !obj.singleton_class.flexmock_defined?(:jump)
end
end
def test_flexmock_defined_works_with_included_modules
assert Dog.flexmock_defined?(:sleep)
end
end
|