Hello, I'm looking for a way to create a mock (in...
# help
k
Hello, I'm looking for a way to create a mock (in standalone setup) that will run specific number of times, and then delete itself, but I can't really find any examples or documentation - I'm not even sure if it is possible. For example, I would like to have "default" response that is always returned (easy part), and from time to time, I would like to add mock that will run once or twice, and then again server should return default response. Unfortunately deleting mock manually isn't an option, because I will not be able to delete it right in time (when process is running). I thought about using scenarios, but I'm not sure if it will work well with such cases... I mean, I need to have a way to run similar or even the same test case simultaneously with different data (requests matched by xpath/json path)... And the best idea I got to do so, was to use mix of priority and deleting mocks after x times. Does anybody know of a way to achieve it?
t
You can achieve this with scenarios. You’d need to create several stubs, all identical except that they each depend on a different scenario state, and also each advance the scenario state. Then after the last one has been matched and the state moves on to one that doesn’t have a stub associated, it’ll return a no-match (as if there was no stub).
k
Thanks for explanations! Turns out I misunderstood the idea of scenarios... I will play a little bit with this, and I hope I will get it working If I understand it correctly, I will have to create a hell lot of them for each test case 🙂
t
Might be easier to create the stubs programmatically rather than by hand