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

David Chelimsky dchelimsky at gmail.com
Thu Apr 23 12:40:17 EDT 2009


On Thu, Apr 23, 2009 at 9:39 AM, Ben Mabey <ben at benmabey.com> wrote:
> David Chelimsky wrote:
>>
>> 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
>>
>
> LOL... I seem to have that effect on people. :)  But, think how I feel.  Do
> you know how many "witty" people I have met who tell some "maybe" joke and
> think they are the first person to ever make it?  Well, I can tell you that
> it does, in fact, get very old. :)
>>
>> 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).
>>
>
> Back on topic...  I like this proposal the best.  Having the
>  "should_or_should_not" makes it very clear what is happening.  To reduce
> typing I suppose you could call it "expectation" in the step definition...
> and you could possibly even abbrevaite that more.

e9n ???
s18t ???

> But I wold probably stick
> with the more verbose "should_or_should_not".  I also agree that this is
> something that shouldn't be part of Cucumber itself but I'll probably play
> around with it in my own projects.
>
> -Ben *Mabey*
>
>
>
>> 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
>>>
>>>
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list