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

David Chelimsky dchelimsky at gmail.com
Thu Apr 23 08:51:43 EDT 2009


On Thu, Apr 16, 2009 at 10:35 AM, Matt Wynne <matt at mattwynne.net> wrote:
>
> On 16 Apr 2009, at 14:06, Joaquin Rivera Padron wrote:
>
>> thanks matt,
>> 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
>>
>> 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

I'm definitely on the "clarity trumps DRY" side of the fence here. But
that doesn't deny that there is a problem to solve. This solution gets
close but is still takes me some extra time to grok. What extracting
that to a method like this:

Then /^I (should|should not) see the people search form$/ do
|should_or_should_not|
  expect_that(response, should_or_should_not, have_tag('form#frmSearch'))
end

def expect_that(target, should_or_should_not, matcher)
  target.send should_or_should_not.underscore.to_sym, matcher
end

I definitely don't see this in Cucumber, BTW as "should" and "should
not" are not the only way to express positive and negative
expectations even in English, let alone other languages that might not
deal w/ negation in such clean and consistent ways.

And it's not the least number of characters you can type. But it's
grok-able IMO. And DRY. And cute, to boot.

Of course, if anybody can come up with one word other than "maybe"
(damn you Ben Mabey for f'ing up my ability to type that word) to
express should_or_should_not more succinctly, that might help reduce
the typing. "Maybe" doesn't work for me because it implies lack of
precision rather than choice (to me).

Don't know how helpful this is, but it's fun to explore.

David

>
>
>> thanks again,
>> joaquin
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>
> Matt Wynne
> http://blog.mattwynne.net
> http://www.songkick.com
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list