Add DSL keyword "repeatedly" which enables repeated answer - #1241
ryu1-sakai wants to merge 1 commit into
Conversation
|
Hey, thanks for looking into this and putting a PR together! However, I'm a bit concerned that this would add some confusion to the existing DSL: isn't this implementing the behavior we already have for the |
|
Specifically, what you are doing in your example can be written as |
|
@Raibaz, thank you for your comment! As you pointed out, Another idea to solve this issue is to add However, this solution has a downside. We need a function like the following to let compiler know the element type of the list given to Then code to use Do you have any idea? Do you feel |
Summary
I'd like to add a new DSL keyword "repeatedly" which makes a mock to repeat a certain answer the specified number of times.
The usage is like the following.
The mock repeatedly replies "repeating" 3 times, and then replies "final".
Background
The reason why I'd like this feature is that I actually needed it when I made unit tests of a retry operation.
Let's say there are classes like the following.
Then we want to make a test of
RetryableOperationwith the scenario where:failableOperation.runFailable()throws an exception several times less thanmaxAttempts.failableOperation.runFailable()returns an expected value.We can make this test using existing features like the following, but the code not only doesn't look smart but also is not readable. (It takes an effort to know how many times the mock throws exception. 9 times? 10 times?)
Using the new keyword
repeatedly, the test can look smart and be readable like the following. (Now it's easy to know that the mock throws an exception 9 times.)