[rspec-users] Cucumber - step negating another expecting step

Kero van Gelder kero at chello.nl
Sat Apr 18 05:26:48 EDT 2009

> I've been doing something similar. I think the benefit of having half  
> the steps(each can be negated) wins over the small impact it has on step 
> readability. Personally I started adding stuff like this(perhaps not as 
> DRY but simple enough):
> Then /^the correspondence should (not )?have inclusions$/ do |negate|
>   if negate
>     @outcorr.inclusions.should be_empty
>   else
>     @outcorr.inclusions.should_not be_empty
>   end
> end

What's the advantage of having half the steps?
They should be grouped in a nice way in files anyway.

This one's quite readable, though.

>> yes, the regexp in the step matcher is a good one to dry it up
>> So I end up with this one:
>> Then /^I (should|should not) see the people search form$/ do |maybe|
>>  people_search_form_should_exist maybe == "should"
>> end

should ... exist ...  maybe... should


>> and the method:
>> def people_search_form_should_exist it_should_exist
>>  _not = "_not" unless it_should_exist
>>  response.send "should#{_not}".to_sym, have_tag('form#frmSearch')
>> end


>> only because I find it easier to read (when I don't need to jump to  
>> the method), but yours maybe faster (shorter it is), I could come back 
>> to it later and benchmark both
>> If you don't mind using the #send (I was trying to help you get rid of 
>> it) then just do this:
>> Then /^I (should|should not) see the people search form$/ do |maybe|
>>  response.send maybe.underscore.to_sym, have_tag('form#frmSearch')
>> end

If you go with this kind of abstraction, this solution and the topmost
in this mail at least do not introduce extra methods to deal with the
should/should not. more methods to have fewer steps can not be an advantage,
I think.

But the readbility of

  Then /^I should see the people search form$/ do
    response.should have_tag('form#peopleSearch')

  Then /^I should not see the people search form$/ do
    response.should_not have_tag('form#peopleSearch')

is higher for me, as I only need to think what the have_tag means,
but do not have to parse the should/not, send, underscore and to_sym.

The difference in readability is from about 2 seconds to at least
10 seconds. That's a disadvantage that I'm not willing to pay for
any advantage of having "fewer steps".

How can I change the world if I can't even change myself?
  -- Faithless, Salva Mea

More information about the rspec-users mailing list