mocha 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -4
- data/RELEASE +32 -0
- data/Rakefile +3 -3
- data/examples/misc.rb +36 -0
- data/examples/mocha.rb +26 -0
- data/examples/stubba.rb +65 -0
- data/lib/mocha.rb +17 -5
- data/lib/{stubba → mocha}/any_instance_method.rb +2 -2
- data/lib/mocha/auto_verify.rb +7 -7
- data/lib/{stubba → mocha}/central.rb +2 -2
- data/lib/{stubba → mocha}/class_method.rb +7 -10
- data/lib/mocha/expectation.rb +88 -33
- data/lib/mocha/expectation_error.rb +6 -0
- data/lib/mocha/inspect.rb +1 -1
- data/lib/mocha/instance_method.rb +8 -0
- data/lib/mocha/metaclass.rb +1 -1
- data/lib/mocha/mock.rb +8 -8
- data/lib/mocha/mock_methods.rb +60 -16
- data/lib/{stubba → mocha}/object.rb +8 -10
- data/lib/mocha/setup_and_teardown.rb +23 -0
- data/lib/mocha/standalone.rb +30 -0
- data/lib/mocha/test_case_adapter.rb +49 -0
- data/lib/mocha_standalone.rb +2 -0
- data/lib/stubba.rb +2 -8
- data/test/all_tests.rb +9 -10
- data/test/method_definer.rb +2 -2
- data/test/{stubba → mocha}/any_instance_method_test.rb +1 -3
- data/test/mocha/auto_verify_test.rb +9 -10
- data/test/{stubba → mocha}/central_test.rb +5 -4
- data/test/{stubba → mocha}/class_method_test.rb +40 -10
- data/test/mocha/expectation_test.rb +144 -67
- data/test/mocha/inspect_test.rb +12 -1
- data/test/mocha/metaclass_test.rb +22 -0
- data/test/mocha/mock_methods_test.rb +65 -7
- data/test/mocha/mock_test.rb +41 -4
- data/test/{stubba → mocha}/object_test.rb +9 -9
- data/test/mocha/setup_and_teardown_test.rb +76 -0
- data/test/mocha_acceptance_test.rb +8 -8
- data/test/mocha_test_result_integration_test.rb +5 -6
- data/test/standalone_acceptance_test.rb +110 -0
- data/test/stubba_acceptance_test.rb +2 -2
- data/test/stubba_integration_test.rb +17 -24
- data/test/stubba_test_result_integration_test.rb +5 -6
- metadata +22 -18
- data/lib/shared/backtracefilter.rb +0 -46
- data/lib/smart_test_case.rb +0 -5
- data/lib/smart_test_case/multiple_setup_and_teardown.rb +0 -123
- data/lib/stubba/instance_method.rb +0 -18
- data/lib/stubba/setup_and_teardown.rb +0 -25
- data/test/smart_test_case/multiple_setup_and_teardown_test.rb +0 -192
- data/test/stubba/instance_method_test.rb +0 -46
- data/test/stubba/setup_and_teardown_test.rb +0 -134
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
-
require 'method_definer'
|
3
|
-
|
4
|
-
require 'stubba/instance_method'
|
5
|
-
|
6
|
-
class InstanceMethodTest < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Stubba
|
9
|
-
|
10
|
-
def test_should_exist
|
11
|
-
klass = Class.new { def method_x; end }
|
12
|
-
instance = klass.new
|
13
|
-
method = InstanceMethod.new(instance, :method_x)
|
14
|
-
|
15
|
-
assert method.exists?
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_should_not_exist
|
19
|
-
klass = Class.new { }
|
20
|
-
instance = klass.new
|
21
|
-
method = InstanceMethod.new(instance, :non_existent_method)
|
22
|
-
|
23
|
-
assert !method.exists?
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_raise_assertion_failed_error_when_attempting_to_stub_non_existent_method
|
27
|
-
klass = Class.new
|
28
|
-
instance = klass.new
|
29
|
-
method = InstanceMethod.new(instance, :non_existent_method)
|
30
|
-
|
31
|
-
assert_raise(Test::Unit::AssertionFailedError) { method.stub }
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_not_raise_assertion_failed_error_when_attempting_to_stub_existing_method
|
35
|
-
klass = Class.new { def method_x; end }
|
36
|
-
instance = klass.new
|
37
|
-
method = InstanceMethod.new(instance, :method_x)
|
38
|
-
|
39
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) { method.stub }
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_inherit_from_class_method
|
43
|
-
assert_equal ClassMethod, InstanceMethod.superclass
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
-
require 'mocha/mock'
|
3
|
-
|
4
|
-
require 'stubba/setup_and_teardown'
|
5
|
-
|
6
|
-
class SetupAndTeardownTest < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Mocha
|
9
|
-
|
10
|
-
def test_should_add_setup_stubs_to_setup_methods
|
11
|
-
test_case_class = Class.new do
|
12
|
-
class << self
|
13
|
-
attr_accessor :symbol
|
14
|
-
define_method(:add_setup_method) { |symbol| @symbol = symbol }
|
15
|
-
define_method(:add_teardown_method) {}
|
16
|
-
end
|
17
|
-
include SetupAndTeardown
|
18
|
-
end
|
19
|
-
|
20
|
-
assert_equal :setup_stubs, test_case_class.symbol
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_should_add_teardown_stubs_to_teardown_methods
|
24
|
-
test_case_class = Class.new do
|
25
|
-
class << self
|
26
|
-
attr_accessor :symbol
|
27
|
-
define_method(:add_setup_method) {}
|
28
|
-
define_method(:add_teardown_method) { |symbol| @symbol = symbol }
|
29
|
-
end
|
30
|
-
include SetupAndTeardown
|
31
|
-
end
|
32
|
-
|
33
|
-
assert_equal :teardown_stubs, test_case_class.symbol
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_should_instantiate_new_stubba
|
37
|
-
test_case = stubbed_test_case_class.new
|
38
|
-
test_case.setup_stubs
|
39
|
-
|
40
|
-
assert $stubba
|
41
|
-
assert $stubba.is_a?(Stubba::Central)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_should_verify_all_expectations
|
45
|
-
test_case = stubbed_test_case_class.new
|
46
|
-
stubba = Mock.new
|
47
|
-
stubba.expects(:verify_all)
|
48
|
-
stubba.stubs(:unstub_all)
|
49
|
-
$stubba = stubba
|
50
|
-
|
51
|
-
test_case.teardown_stubs
|
52
|
-
|
53
|
-
stubba.verify
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_pass_block_to_add_assertion_to_test_case
|
57
|
-
test_case = stubbed_test_case_class.new
|
58
|
-
$stubba = Mock.new
|
59
|
-
$stubba.stubs(:verify_all).yields
|
60
|
-
$stubba.stubs(:unstub_all)
|
61
|
-
|
62
|
-
test_case.teardown_stubs
|
63
|
-
|
64
|
-
assert_equal true, test_case.add_assertion_called
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_should_unstub_all_stubbed_methods
|
68
|
-
test_case = stubbed_test_case_class.new
|
69
|
-
stubba = Mock.new
|
70
|
-
stubba.stubs(:verify_all)
|
71
|
-
stubba.expects(:unstub_all)
|
72
|
-
$stubba = stubba
|
73
|
-
|
74
|
-
test_case.teardown_stubs
|
75
|
-
|
76
|
-
stubba.verify
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_should_unstub_all_stubbed_methods_even_if_verify_all_raises_exception
|
80
|
-
test_case = stubbed_test_case_class.new
|
81
|
-
stubba = Mock.new
|
82
|
-
stubba.stubs(:verify_all).raises(Exception)
|
83
|
-
stubba.expects(:unstub_all)
|
84
|
-
$stubba = stubba
|
85
|
-
|
86
|
-
assert_raises(Exception) { test_case.teardown_stubs }
|
87
|
-
|
88
|
-
stubba.verify
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_should_set_stubba_to_nil
|
92
|
-
test_case = stubbed_test_case_class.new
|
93
|
-
$stubba = Mock.new
|
94
|
-
$stubba.stubs(:verify_all)
|
95
|
-
$stubba.stubs(:unstub_all)
|
96
|
-
|
97
|
-
test_case.teardown_stubs
|
98
|
-
|
99
|
-
assert_nil $stubba
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_should_set_stubba_to_nil_even_if_verify_all_raises_exception
|
103
|
-
test_case = stubbed_test_case_class.new
|
104
|
-
$stubba = Mock.new
|
105
|
-
$stubba.stubs(:verify_all).raises(Exception)
|
106
|
-
$stubba.stubs(:unstub_all)
|
107
|
-
|
108
|
-
assert_raises(Exception) { test_case.teardown_stubs }
|
109
|
-
|
110
|
-
assert_nil $stubba
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_should_not_raise_exception_if_no_stubba_central_available
|
114
|
-
test_case = stubbed_test_case_class.new
|
115
|
-
$stubba = nil
|
116
|
-
assert_nothing_raised { test_case.teardown_stubs }
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
def stubbed_test_case_class
|
122
|
-
Class.new do
|
123
|
-
class << self
|
124
|
-
define_method(:add_setup_method) {}
|
125
|
-
define_method(:add_teardown_method) {}
|
126
|
-
end
|
127
|
-
attr_accessor :add_assertion_called
|
128
|
-
define_method(:add_assertion) { self.add_assertion_called = true }
|
129
|
-
include SetupAndTeardown
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
|