Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add explanation in README on how to do a was_called_with when mutating self. #163

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ match.any_of(m1, m2, ...) -- argument matches at least one of the matchers m1 to
match.none_of(m1, m2, ...) -- argument does not match any of the matchers m1 to mn
```

If you're creating a spy for methods that mutate any properties on `self` you should should use `match.is_ref(obj)`:
```lua
local t = { cnt = 0, }
function t:incrby(i) self.cnt = self.cnt + i end

local s = spy.on(t, "incrby")
t:incrby(2)

assert.spy(s).was_called_with(match.is_ref(t), 2)
```

## Snapshots
To be able to revert changes created by tests, inserting spies and stubs for example, luassert supports 'snapshots'. A snapshot includes the following;

Expand Down