luisobo/Nocilla — pull request #56 by sansari (2013-11-23 23:33:30+00:00)
Title: add an unstubRequest method, so you can unstub a specific stubbed request

When you are building out a set of tests, you will undoubtedly build a stack of tests (within describes, contexts, etc.) that can be a few levels deep. If you are down a few levels, and you need to modify a specific stub to behave differently (to test a different context, perhaps), the only real way to do this is to:

1) Refactor your tests such that the stubbing you wish to change is done further down and can be configurable. This can work, but other times is not ideal as it can result in before blocks that are duplicated across scenarios.
2) Clear all stubs, and re-initialize everything again. Definitely not ideal.

This changeset adds a simple "unstubRequest" method to the DSL and implementation. To use it, one can just store the resulting DSL from a specific stub as a variable, and then later on pass it to unstubRequest to remove it.

I considered trying to build unstub so that it takes a method and a URL, but that presents complexity/ambiguity when considering whether it will also need you to pass the body/headers, or if it should just remove them all liberally by method/URL alone, or be super conservative and only do exact matches, etc.

Taking the DSL object itself and (only) removing that is probably the simplest approach, and should do the trick for most folks who are looking to just unstub one of many stubs set up for a complex scenario.