Skip to content

Commit

Permalink
Merge pull request #163 from rubensayshi/spy-self-ref-doc
Browse files Browse the repository at this point in the history
add explanation in README on how to do a `was_called_with` when mutating `self`.
  • Loading branch information
ajacksified authored Jun 28, 2019
2 parents 3b2351c + 54969da commit c90e1be
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit c90e1be

Please sign in to comment.