test/stubba_integration_test.rb in mocha-0.3.2 vs test/stubba_integration_test.rb in mocha-0.3.3
- old
+ new
@@ -8,52 +8,89 @@
class DontMessWithMe
def self.method_x
:original_return_value
end
+ def instance_method_1
+ :original_return_value
+ end
+ # def self.object
+ # @object ||= Class.new do
+ # def instance_method_1
+ # :original_return_value
+ # end
+ # end.new
+ # end
end
def test_should_stub_class_method_within_test
- test_class = Class.new(Test::Unit::TestCase) do
- include SmartTestCase::MultipleSetupAndTeardown
- include Stubba::SetupAndTeardown
- define_method(:test_me) do
- DontMessWithMe.expects(:method_x).returns(:new_return_value)
- assert_equal :new_return_value, DontMessWithMe.method_x
- end
+ test = build_test do
+ DontMessWithMe.expects(:method_x).returns(:new_return_value)
+ assert_equal :new_return_value, DontMessWithMe.method_x
end
- test = test_class.new(:test_me)
test_result = Test::Unit::TestResult.new
test.run(test_result) {}
assert test_result.passed?
end
- def test_should_leave_stubbed_class_unchanged_after_test
- test_class = Class.new(Test::Unit::TestCase) do
- include SmartTestCase::MultipleSetupAndTeardown
- include Stubba::SetupAndTeardown
- define_method(:test_me) do
- DontMessWithMe.expects(:method_x).returns(:new_return_value)
- end
+ def test_should_leave_stubbed_class_method_unchanged_after_test
+ test = build_test do
+ DontMessWithMe.expects(:method_x).returns(:new_return_value)
end
- test = test_class.new(:test_me)
test.run(Test::Unit::TestResult.new) {}
assert_equal :original_return_value, DontMessWithMe.method_x
end
- def test_should_reset_expectations_after_test
- test_class = Class.new(Test::Unit::TestCase) do
- include SmartTestCase::MultipleSetupAndTeardown
- include Stubba::SetupAndTeardown
- define_method(:test_me) do
- DontMessWithMe.expects(:method_x)
- end
+ def test_should_reset_class_expectations_after_test
+ test = build_test do
+ DontMessWithMe.expects(:method_x)
end
- test = test_class.new(:test_me)
test.run(Test::Unit::TestResult.new) {}
assert_equal 0, DontMessWithMe.mocha.expectations.size
end
+
+ def test_should_stub_instance_method_within_test
+ instance = DontMessWithMe.new
+ test = build_test do
+ instance.expects(:instance_method_1).returns(:new_return_value)
+ assert_equal :new_return_value, instance.instance_method_1
+ end
+ test_result = Test::Unit::TestResult.new
+ test.run(test_result) {}
+ assert test_result.passed?
+ end
+
+ def test_should_leave_stubbed_instance_method_unchanged_after_test
+ instance = DontMessWithMe.new
+ test = build_test do
+ instance.expects(:instance_method_1).returns(:new_return_value)
+ end
+
+ test.run(Test::Unit::TestResult.new) {}
+ assert_equal :original_return_value, instance.instance_method_1
+ end
+
+ def test_should_reset_instance_expectations_after_test
+ instance = DontMessWithMe.new
+ test = build_test do
+ instance.expects(:instance_method_1).returns(:new_return_value)
+ end
+
+ test.run(Test::Unit::TestResult.new) {}
+ assert_equal 0, instance.mocha.expectations.size
+ end
+
+ private
+
+ def build_test(&block)
+ test_class = Class.new(Test::Unit::TestCase) do
+ include MultipleSetupAndTeardown
+ include SetupAndTeardown
+ define_method(:test_me, &block)
+ end
+ test_class.new(:test_me)
+ end
end
\ No newline at end of file