File tree Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,19 @@ f:should_be_called_with(1):
150
150
end )
151
151
```
152
152
153
+ ## Ignoring Other calls
154
+
155
+ ``` javascript
156
+ local mach = require ' mach'
157
+
158
+ local f = mach .mock_function (' f' )
159
+
160
+ f: should_be_called ().and_other_calls_should_be_ignored (): when (function ()
161
+ f()
162
+ f(1)
163
+ end)
164
+ ```
165
+
153
166
## Flexible Syntax
154
167
155
168
```lua
Original file line number Diff line number Diff line change @@ -439,4 +439,11 @@ describe('The mach library', function()
439
439
mach .mock_method ()(1 , 2 , 3 )
440
440
end )
441
441
end )
442
+
443
+ it (' should allow additional mocked calls to be ignored' , function ()
444
+ f1 :should_be_called ():and_other_calls_should_be_ignored ():when (function ()
445
+ f1 ()
446
+ f2 ()
447
+ end )
448
+ end )
442
449
end )
Original file line number Diff line number Diff line change @@ -43,8 +43,6 @@ function expectation:when(thunk)
43
43
end
44
44
45
45
local function called (m , name , args )
46
- assert (# self ._calls > 0 , ' unexpected call' )
47
-
48
46
local valid_function_found = false
49
47
50
48
for i , call in ipairs (self ._calls ) do
@@ -69,10 +67,12 @@ function expectation:when(thunk)
69
67
if call :has_fixed_order () then break end
70
68
end
71
69
72
- if not valid_function_found then
73
- unexpected_call_error (name , args , 2 )
74
- else
75
- unexpected_args_error (name , args , 2 )
70
+ if not self ._ignore_other_calls then
71
+ if not valid_function_found then
72
+ unexpected_call_error (name , args , 2 )
73
+ else
74
+ unexpected_args_error (name , args , 2 )
75
+ end
76
76
end
77
77
end
78
78
@@ -155,4 +155,9 @@ function expectation:multiple_times(times)
155
155
return self
156
156
end
157
157
158
+ function expectation :and_other_calls_should_be_ignored ()
159
+ self ._ignore_other_calls = true
160
+ return self
161
+ end
162
+
158
163
return create
You can’t perform that action at this time.
0 commit comments