Open ericgj opened 12 years ago
How about something like this?
validate do
# check something about the message
end
invalid_request do
# send a response, log it, etc.
end
A failed validation would set some state (or raise an error) which causes invalid_request to be triggered. This could also be done explicitly with some method that could be called from within any matcher. Better names are needed here.
Right now, if the request email coming in to your application isn't correct in some application-specific way, can't be parsed etc., your callback might look like
Which is fine for simple cases, but if you have several different error conditions that each call for different behavior/responses, the code starts getting ugly with nested if's. One thing that might be helpful would be a way of exiting the callback early. You could use
next
-or to DRY it up, -
But somehow that still isn't satisfying. Not suggesting rails-style controller validations, but maybe something
Newman::Controller
could help with that I'm not thinking of.