mocha 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +17 -146
- data/Rakefile +60 -6
- data/lib/mocha.rb +1 -1
- data/lib/mocha/auto_verify.rb +101 -34
- data/lib/mocha/expectation.rb +112 -3
- data/lib/mocha/mock.rb +9 -2
- data/lib/mocha/mock_methods.rb +21 -1
- data/lib/smart_test_case.rb +1 -1
- data/lib/smart_test_case/multiple_setup_and_teardown.rb +91 -89
- data/lib/stubba.rb +1 -1
- data/lib/stubba/object.rb +33 -8
- data/lib/stubba/setup_and_teardown.rb +19 -17
- data/test/all_tests.rb +0 -7
- data/test/mocha/auto_verify_test.rb +16 -1
- data/test/mocha/expectation_test.rb +8 -6
- data/test/mocha/mock_methods_test.rb +1 -1
- data/test/mocha/mock_test.rb +10 -0
- data/test/mocha_test_result_integration_test.rb +2 -2
- data/test/smart_test_case/multiple_setup_and_teardown_test.rb +11 -11
- data/test/stubba/setup_and_teardown_test.rb +3 -3
- data/test/stubba_integration_test.rb +7 -7
- data/test/stubba_test_result_integration_test.rb +2 -2
- metadata +3 -12
- data/TODO +0 -14
- data/lib/auto_mocha.rb +0 -2
- data/lib/auto_mocha/auto_mock.rb +0 -54
- data/lib/auto_mocha/mock_class.rb +0 -38
- data/test/auto_mocha/auto_mock_test.rb +0 -85
- data/test/auto_mocha/mock_class_test.rb +0 -179
- data/test/auto_mock_acceptance_test.rb +0 -35
@@ -1,85 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
-
require 'auto_mocha/auto_mock'
|
3
|
-
|
4
|
-
class AutoMockTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
reset_mochas
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_should_reset_mochas
|
11
|
-
undefined_class = UndefinedClass
|
12
|
-
reset_mochas
|
13
|
-
assert_not_same undefined_class, UndefinedClass
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_refer_to_same_class
|
17
|
-
defined_class = Class.new { def self.undefined_class; UndefinedClass; end }
|
18
|
-
assert_same UndefinedClass, defined_class.undefined_class
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_refer_to_same_parent_class
|
22
|
-
defined_class = Class.new(UndefinedClass)
|
23
|
-
assert_same UndefinedClass, defined_class.superclass
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_refer_to_same_namespaced_class
|
27
|
-
defined_class = Class.new { def self.namespaced_class; Namespace::UndefinedClass; end }
|
28
|
-
assert_same Namespace::UndefinedClass, defined_class.namespaced_class
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_should_refer_to_different_namespaced_classes_within_test
|
32
|
-
assert ! NamespaceOne::UndefinedClass.equal?(NamespaceTwo::UndefinedClass)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_should_refer_to_different_namespaced_classes_within_class_under_test
|
36
|
-
defined_class = Class.new {
|
37
|
-
def self.class_in_namespace_one; NamespaceOne::UndefinedClass; end
|
38
|
-
def self.class_in_namespace_two; NamespaceTwo::UndefinedClass; end
|
39
|
-
}
|
40
|
-
assert ! defined_class.class_in_namespace_one.equal?(defined_class.class_in_namespace_two)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_refer_to_same_class_within_instance_under_test
|
44
|
-
defined_class = Class.new(UndefinedClassOne) { def undefined_class_two; UndefinedClassTwo; end }
|
45
|
-
instance = defined_class.new
|
46
|
-
assert_same UndefinedClassTwo, instance.undefined_class_two
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_verify_all_root_mochas_when_second_method_is_not_called
|
50
|
-
ClassOne.expects(:first)
|
51
|
-
ClassTwo.expects(:second)
|
52
|
-
ClassOne.first
|
53
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
54
|
-
verify_all
|
55
|
-
}
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_should_verify_all_root_mochas_when_first_method_is_not_called
|
59
|
-
ClassOne.expects(:first)
|
60
|
-
ClassTwo.expects(:second)
|
61
|
-
ClassTwo.second
|
62
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
63
|
-
verify_all
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_should_verify_all_namespaced_mochas_when_second_method_is_not_called
|
68
|
-
NamespaceOne::ClassOne.expects(:first)
|
69
|
-
NamespaceTwo::ClassTwo.expects(:second)
|
70
|
-
NamespaceOne::ClassOne.first
|
71
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
72
|
-
verify_all
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_should_verify_all_namespaced_mochas_when_first_method_is_not_called
|
77
|
-
NamespaceOne::ClassOne.expects(:first)
|
78
|
-
NamespaceTwo::ClassTwo.expects(:second)
|
79
|
-
NamespaceTwo::ClassTwo.second
|
80
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
81
|
-
verify_all
|
82
|
-
}
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
@@ -1,179 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
-
require 'auto_mocha/mock_class'
|
3
|
-
|
4
|
-
class MockClassTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include Mocha
|
7
|
-
|
8
|
-
def test_should_not_expect_unexpected_class_method_call
|
9
|
-
klass = MockClass.dup
|
10
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
11
|
-
klass.unexpected_class_method
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_should_expect_expected_class_method_call
|
16
|
-
klass = MockClass.dup
|
17
|
-
klass.expects(:expected_class_method)
|
18
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) {
|
19
|
-
klass.expected_class_method
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_should_fail_verification_for_missing_class_method_call
|
24
|
-
klass = MockClass.dup
|
25
|
-
klass.expects(:expected_class_method)
|
26
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
27
|
-
klass.verify
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_should_verify_expected_class_method_call
|
32
|
-
klass = MockClass.dup
|
33
|
-
klass.expects(:expected_class_method)
|
34
|
-
klass.expected_class_method
|
35
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) {
|
36
|
-
klass.verify
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_not_expect_unexpected_child_class_method_call
|
41
|
-
parent_class = MockClass.dup
|
42
|
-
child_class = Class.new(parent_class)
|
43
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
44
|
-
child_class.unexpected_child_class_method
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_should_expect_child_class_method_call
|
49
|
-
parent_class = MockClass.dup
|
50
|
-
child_class = Class.new(parent_class)
|
51
|
-
child_class.expects(:expected_child_class_method)
|
52
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) {
|
53
|
-
child_class.expected_child_class_method
|
54
|
-
}
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_should_fail_verification_for_missing_child_class_method_call
|
58
|
-
parent_class = MockClass.dup
|
59
|
-
child_class = Class.new(parent_class)
|
60
|
-
child_class.expects(:expected_child_class_method)
|
61
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
62
|
-
child_class.verify
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_should_verify_expected_child_class_method_call
|
67
|
-
parent_class = MockClass.dup
|
68
|
-
child_class = Class.new(parent_class)
|
69
|
-
child_class.expects(:expected_child_class_method)
|
70
|
-
child_class.expected_child_class_method
|
71
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) {
|
72
|
-
child_class.verify
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_should_not_expect_unexpected_parent_class_method_call
|
77
|
-
parent_class = MockClass.dup
|
78
|
-
child_class = Class.new(parent_class)
|
79
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
80
|
-
child_class.unexpected_parent_class_method
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_should_expect_parent_class_method_call
|
85
|
-
parent_class = MockClass.dup
|
86
|
-
child_class = Class.new(parent_class)
|
87
|
-
parent_class.expects(:expected_parent_class_method)
|
88
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) {
|
89
|
-
child_class.expected_parent_class_method
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_should_fail_verification_for_missing_parent_class_method
|
94
|
-
parent_class = MockClass.dup
|
95
|
-
child_class = Class.new(parent_class)
|
96
|
-
parent_class.expects(:expected_parent_class_method)
|
97
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
98
|
-
parent_class.verify
|
99
|
-
}
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_should_verify_expected_parent_class_method_call_from_child_class
|
103
|
-
parent_class = MockClass.dup
|
104
|
-
child_class = Class.new(parent_class)
|
105
|
-
parent_class.expects(:expected_parent_class_method)
|
106
|
-
child_class.expected_parent_class_method
|
107
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) {
|
108
|
-
parent_class.verify
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_should_have_different_expectations_for_different_descendant_classes
|
113
|
-
klass1 = MockClass.dup
|
114
|
-
klass2 = MockClass.dup
|
115
|
-
klass2.expects(:my_class_method)
|
116
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
117
|
-
klass1.my_class_method
|
118
|
-
}
|
119
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) {
|
120
|
-
klass2.my_class_method
|
121
|
-
}
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_should_allow_mocking_of_class_constructor
|
125
|
-
klass = MockClass.dup
|
126
|
-
expected_instance = Object.new
|
127
|
-
klass.expects(:new).returns(expected_instance)
|
128
|
-
assert_same expected_instance, klass.new
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_should_use_original_constructor_for_derived_classes
|
132
|
-
parent_class = MockClass.dup
|
133
|
-
child_class = Class.new(parent_class) { attr_reader :p1, :p2; def initialize(p1, p2); @p1, @p2 = p1, p2; end }
|
134
|
-
child_instance = child_class.new(1, 2)
|
135
|
-
assert_equal 1, child_instance.p1
|
136
|
-
assert_equal 2, child_instance.p2
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_should_not_expect_unexpected_parent_instance_method_call
|
140
|
-
parent_class = MockClass.dup
|
141
|
-
child_class = Class.new(parent_class)
|
142
|
-
child_instance = child_class.new
|
143
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
144
|
-
child_instance.unexpected_parent_instance_method
|
145
|
-
}
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_should_expect_expected_parent_instance_method_call
|
149
|
-
parent_class = MockClass.dup
|
150
|
-
child_class = Class.new(parent_class)
|
151
|
-
child_instance = child_class.new
|
152
|
-
child_instance.expects(:expected_parent_instance_method)
|
153
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) {
|
154
|
-
child_instance.expected_parent_instance_method
|
155
|
-
}
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_should_fail_verification_for_missing_parent_instance_method
|
159
|
-
parent_class = MockClass.dup
|
160
|
-
child_class = Class.new(parent_class)
|
161
|
-
child_instance = child_class.new
|
162
|
-
child_instance.expects(:expected_parent_instance_method)
|
163
|
-
assert_raise(Test::Unit::AssertionFailedError) {
|
164
|
-
child_instance.verify
|
165
|
-
}
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_should_verify_expected_parent_class_method_call_from_child_class
|
169
|
-
parent_class = MockClass.dup
|
170
|
-
child_class = Class.new(parent_class)
|
171
|
-
child_instance = child_class.new
|
172
|
-
child_instance.expects(:expected_parent_instance_method)
|
173
|
-
child_instance.expected_parent_instance_method
|
174
|
-
assert_nothing_raised(Test::Unit::AssertionFailedError) {
|
175
|
-
child_instance.verify
|
176
|
-
}
|
177
|
-
end
|
178
|
-
|
179
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'auto_mocha'
|
3
|
-
|
4
|
-
class Product < ActiveRecord::Base
|
5
|
-
|
6
|
-
def self.released_since(cutoff_date)
|
7
|
-
find(:all, :conditions => ['release_date > :date', {:date => cutoff_date}])
|
8
|
-
end
|
9
|
-
|
10
|
-
def sales_with_price_exceeding(price_threshold)
|
11
|
-
sales.select { |sale| sale.price > price_threshold }
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
class AutoMockAcceptanceTest < Test::Unit::TestCase
|
17
|
-
|
18
|
-
def test_should_find_all_products_released_since_specified_date
|
19
|
-
new_releases = [Product.new]
|
20
|
-
Product.expects(:find).with(:all, :conditions => ['release_date > :date', {:date => :cutoff_date}]).returns(new_releases)
|
21
|
-
assert_equal new_releases, Product.released_since(:cutoff_date)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_find_sales_for_this_product_which_exceeded_specified_price
|
25
|
-
product = Product.new
|
26
|
-
cheap_order = Mocha::Mock.new
|
27
|
-
cheap_order.expects(:price).returns(5)
|
28
|
-
expensive_order = Mocha::Mock.new
|
29
|
-
expensive_order.expects(:price).returns(15)
|
30
|
-
orders = [cheap_order, expensive_order]
|
31
|
-
product.expects(:sales).returns(orders)
|
32
|
-
assert_equal [expensive_order], product.sales_with_price_exceeding(10)
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|