speclj
speclj copied to clipboard
Add support for regex's with should-throw?
Hi,
I have a situation where are tests are sometimes run under phantom 1.x and sometimes under 2.x. I have to check for a specific exception message being thrown but the exact message depends on which version of phantom, e.g.:
(def phantom-1.x-undef-err-msg "'undefined' is not a function (evaluating 'window.foo()')")
(def phantom-2.x-undef-err-msg "undefined is not a constructor (evaluating 'window.foo()')")
It would be great to be able to pass a regex instead of a string to should-throw
then I could just definte one regex something like .*undefined.*is not a .* evaluating ('window.foo()')
.
I've also run into cases in the past where the exceptions thrown by a library outside of my control would use messages that included details like IP addresses or other values that could vary from environment to environment. Previously I just skipped checking the messages for these exceptions but that was not ideal.
I would be happy to take a shot at a PR if it would be welcomed.
Let me know what you think. Thanks.