1
require File.join(File.dirname(__FILE__), "..", "test_helper")
2
require 'mocha_standalone'
4
class NotATestUnitAssertionFailedError < StandardError
7
class NotATestUnitTestCase
9
include Mocha::Standalone
11
attr_reader :assertion_count
23
mocha_verify { @assertion_count += 1 }
24
rescue Mocha::ExpectationError => e
25
new_error = NotATestUnitAssertionFailedError.new(e.message)
26
new_error.set_backtrace(e.backtrace)
44
class SampleTest < NotATestUnitTestCase
46
def mocha_with_fulfilled_expectation
52
def mocha_with_unfulfilled_expectation
57
def mocha_with_unexpected_invocation
62
def stubba_with_fulfilled_expectation
63
stubbee = Class.new { define_method(:blah) {} }.new
64
stubbee.expects(:blah)
68
def stubba_with_unfulfilled_expectation
69
stubbee = Class.new { define_method(:blah) {} }.new
70
stubbee.expects(:blah)
73
def mocha_with_matching_parameter
75
mockee.expects(:blah).with(has_key(:wibble))
76
mockee.blah(:wibble => 1)
79
def mocha_with_non_matching_parameter
81
mockee.expects(:blah).with(has_key(:wibble))
82
mockee.blah(:wobble => 2)
89
class StandaloneAcceptanceTest < Test::Unit::TestCase
91
attr_reader :sample_test
94
@sample_test = SampleTest.new
97
def test_should_pass_mocha_test
98
assert_nothing_raised { sample_test.run(:mocha_with_fulfilled_expectation) }
99
assert_equal 1, sample_test.assertion_count
102
def test_should_fail_mocha_test_due_to_unfulfilled_exception
103
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unfulfilled_expectation) }
104
assert_equal 1, sample_test.assertion_count
107
def test_should_fail_mocha_test_due_to_unexpected_invocation
108
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unexpected_invocation) }
109
assert_equal 0, sample_test.assertion_count
112
def test_should_pass_stubba_test
113
assert_nothing_raised { sample_test.run(:stubba_with_fulfilled_expectation) }
114
assert_equal 1, sample_test.assertion_count
117
def test_should_fail_stubba_test
118
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:stubba_with_unfulfilled_expectation) }
119
assert_equal 1, sample_test.assertion_count
122
def test_should_pass_mocha_test_with_matching_parameter
123
assert_nothing_raised { sample_test.run(:mocha_with_matching_parameter) }
124
assert_equal 1, sample_test.assertion_count
127
def test_should_fail_mocha_test_with_non_matching_parameter
128
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_non_matching_parameter) }
b'\\ No newline at end of file'