You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this example I can see that PollChat_ expectation constructor accepts Predicate, in this case anything. Is there the good way to use IO-like expressions (with side effects) to create predicates (like anything)? Sometimes it would be super useful to call database/webservice hosted in local test environment to verify that argument is genuine. This especially useful in cases where code which is tested is using some sort of randomness involved, for example request should be always unique due dynamically generated nonce and signed on top of it with some private key. I hope I manged to explain the use case. Best regards!
expectAny $PollChat_ anything
|-> (User"A", "I love Haskell")
|-> (User"B", "Lovin' the ass. candies")
|-> (User"B", "!leave")
The text was updated successfully, but these errors were encountered:
One thought here is that logically, predicates should be pure. You are describing a case where you have a predicate that's sort of "morally pure" in the sense that you don't care to track the I/O. Well, that's precisely what unsafePerformIO means, and you can certainly construct a Predicate using is from explainable-predicates along with unsafePerformIO.
The counter-argument would be, I suppose, that you really do care about the effect. In the example of looking something up in a database, you actually want to specifically check that it's in the database when the action is performed, and not at some other arbitrary time. So my initial reaction is probably wrong. I suppose this argues for either extending explainable-predicates to handle predicates with effects, or offering some HMock-specific alternative. I'm leaning towards the latter at the moment.
In this example I can see that
PollChat_
expectation constructor acceptsPredicate
, in this caseanything
. Is there the good way to use IO-like expressions (with side effects) to create predicates (likeanything
)? Sometimes it would be super useful to call database/webservice hosted in local test environment to verify that argument is genuine. This especially useful in cases where code which is tested is using some sort of randomness involved, for example request should be always unique due dynamically generated nonce and signed on top of it with some private key. I hope I manged to explain the use case. Best regards!The text was updated successfully, but these errors were encountered: