Closed stiansoevik closed 4 years ago
Hi,
That is an interesting idea indeed. However, the behavior you are witnessing was intentional.
The given that
phase is setting the stage and not triggering any action. Then you can call the callbacks you registered manually. It makes much more clear what's going on to the reader of the test as "no magic is involved".
To make sure the callbacks you're manually calling in the tests were actually registered, you can use assert_that(...).listens_to.even(...).with_callback(...)
: See doc
That being said, it is an interesting idea 😃 It could be integrated as an option in the given_that
, or better in a new helper called when
. Like given_that.state_is(...)
and when.state_becomes(...)
. One sets the stage and does not trigger any callback, while the other does its magic.
If you want to give it a shot with a PR, go for it. I'll be available for support (as long as you're not in a hurry 🙂 )
Thanks for the idea 👍
I'm closing for now, but feel free to re-open if you decide to work on it and want a place to discuss 🙂👍
I think it would be natural if state listener callbacks were automatically called when a mocked state changes. In the example below, I had to call it myself from the test, which increases the amount of code needed in tests, and the probability of errors.
If this isn't the intended behavior, please give me a hint on what I'm doing wrong. Otherwise, do you think it would be desirable to make the framework automatically call the listeners on state change?