l0.DependencyControl.Stub¶
Stub ¶
A callable stub that records invocations and supports fluent configuration and assertions. Can be used standalone or via UnitTest:stub for automatic lifecycle management.
Constructor ¶
Creates a stub, optionally replacing a key in a table.
| param | type | description |
|---|---|---|
| table? | table|string |
The table to stub into, or a module name (looked up in the module cache). |
| key? | string |
The field name to replace; no table is modified when nil. |
| logger? | Logger | Logger to use; a default logger is used when nil. |
| unitTest? | UnitTest | Unit test instance to report assertion failures to; failures throw when nil. |
Instance methods¶
calls ¶
Sets the function to invoke when the stub is called.
| param | type | description |
|---|---|---|
| impl | function |
Returns:
selfStub
returns ¶
Sets the stub to return fixed values on every call.
| param | type | description |
|---|---|---|
| ... | any |
Values to return from every call. |
Returns:
selfStub
restore ¶
Restores the original value that was replaced by this stub.
assertCalled ¶
Asserts the stub was called at least once.
assertNotCalled ¶
Asserts the stub was never called.
assertCalledTimes ¶
Asserts the stub was called exactly the given number of times.
| param | type | description |
|---|---|---|
| n | integer |
The expected call count. |
assertCalledOnce ¶
Asserts the stub was called exactly once.
assertCalledOnceWith ¶
Asserts the stub was called exactly once and with the given arguments.
| param | type | description |
|---|---|---|
| ... | any |
The arguments expected on the single call. |
assertCalledWith ¶
Asserts at least one recorded call was made with the given arguments.
| param | type | description |
|---|---|---|
| ... | any |
The arguments expected on some call. |
assertLastCalledWith ¶
Asserts the most recent call was made with the given arguments.
| param | type | description |
|---|---|---|
| ... | any |
The arguments expected on the last call. |
assertNthCalledWith ¶
Asserts the nth recorded call was made with the given arguments.
| param | type | description |
|---|---|---|
| n | integer |
The 1-based index of the call to check. |
| ... | any |
The arguments expected on that call. |
Class methods¶
spy ¶
Creates a spy on a method, recording calls while still invoking the original method.
| param | type | description |
|---|---|---|
| table | table|string |
The table to spy into, or a module name (looked up in the module cache). |
| key | string |
The field name to spy on. |
| logger? | Logger | Logger to use; a default logger is used when nil. |
| unitTest? | UnitTest | Unit test instance used to report assertion failures. |
Returns: