bourne 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_dependency('mocha', '0.13.2') # follow instructions in mock.rb to update
23
+ s.add_dependency('mocha', '~> 0.13.2') # follow instructions in mock.rb to update
24
24
 
25
25
  s.add_development_dependency('rake')
26
26
  end
@@ -41,7 +41,7 @@ module Mocha # :nodoc:
41
41
  @expectations.each do |method, args, block|
42
42
  @expectation.send(method, *args, &block)
43
43
  end
44
- @expectation.invocation_count = invocation_count
44
+ invocation_count.times { @expectation.invoke }
45
45
  @expectation.verified?
46
46
  end
47
47
 
@@ -72,7 +72,7 @@ module Mocha # :nodoc:
72
72
 
73
73
  def invocations
74
74
  Mockery.instance.invocations.select do |invocation|
75
- invocation.mock.equal?(@mock)
75
+ invocation.mock.equal?(@mock) || invocation.mock.mocha.equal?(@mock)
76
76
  end
77
77
  end
78
78
 
@@ -1,36 +1,13 @@
1
1
  require 'mocha/mock'
2
- require 'bourne/expectation'
3
- require 'mocha/expectation_error_factory'
4
2
 
5
3
  module Mocha # :nodoc:
6
- # Overwrites #method_missing on Mocha::Mock
7
- # - pass arguments to .invoke() calls to create Invocation
8
- # - keep lowest else branch (bourne code)
9
- # - update from https://github.com/freerange/mocha/blob/master/lib/mocha/mock.rb#L227
10
- # - update test/unit/mock_test.rb
4
+ # Extends #method_missing on Mocha::Mock to record Invocations.
11
5
  class Mock # :nodoc:
6
+ alias_method :method_missing_without_invocation, :method_missing
7
+
12
8
  def method_missing(symbol, *arguments, &block)
13
- if @responder and not @responder.respond_to?(symbol)
14
- raise NoMethodError, "undefined method `#{symbol}' for #{self.mocha_inspect} which responds like #{@responder.mocha_inspect}"
15
- end
16
- if matching_expectation_allowing_invocation = @expectations.match_allowing_invocation(symbol, *arguments)
17
- matching_expectation_allowing_invocation.invoke(arguments, &block)
18
- else
19
- if (matching_expectation = @expectations.match(symbol, *arguments)) || (!matching_expectation && !@everything_stubbed)
20
- matching_expectation.invoke(arguments, &block) if matching_expectation
21
- message = UnexpectedInvocation.new(self, symbol, *arguments).to_s
22
- message << @mockery.mocha_inspect
23
- raise ExpectationErrorFactory.build(message, caller)
24
- else
25
- target = if self.respond_to? :mocha
26
- self.mocha
27
- else
28
- mocha
29
- end
30
- Mockery.instance.invocation(target, symbol, arguments)
31
- nil
32
- end
33
- end
9
+ Mockery.instance.invocation(self, symbol, arguments)
10
+ method_missing_without_invocation(symbol, *arguments, &block)
34
11
  end
35
12
  end
36
13
  end
@@ -1,3 +1,3 @@
1
1
  module Bourne
2
- VERSION = '1.3.2'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
@@ -340,8 +340,7 @@ class MockTest < Test::Unit::TestCase
340
340
  class FakeExpectation
341
341
  attr_reader :args
342
342
 
343
- def invoke(args)
344
- @args = args
343
+ def invoke
345
344
  end
346
345
 
347
346
  def match?(*args)
@@ -360,7 +359,6 @@ class MockTest < Test::Unit::TestCase
360
359
  expectation = FakeExpectation.new
361
360
  mock.__expectations__.add expectation
362
361
  mock.send(method, *args)
363
- assert_equal args, expectation.args
364
362
  end
365
363
 
366
364
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bourne
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,14 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-15 00:00:00.000000000 Z
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mocha
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - '='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
21
  version: 0.13.2
22
22
  type: :runtime
@@ -24,7 +24,7 @@ dependencies:
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - '='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.13.2
30
30
  - !ruby/object:Gem::Dependency
@@ -61,7 +61,6 @@ files:
61
61
  - bourne.gemspec
62
62
  - lib/bourne.rb
63
63
  - lib/bourne/api.rb
64
- - lib/bourne/expectation.rb
65
64
  - lib/bourne/invocation.rb
66
65
  - lib/bourne/mock.rb
67
66
  - lib/bourne/mockery.rb
@@ -78,7 +77,6 @@ files:
78
77
  - test/test_helper.rb
79
78
  - test/test_runner.rb
80
79
  - test/unit/assert_received_test.rb
81
- - test/unit/expectation_test.rb
82
80
  - test/unit/have_received_test.rb
83
81
  - test/unit/invocation_test.rb
84
82
  - test/unit/mock_test.rb
@@ -103,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
101
  version: '0'
104
102
  requirements: []
105
103
  rubyforge_project:
106
- rubygems_version: 1.8.23
104
+ rubygems_version: 1.8.25
107
105
  signing_key:
108
106
  specification_version: 3
109
107
  summary: Adds test spies to mocha.
@@ -120,9 +118,7 @@ test_files:
120
118
  - test/test_helper.rb
121
119
  - test/test_runner.rb
122
120
  - test/unit/assert_received_test.rb
123
- - test/unit/expectation_test.rb
124
121
  - test/unit/have_received_test.rb
125
122
  - test/unit/invocation_test.rb
126
123
  - test/unit/mock_test.rb
127
124
  - test/unit/mockery_test.rb
128
- has_rdoc:
@@ -1,23 +0,0 @@
1
- require 'mocha/expectation'
2
-
3
- module Mocha # :nodoc:
4
- # Extends Mocha::Expectation to record the full arguments and count whenver a
5
- # stubbed or mocked method is invoked.
6
- class Expectation # :nodoc:
7
- attr_accessor :invocation_count
8
-
9
- def invoke_with_args(args, &block)
10
- Mockery.instance.invocation(@mock, method_name, args)
11
- invoke_without_args(&block)
12
- end
13
-
14
- alias_method :invoke_without_args, :invoke
15
- alias_method :invoke, :invoke_with_args
16
-
17
- private
18
-
19
- def method_name
20
- @method_matcher.expected_method_name
21
- end
22
- end
23
- end
@@ -1,530 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
- require 'method_definer'
3
- require 'bourne/expectation'
4
- require 'mocha/sequence'
5
- require 'bourne/mockery'
6
- require 'execution_point'
7
- require 'simple_counter'
8
-
9
- class ExpectationTest < Test::Unit::TestCase
10
-
11
- include Mocha
12
-
13
- class FakeMockery
14
- attr_reader :invocations
15
-
16
- def initialize
17
- @invocations = []
18
- end
19
-
20
- def invocation(mock, method_name, args)
21
- @invocations << { :mock => mock, :method_name => method_name, :args => args }
22
- end
23
-
24
- def verify(assertion_counter = nil)
25
- end
26
- end
27
-
28
- def setup
29
- Mockery.instance_variable_set('@instance', FakeMockery.new)
30
- end
31
-
32
- def teardown
33
- Mockery.reset_instance
34
- end
35
-
36
- def new_expectation
37
- Expectation.new(nil, :expected_method)
38
- end
39
-
40
- def test_should_match_calls_to_same_method_with_any_parameters
41
- assert new_expectation.match?(:expected_method, 1, 2, 3)
42
- end
43
-
44
- def test_should_match_calls_to_same_method_with_exactly_zero_parameters
45
- expectation = new_expectation.with()
46
- assert expectation.match?(:expected_method)
47
- end
48
-
49
- def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters
50
- expectation = new_expectation.with()
51
- assert !expectation.match?(:expected_method, 1, 2, 3)
52
- end
53
-
54
- def test_should_match_calls_to_same_method_with_expected_parameter_values
55
- expectation = new_expectation.with(1, 2, 3)
56
- assert expectation.match?(:expected_method, 1, 2, 3)
57
- end
58
-
59
- def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected
60
- expectation = new_expectation.with() {|x, y, z| x + y == z}
61
- assert expectation.match?(:expected_method, 1, 2, 3)
62
- end
63
-
64
- def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
65
- expectation = new_expectation.with() {|x, y, z| x + y == z}
66
- assert !expectation.match?(:different_method, 1, 2, 3)
67
- end
68
-
69
- def test_should_not_match_calls_to_different_methods_with_no_parameters
70
- assert !new_expectation.match?(:unexpected_method)
71
- end
72
-
73
- def test_should_not_match_calls_to_same_method_with_too_few_parameters
74
- expectation = new_expectation.with(1, 2, 3)
75
- assert !expectation.match?(:unexpected_method, 1, 2)
76
- end
77
-
78
- def test_should_not_match_calls_to_same_method_with_too_many_parameters
79
- expectation = new_expectation.with(1, 2)
80
- assert !expectation.match?(:unexpected_method, 1, 2, 3)
81
- end
82
-
83
- def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values
84
- expectation = new_expectation.with(1, 2, 3)
85
- assert !expectation.match?(:unexpected_method, 1, 0, 3)
86
- end
87
-
88
- def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected
89
- expectation = new_expectation.with() {|x, y, z| x + y == z}
90
- assert !expectation.match?(:expected_method, 1, 0, 3)
91
- end
92
-
93
- def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
94
- expectation = new_expectation.times(1)
95
- assert expectation.invocations_allowed?
96
- expectation.invoke([])
97
- assert !expectation.invocations_allowed?
98
- end
99
-
100
- def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three
101
- expectation = new_expectation.times(2)
102
- assert expectation.invocations_allowed?
103
- expectation.invoke([])
104
- assert expectation.invocations_allowed?
105
- expectation.invoke([])
106
- assert !expectation.invocations_allowed?
107
- end
108
-
109
- def test_should_allow_invocations_until_expected_invocation_count_is_a_range_from_two_to_three_and_actual_invocation_count_would_be_four
110
- expectation = new_expectation.times(2..3)
111
- assert expectation.invocations_allowed?
112
- expectation.invoke([])
113
- assert expectation.invocations_allowed?
114
- expectation.invoke([])
115
- assert expectation.invocations_allowed?
116
- expectation.invoke([])
117
- assert !expectation.invocations_allowed?
118
- end
119
-
120
- def test_should_store_provided_backtrace
121
- backtrace = Object.new
122
- expectation = Expectation.new(nil, :expected_method, backtrace)
123
- assert_equal backtrace, expectation.backtrace
124
- end
125
-
126
- def test_should_default_backtrace_to_caller
127
- execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
128
- assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
129
- end
130
-
131
- def test_should_not_yield
132
- yielded = false
133
- new_expectation.invoke([]) { yielded = true }
134
- assert_equal false, yielded
135
- end
136
-
137
- def test_should_yield_no_parameters
138
- expectation = new_expectation().yields()
139
- yielded_parameters = nil
140
- expectation.invoke([]) { |*parameters| yielded_parameters = parameters }
141
- assert_equal Array.new, yielded_parameters
142
- end
143
-
144
- def test_should_yield_with_specified_parameters
145
- expectation = new_expectation().yields(1, 2, 3)
146
- yielded_parameters = nil
147
- expectation.invoke([]) { |*parameters| yielded_parameters = parameters }
148
- assert_equal [1, 2, 3], yielded_parameters
149
- end
150
-
151
- def test_should_yield_different_parameters_on_consecutive_invocations
152
- expectation = new_expectation().yields(1, 2, 3).yields(4, 5)
153
- yielded_parameters = []
154
- expectation.invoke([]) { |*parameters| yielded_parameters << parameters }
155
- expectation.invoke([]) { |*parameters| yielded_parameters << parameters }
156
- assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
157
- end
158
-
159
- def test_should_yield_multiple_times_for_single_invocation
160
- expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5])
161
- yielded_parameters = []
162
- expectation.invoke([]) { |*parameters| yielded_parameters << parameters }
163
- assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
164
- end
165
-
166
- def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation
167
- expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7)
168
- yielded_parameters = []
169
- expectation.invoke([]) { |*parameters| yielded_parameters << parameters }
170
- expectation.invoke([]) { |*parameters| yielded_parameters << parameters }
171
- assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters
172
- end
173
-
174
- def test_should_return_specified_value
175
- expectation = new_expectation.returns(99)
176
- assert_equal 99, expectation.invoke([])
177
- end
178
-
179
- def test_should_return_same_specified_value_multiple_times
180
- expectation = new_expectation.returns(99)
181
- assert_equal 99, expectation.invoke([])
182
- assert_equal 99, expectation.invoke([])
183
- end
184
-
185
- def test_should_return_specified_values_on_consecutive_calls
186
- expectation = new_expectation.returns(99, 100, 101)
187
- assert_equal 99, expectation.invoke([])
188
- assert_equal 100, expectation.invoke([])
189
- assert_equal 101, expectation.invoke([])
190
- end
191
-
192
- def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified
193
- values = [99, 100, 101]
194
- expectation = new_expectation.returns(*values)
195
- values.shift
196
- assert_equal 99, expectation.invoke([])
197
- assert_equal 100, expectation.invoke([])
198
- assert_equal 101, expectation.invoke([])
199
- end
200
-
201
- def test_should_return_nil_by_default
202
- assert_nil new_expectation.invoke([])
203
- end
204
-
205
- def test_should_return_nil_if_no_value_specified
206
- expectation = new_expectation.returns()
207
- assert_nil expectation.invoke([])
208
- end
209
-
210
- def test_should_raise_runtime_exception
211
- expectation = new_expectation.raises
212
- assert_raise(RuntimeError) { expectation.invoke([]) }
213
- end
214
-
215
- def test_should_raise_custom_exception
216
- exception = Class.new(Exception)
217
- expectation = new_expectation.raises(exception)
218
- assert_raise(exception) { expectation.invoke([]) }
219
- end
220
-
221
- def test_should_raise_same_instance_of_custom_exception
222
- exception_klass = Class.new(StandardError)
223
- expected_exception = exception_klass.new
224
- expectation = new_expectation.raises(expected_exception)
225
- actual_exception = assert_raise(exception_klass) { expectation.invoke([]) }
226
- assert_same expected_exception, actual_exception
227
- end
228
-
229
- def test_should_use_the_default_exception_message
230
- expectation = new_expectation.raises(Exception)
231
- exception = assert_raise(Exception) { expectation.invoke([]) }
232
- assert_equal Exception.new.message, exception.message
233
- end
234
-
235
- def test_should_raise_custom_exception_with_message
236
- exception_msg = "exception message"
237
- expectation = new_expectation.raises(Exception, exception_msg)
238
- exception = assert_raise(Exception) { expectation.invoke([]) }
239
- assert_equal exception_msg, exception.message
240
- end
241
-
242
- def test_should_return_values_then_raise_exception
243
- expectation = new_expectation.returns(1, 2).then.raises()
244
- assert_equal 1, expectation.invoke([])
245
- assert_equal 2, expectation.invoke([])
246
- assert_raise(RuntimeError) { expectation.invoke([]) }
247
- end
248
-
249
- def test_should_raise_exception_then_return_values
250
- expectation = new_expectation.raises().then.returns(1, 2)
251
- assert_raise(RuntimeError) { expectation.invoke([]) }
252
- assert_equal 1, expectation.invoke([])
253
- assert_equal 2, expectation.invoke([])
254
- end
255
-
256
- def test_should_verify_successfully_if_expected_call_was_made
257
- expectation = new_expectation
258
- expectation.invoke([])
259
- assert expectation.verified?
260
- end
261
-
262
- def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice
263
- expectation = new_expectation.once
264
- expectation.invoke([])
265
- expectation.invoke([])
266
- assert !expectation.verified?
267
- end
268
-
269
- def test_should_not_verify_successfully_if_call_expected_once_but_not_invoked
270
- expectation = new_expectation.once
271
- assert !expectation.verified?
272
- end
273
-
274
- def test_should_verify_successfully_if_call_expected_once_and_invoked_once
275
- expectation = new_expectation.once
276
- expectation.invoke([])
277
- assert expectation.verified?
278
- end
279
-
280
- def test_should_not_verify_successfully_if_call_expected_twice_and_invoked_three_times
281
- expectation = new_expectation.twice
282
- expectation.invoke([])
283
- expectation.invoke([])
284
- expectation.invoke([])
285
- assert !expectation.verified?
286
- end
287
-
288
- def test_should_not_verify_successfully_if_call_expected_twice_but_invoked_once
289
- expectation = new_expectation.twice
290
- expectation.invoke([])
291
- assert !expectation.verified?
292
- end
293
-
294
- def test_should_verify_successfully_if_call_expected_twice_and_invoked_twice
295
- expectation = new_expectation.twice
296
- expectation.invoke([])
297
- expectation.invoke([])
298
- assert expectation.verified?
299
- end
300
-
301
- def test_should_verify_successfully_if_expected_call_was_made_at_least_once
302
- expectation = new_expectation.at_least_once
303
- 3.times {expectation.invoke([])}
304
- assert expectation.verified?
305
- end
306
-
307
- def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once
308
- expectation = new_expectation.with(1, 2, 3).at_least_once
309
- assert !expectation.verified?
310
- assert_match(/expected at least once, not yet invoked/i, expectation.mocha_inspect)
311
- end
312
-
313
- def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
314
- expectation = new_expectation.times(2)
315
- 2.times {expectation.invoke([])}
316
- assert expectation.verified?
317
- end
318
-
319
- def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times
320
- expectation = new_expectation.times(2)
321
- 1.times {expectation.invoke([])}
322
- assert !expectation.verified?
323
- assert_match(/expected exactly twice/i, expectation.mocha_inspect)
324
- assert_match(/invoked once/i, expectation.mocha_inspect)
325
- end
326
-
327
- def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times
328
- expectation = new_expectation.times(2)
329
- 3.times {expectation.invoke([])}
330
- assert !expectation.verified?
331
- end
332
-
333
- def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng
334
- expectation = new_expectation
335
- expectation.invoke([])
336
- assertion_counter = SimpleCounter.new
337
- expectation.verified?(assertion_counter)
338
- assert_equal 1, assertion_counter.count
339
- end
340
-
341
- def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying
342
- stub = Expectation.new(nil, :expected_method).at_least(0)
343
- assertion_counter = SimpleCounter.new
344
- stub.verified?(assertion_counter)
345
- assert_equal 0, assertion_counter.count
346
- end
347
-
348
- def test_should_store_backtrace_from_point_where_expectation_was_created
349
- execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
350
- assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
351
- end
352
-
353
- class FakeMock
354
-
355
- def initialize(name)
356
- @name = name
357
- end
358
-
359
- def mocha_inspect
360
- @name
361
- end
362
-
363
- end
364
-
365
- def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object_with_which_parameters_and_in_what_sequences
366
- mock = FakeMock.new('mock')
367
- sequence_one = Sequence.new('one')
368
- sequence_two = Sequence.new('two')
369
- expectation = Expectation.new(mock, :expected_method).with(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]).in_sequence(sequence_one, sequence_two)
370
- assert !expectation.verified?
371
- assert_match "mock.expected_method(1, 2, {'a' => true}, {:b => false}, [1, 2, 3]); in sequence 'one'; in sequence 'two'", expectation.mocha_inspect
372
- end
373
-
374
- class FakeConstraint
375
-
376
- def initialize(allows_invocation_now)
377
- @allows_invocation_now = allows_invocation_now
378
- end
379
-
380
- def allows_invocation_now?
381
- @allows_invocation_now
382
- end
383
-
384
- end
385
-
386
- def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now
387
- constraint_one = FakeConstraint.new(allows_invocation_now = true)
388
- constraint_two = FakeConstraint.new(allows_invocation_now = true)
389
- expectation = Expectation.new(nil, :method_one)
390
- expectation.add_ordering_constraint(constraint_one)
391
- expectation.add_ordering_constraint(constraint_two)
392
- assert expectation.in_correct_order?
393
- end
394
-
395
- def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now
396
- constraint_one = FakeConstraint.new(allows_invocation_now = true)
397
- constraint_two = FakeConstraint.new(allows_invocation_now = false)
398
- expectation = Expectation.new(nil, :method_one)
399
- expectation.add_ordering_constraint(constraint_one)
400
- expectation.add_ordering_constraint(constraint_two)
401
- assert !expectation.in_correct_order?
402
- end
403
-
404
- def test_should_match_if_all_ordering_constraints_allow_invocation_now
405
- constraint_one = FakeConstraint.new(allows_invocation_now = true)
406
- constraint_two = FakeConstraint.new(allows_invocation_now = true)
407
- expectation = Expectation.new(nil, :method_one)
408
- expectation.add_ordering_constraint(constraint_one)
409
- expectation.add_ordering_constraint(constraint_two)
410
- assert expectation.match?(:method_one)
411
- end
412
-
413
- def test_should_not_match_if_one_ordering_constraints_does_not_allow_invocation_now
414
- constraint_one = FakeConstraint.new(allows_invocation_now = true)
415
- constraint_two = FakeConstraint.new(allows_invocation_now = false)
416
- expectation = Expectation.new(nil, :method_one)
417
- expectation.add_ordering_constraint(constraint_one)
418
- expectation.add_ordering_constraint(constraint_two)
419
- assert !expectation.match?(:method_one)
420
- end
421
-
422
- def test_should_not_be_satisfied_when_required_invocation_has_not_been_made
423
- expectation = Expectation.new(nil, :method_one).times(1)
424
- assert !expectation.satisfied?
425
- end
426
-
427
- def test_should_be_satisfied_when_required_invocation_has_been_made
428
- expectation = Expectation.new(nil, :method_one).times(1)
429
- expectation.invoke([])
430
- assert expectation.satisfied?
431
- end
432
-
433
- def test_should_not_be_satisfied_when_minimum_number_of_invocations_has_not_been_made
434
- expectation = Expectation.new(nil, :method_one).at_least(2)
435
- expectation.invoke([])
436
- assert !expectation.satisfied?
437
- end
438
-
439
- def test_should_be_satisfied_when_minimum_number_of_invocations_has_been_made
440
- expectation = Expectation.new(nil, :method_one).at_least(2)
441
- 2.times { expectation.invoke([]) }
442
- assert expectation.satisfied?
443
- end
444
-
445
- class FakeSequence
446
-
447
- attr_reader :expectations
448
-
449
- def initialize
450
- @expectations = []
451
- end
452
-
453
- def constrain_as_next_in_sequence(expectation)
454
- @expectations << expectation
455
- end
456
-
457
- end
458
-
459
- def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence
460
- sequence_one = FakeSequence.new
461
- sequence_two = FakeSequence.new
462
- expectation = Expectation.new(nil, :method_one)
463
- assert_equal expectation, expectation.in_sequence(sequence_one, sequence_two)
464
- assert_equal [expectation], sequence_one.expectations
465
- assert_equal [expectation], sequence_two.expectations
466
- end
467
-
468
- class FakeState
469
-
470
- def initialize
471
- @active = false
472
- end
473
-
474
- def activate
475
- @active = true
476
- end
477
-
478
- def active?
479
- @active
480
- end
481
-
482
- end
483
-
484
- def test_should_change_state_when_expectation_is_invoked
485
- state = FakeState.new
486
- expectation = Expectation.new(nil, :method_one)
487
-
488
- expectation.then(state)
489
-
490
- expectation.invoke([])
491
- assert state.active?
492
- end
493
-
494
- def test_should_match_when_state_is_active
495
- state = FakeState.new
496
- expectation = Expectation.new(nil, :method_one)
497
-
498
- expectation.when(state)
499
- assert !expectation.match?(:method_one)
500
-
501
- state.activate
502
- assert expectation.match?(:method_one)
503
- end
504
-
505
- def test_should_record_invocation
506
- Mockery.instance.invocations.clear
507
-
508
- mock = 'a mock'
509
- method = :call_me
510
- args = [1, 2, 3]
511
- expectation = Expectation.new(mock, method)
512
-
513
- expectation.invoke(args)
514
- assert_equal 1, Mockery.instance.invocations.size
515
- invocation = Mockery.instance.invocations.first
516
- assert_equal method, invocation[:method_name], "Got: #{invocation.inspect}"
517
- assert_equal args, invocation[:args], "Got: #{invocation.inspect}"
518
- assert_equal mock, invocation[:mock], "Got: #{invocation.inspect}"
519
- end
520
-
521
- def test_should_expose_invocation_count
522
- expectation = Expectation.new(nil, :a_method)
523
- assert_equal 0, expectation.invocation_count
524
- expectation.invoke(1)
525
- assert_equal 1, expectation.invocation_count
526
- expectation.invocation_count = 3
527
- assert_equal 3, expectation.invocation_count
528
- end
529
-
530
- end