Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure stubs are called exactly once
Ensure that the stubs are called exactly once -- that is, that the same stub is not used several times, potentially masking a bug where several transmissions happen for the same events, and that no stubs are declared which are left unused. The strange way in which it is implemented is due to certain quirks of how the `webmock` gem works. I could not find a way to have a stub automatically disable itself when called, similar to what the `nock` Node.js package provides -- so I implemented this by passing a number of request bodies to expect to respond to when declaring the mock, and erroring if more requests are made than the request bodies provided. That, however, does not cover the scenario where the stub is not called at all. Somewhat bafflingly, the `have_been_requested` matcher does not check a counter that has been incremented for each request. Instead, it re-runs the requests it has stored by the stubs _again_, and counts how many match. Given the implementation described above, where the stub is exhausting a list of request bodies as it goes, the matcher will fail when attempting to go a second time around. So instead, we increment a counter when a request is processed (without said request having exhausted the matcher) and we return that counter from the stub. The tests store these counters in a `let` binding, and an `after` block checks that each stored counter has been increased to one. This is done in an `after` block not only for convenience, but because some tests are mocking a call that will only be performed in that same `after` block, when the scheduler is stopped.
- Loading branch information