Chris Bailey
unread,Jul 21, 2009, 6:30:53 PM7/21/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Cukes
I often have the need to write steps that are simply the opposite of
each other, like:
Then there should be an event logged
Then there should not be an event logged
I'd like to be able to implement this as a single step definition and
simply use "should" or "should_not" in my matcher use based on
whichever was specified. I know I can write the step definition as:
Then /^there should( not)? be an event logged$/ do |should_not|
or similar, but the question is then how do you implement it and stay
dry, so that you aren't doing this kind of thing:
if shoudl_not
foo.should_not =~ /some really long regex for example/
else
foo.should =~ /that same regex as above/
end
Obviously the duplication of the regex isn't really the issue (I can
define that once above), but the whole conditional if/else to do this
just feels non-Ruby - I feel like I'm missing some obvious way to
implement this in a nicer way.