bourne 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,24 +5,24 @@ require 'set'
5
5
  require 'simple_counter'
6
6
 
7
7
  class MockTest < Test::Unit::TestCase
8
-
8
+
9
9
  include Mocha
10
-
10
+
11
11
  def test_should_set_single_expectation
12
12
  mock = build_mock
13
13
  mock.expects(:method1).returns(1)
14
14
  assert_nothing_raised(ExpectationError) do
15
15
  assert_equal 1, mock.method1
16
16
  end
17
- end
17
+ end
18
18
 
19
19
  def test_should_build_and_store_expectations
20
20
  mock = build_mock
21
21
  expectation = mock.expects(:method1)
22
22
  assert_not_nil expectation
23
- assert_equal [expectation], mock.expectations.to_a
23
+ assert_equal [expectation], mock.__expectations__.to_a
24
24
  end
25
-
25
+
26
26
  def test_should_not_stub_everything_by_default
27
27
  mock = build_mock
28
28
  assert_equal false, mock.everything_stubbed
@@ -33,71 +33,71 @@ class MockTest < Test::Unit::TestCase
33
33
  mock.stub_everything
34
34
  assert_equal true, mock.everything_stubbed
35
35
  end
36
-
36
+
37
37
  def test_should_be_able_to_extend_mock_object_with_module
38
38
  mock = build_mock
39
39
  assert_nothing_raised(ExpectationError) { mock.extend(Module.new) }
40
40
  end
41
-
41
+
42
42
  def test_should_be_equal
43
43
  mock = build_mock
44
44
  assert_equal true, mock.eql?(mock)
45
45
  end
46
-
46
+
47
47
  if RUBY_VERSION < '1.9'
48
48
  OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ }
49
49
  else
50
50
  OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ || m == :object_id }
51
51
  end
52
-
52
+
53
53
  def test_should_be_able_to_mock_standard_object_methods
54
54
  mock = build_mock
55
55
  OBJECT_METHODS.each { |method| mock.__expects__(method.to_sym).returns(method) }
56
56
  OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) }
57
57
  assert mock.__verified__?
58
58
  end
59
-
59
+
60
60
  def test_should_be_able_to_stub_standard_object_methods
61
61
  mock = build_mock
62
62
  OBJECT_METHODS.each { |method| mock.__stubs__(method.to_sym).returns(method) }
63
63
  OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) }
64
64
  end
65
-
65
+
66
66
  def test_should_create_and_add_expectations
67
67
  mock = build_mock
68
68
  expectation1 = mock.expects(:method1)
69
69
  expectation2 = mock.expects(:method2)
70
- assert_equal [expectation1, expectation2].to_set, mock.expectations.to_set
70
+ assert_equal [expectation1, expectation2].to_set, mock.__expectations__.to_set
71
71
  end
72
-
72
+
73
73
  def test_should_pass_backtrace_into_expectation
74
74
  mock = build_mock
75
75
  backtrace = Object.new
76
76
  expectation = mock.expects(:method1, backtrace)
77
77
  assert_equal backtrace, expectation.backtrace
78
78
  end
79
-
79
+
80
80
  def test_should_pass_backtrace_into_stub
81
81
  mock = build_mock
82
82
  backtrace = Object.new
83
83
  stub = mock.stubs(:method1, backtrace)
84
84
  assert_equal backtrace, stub.backtrace
85
85
  end
86
-
86
+
87
87
  def test_should_create_and_add_stubs
88
88
  mock = build_mock
89
89
  stub1 = mock.stubs(:method1)
90
90
  stub2 = mock.stubs(:method2)
91
- assert_equal [stub1, stub2].to_set, mock.expectations.to_set
91
+ assert_equal [stub1, stub2].to_set, mock.__expectations__.to_set
92
92
  end
93
-
93
+
94
94
  def test_should_invoke_expectation_and_return_result
95
95
  mock = build_mock
96
96
  mock.expects(:my_method).returns(:result)
97
97
  result = mock.my_method
98
98
  assert_equal :result, result
99
99
  end
100
-
100
+
101
101
  def test_should_not_raise_error_if_stubbing_everything
102
102
  mock = build_mock
103
103
  mock.stub_everything
@@ -107,7 +107,7 @@ class MockTest < Test::Unit::TestCase
107
107
  end
108
108
  assert_nil result
109
109
  end
110
-
110
+
111
111
  def test_should_raise_assertion_error_for_unexpected_method_call
112
112
  mock = build_mock
113
113
  error = assert_raise(ExpectationError) do
@@ -118,7 +118,7 @@ class MockTest < Test::Unit::TestCase
118
118
  assert_match(/argument1/, error.message)
119
119
  assert_match(/argument2/, error.message)
120
120
  end
121
-
121
+
122
122
  def test_should_not_verify_successfully_because_not_all_expectations_have_been_satisfied
123
123
  mock = build_mock
124
124
  mock.expects(:method1)
@@ -126,23 +126,23 @@ class MockTest < Test::Unit::TestCase
126
126
  mock.method1
127
127
  assert !mock.__verified__?
128
128
  end
129
-
129
+
130
130
  def test_should_increment_assertion_counter_for_every_verified_expectation
131
131
  mock = build_mock
132
-
132
+
133
133
  mock.expects(:method1)
134
134
  mock.method1
135
-
135
+
136
136
  mock.expects(:method2)
137
137
  mock.method2
138
-
138
+
139
139
  assertion_counter = SimpleCounter.new
140
-
140
+
141
141
  mock.__verified__?(assertion_counter)
142
-
142
+
143
143
  assert_equal 2, assertion_counter.count
144
144
  end
145
-
145
+
146
146
  def test_should_yield_supplied_parameters_to_block
147
147
  mock = build_mock
148
148
  parameters_for_yield = [1, 2, 3]
@@ -151,35 +151,35 @@ class MockTest < Test::Unit::TestCase
151
151
  mock.method1() { |*parameters| yielded_parameters = parameters }
152
152
  assert_equal parameters_for_yield, yielded_parameters
153
153
  end
154
-
154
+
155
155
  def test_should_set_up_multiple_expectations_with_return_values
156
156
  mock = build_mock
157
157
  mock.expects(:method1 => :result1, :method2 => :result2)
158
158
  assert_equal :result1, mock.method1
159
159
  assert_equal :result2, mock.method2
160
160
  end
161
-
161
+
162
162
  def test_should_set_up_multiple_stubs_with_return_values
163
163
  mock = build_mock
164
164
  mock.stubs(:method1 => :result1, :method2 => :result2)
165
165
  assert_equal :result1, mock.method1
166
166
  assert_equal :result2, mock.method2
167
167
  end
168
-
168
+
169
169
  def test_should_keep_returning_specified_value_for_stubs
170
170
  mock = build_mock
171
171
  mock.stubs(:method1).returns(1)
172
172
  assert_equal 1, mock.method1
173
173
  assert_equal 1, mock.method1
174
174
  end
175
-
175
+
176
176
  def test_should_keep_returning_specified_value_for_expects
177
177
  mock = build_mock
178
178
  mock.expects(:method1).times(2).returns(1)
179
179
  assert_equal 1, mock.method1
180
180
  assert_equal 1, mock.method1
181
181
  end
182
-
182
+
183
183
  def test_should_match_most_recent_call_to_expects
184
184
  mock = build_mock
185
185
  mock.expects(:method1).returns(0)
@@ -207,18 +207,18 @@ class MockTest < Test::Unit::TestCase
207
207
  mock.stubs(:method1).returns(1)
208
208
  assert_equal 1, mock.method1
209
209
  end
210
-
210
+
211
211
  def test_should_respond_to_expected_method
212
212
  mock = build_mock
213
213
  mock.expects(:method1)
214
214
  assert_equal true, mock.respond_to?(:method1)
215
215
  end
216
-
216
+
217
217
  def test_should_not_respond_to_unexpected_method
218
218
  mock = build_mock
219
219
  assert_equal false, mock.respond_to?(:method1)
220
220
  end
221
-
221
+
222
222
  def test_should_respond_to_methods_which_the_responder_does_responds_to
223
223
  instance = Class.new do
224
224
  define_method(:respond_to?) { |symbol| true }
@@ -227,7 +227,7 @@ class MockTest < Test::Unit::TestCase
227
227
  mock.responds_like(instance)
228
228
  assert_equal true, mock.respond_to?(:invoked_method)
229
229
  end
230
-
230
+
231
231
  def test_should_not_respond_to_methods_which_the_responder_does_not_responds_to
232
232
  instance = Class.new do
233
233
  define_method(:respond_to?) { |symbol| false }
@@ -236,18 +236,18 @@ class MockTest < Test::Unit::TestCase
236
236
  mock.responds_like(instance)
237
237
  assert_equal false, mock.respond_to?(:invoked_method)
238
238
  end
239
-
239
+
240
240
  def test_should_return_itself_to_allow_method_chaining
241
241
  mock = build_mock
242
242
  assert_same mock.responds_like(Object.new), mock
243
243
  end
244
-
244
+
245
245
  def test_should_not_raise_no_method_error_if_mock_is_not_restricted_to_respond_like_a_responder
246
246
  mock = build_mock
247
247
  mock.stubs(:invoked_method)
248
248
  assert_nothing_raised(NoMethodError) { mock.invoked_method }
249
249
  end
250
-
250
+
251
251
  def test_should_not_raise_no_method_error_if_responder_does_respond_to_invoked_method
252
252
  instance = Class.new do
253
253
  define_method(:respond_to?) { |symbol| true }
@@ -257,7 +257,7 @@ class MockTest < Test::Unit::TestCase
257
257
  mock.stubs(:invoked_method)
258
258
  assert_nothing_raised(NoMethodError) { mock.invoked_method }
259
259
  end
260
-
260
+
261
261
  def test_should_raise_no_method_error_if_responder_does_not_respond_to_invoked_method
262
262
  instance = Class.new do
263
263
  define_method(:respond_to?) { |symbol| false }
@@ -268,7 +268,7 @@ class MockTest < Test::Unit::TestCase
268
268
  mock.stubs(:invoked_method)
269
269
  assert_raises(NoMethodError) { mock.invoked_method }
270
270
  end
271
-
271
+
272
272
  def test_should_raise_no_method_error_with_message_indicating_that_mock_is_constrained_to_respond_like_responder
273
273
  instance = Class.new do
274
274
  define_method(:respond_to?) { |symbol| false }
@@ -283,12 +283,12 @@ class MockTest < Test::Unit::TestCase
283
283
  assert_match(/which responds like mocha_inspect/, e.message)
284
284
  end
285
285
  end
286
-
286
+
287
287
  def test_should_handle_respond_to_with_private_methods_param_without_error
288
288
  mock = build_mock
289
289
  assert_nothing_raised{ mock.respond_to?(:object_id, false) }
290
290
  end
291
-
291
+
292
292
  def test_should_respond_to_any_method_if_stubbing_everything
293
293
  mock = build_mock
294
294
  mock.stub_everything
@@ -325,7 +325,7 @@ class MockTest < Test::Unit::TestCase
325
325
  args = [1, 2]
326
326
  mock = Mock.new(method)
327
327
  expectation = FakeExpectation.new
328
- mock.expectations.add expectation
328
+ mock.__expectations__.add expectation
329
329
  mock.send(method, *args)
330
330
  assert_equal args, expectation.args
331
331
  end
@@ -4,28 +4,28 @@ require 'mocha/state_machine'
4
4
  require 'bourne/invocation'
5
5
 
6
6
  class MockeryTest < Test::Unit::TestCase
7
-
7
+
8
8
  include Mocha
9
-
9
+
10
10
  def test_should_build_instance_of_mockery
11
11
  mockery = Mockery.instance
12
12
  assert_not_nil mockery
13
13
  assert_kind_of Mockery, mockery
14
14
  end
15
-
15
+
16
16
  def test_should_cache_instance_of_mockery
17
17
  mockery_1 = Mockery.instance
18
18
  mockery_2 = Mockery.instance
19
19
  assert_same mockery_1, mockery_2
20
20
  end
21
-
21
+
22
22
  def test_should_expire_mockery_instance_cache
23
23
  mockery_1 = Mockery.instance
24
24
  Mockery.reset_instance
25
25
  mockery_2 = Mockery.instance
26
26
  assert_not_same mockery_1, mockery_2
27
27
  end
28
-
28
+
29
29
  def test_should_raise_expectation_error_because_not_all_expectations_are_satisfied
30
30
  mockery = Mockery.new
31
31
  mock_1 = mockery.named_mock('mock-1') { expects(:method_1) }
@@ -34,20 +34,20 @@ class MockeryTest < Test::Unit::TestCase
34
34
  0.times { mock_2.method_2 }
35
35
  assert_raises(ExpectationError) { mockery.verify }
36
36
  end
37
-
37
+
38
38
  def test_should_reset_list_of_mocks_on_teardown
39
39
  mockery = Mockery.new
40
40
  mock = mockery.unnamed_mock { expects(:my_method) }
41
41
  mockery.teardown
42
42
  assert_nothing_raised(ExpectationError) { mockery.verify }
43
43
  end
44
-
44
+
45
45
  def test_should_build_instance_of_stubba_on_instantiation
46
46
  mockery = Mockery.new
47
47
  assert_not_nil mockery.stubba
48
48
  assert_kind_of Central, mockery.stubba
49
49
  end
50
-
50
+
51
51
  def test_should_build_new_instance_of_stubba_on_teardown
52
52
  mockery = Mockery.new
53
53
  stubba_1 = mockery.stubba
@@ -55,27 +55,27 @@ class MockeryTest < Test::Unit::TestCase
55
55
  stubba_2 = mockery.stubba
56
56
  assert_not_same stubba_1, stubba_2
57
57
  end
58
-
58
+
59
59
  def test_should_build_and_store_new_state_machine
60
60
  mockery = Mockery.new
61
61
  mockery.new_state_machine('state-machine-name')
62
62
  assert_equal 1, mockery.state_machines.length
63
63
  assert_kind_of StateMachine, mockery.state_machines[0]
64
64
  end
65
-
65
+
66
66
  def test_should_reset_list_of_state_machines_on_teardown
67
67
  mockery = Mockery.new
68
68
  mockery.new_state_machine('state-machine-name')
69
69
  mockery.teardown
70
70
  assert_equal 0, mockery.state_machines.length
71
71
  end
72
-
72
+
73
73
  class FakeMethod
74
74
  def stub; end
75
75
  def unstub; end
76
76
  def matches?(other); true; end
77
77
  end
78
-
78
+
79
79
  def test_should_unstub_all_methods_on_teardown
80
80
  mockery = Mockery.new
81
81
  stubba = mockery.stubba
@@ -83,65 +83,65 @@ class MockeryTest < Test::Unit::TestCase
83
83
  mockery.teardown
84
84
  assert stubba.stubba_methods.empty?
85
85
  end
86
-
86
+
87
87
  def test_should_display_object_id_for_mocha_inspect_if_mock_has_no_name
88
88
  mockery = Mockery.new
89
89
  mock = mockery.unnamed_mock
90
90
  assert_match Regexp.new("^#<Mock:0x[0-9A-Fa-f]{1,12}>$"), mock.mocha_inspect
91
91
  end
92
-
92
+
93
93
  def test_should_display_object_id_for_inspect_if_mock_has_no_name
94
94
  mockery = Mockery.new
95
95
  mock = mockery.unnamed_mock
96
96
  assert_match Regexp.new("^#<Mock:0x[0-9A-Fa-f]{1,12}>$"), mock.inspect
97
97
  end
98
-
98
+
99
99
  def test_should_display_name_for_mocha_inspect_if_mock_has_string_name
100
100
  mockery = Mockery.new
101
101
  mock = mockery.named_mock('named_mock')
102
102
  assert_equal "#<Mock:named_mock>", mock.mocha_inspect
103
103
  end
104
-
104
+
105
105
  def test_should_display_name_for_mocha_inspect_if_mock_has_symbol_name
106
106
  mockery = Mockery.new
107
107
  mock = mockery.named_mock(:named_mock)
108
108
  assert_equal "#<Mock:named_mock>", mock.mocha_inspect
109
109
  end
110
-
110
+
111
111
  def test_should_display_name_for_inspect_if_mock_has_string_name
112
112
  mockery = Mockery.new
113
113
  mock = mockery.named_mock('named_mock')
114
114
  assert_equal "#<Mock:named_mock>", mock.inspect
115
115
  end
116
-
116
+
117
117
  def test_should_display_name_for_inspect_if_mock_has_symbol_name
118
118
  mockery = Mockery.new
119
119
  mock = mockery.named_mock(:named_mock)
120
120
  assert_equal "#<Mock:named_mock>", mock.inspect
121
121
  end
122
-
122
+
123
123
  def test_should_display_impersonated_object_for_mocha_inspect
124
124
  mockery = Mockery.new
125
125
  instance = Object.new
126
126
  mock = mockery.mock_impersonating(instance)
127
127
  assert_equal "#{instance.mocha_inspect}", mock.mocha_inspect
128
128
  end
129
-
129
+
130
130
  def test_should_display_impersonated_object_for_inspect
131
131
  mockery = Mockery.new
132
132
  instance = Object.new
133
133
  mock = mockery.mock_impersonating(instance)
134
134
  assert_equal "#{instance.mocha_inspect}", mock.inspect
135
135
  end
136
-
136
+
137
137
  class FakeClass; end
138
-
138
+
139
139
  def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_mocha_inspect
140
140
  mockery = Mockery.new
141
141
  mock = mockery.mock_impersonating_any_instance_of(FakeClass)
142
142
  assert_equal "#<AnyInstance:MockeryTest::FakeClass>", mock.mocha_inspect
143
143
  end
144
-
144
+
145
145
  def test_should_display_any_instance_prefix_followed_by_class_whose_instances_are_being_impersonated_for_inspect
146
146
  mockery = Mockery.new
147
147
  mock = mockery.mock_impersonating_any_instance_of(FakeClass)
@@ -160,5 +160,5 @@ class MockeryTest < Test::Unit::TestCase
160
160
  assert_equal method, invocation.method_name
161
161
  assert_equal args, invocation.arguments
162
162
  end
163
-
163
+
164
164
  end