[rspec-users] Variable argument matchers for Cucumber

aslak hellesoy aslak.hellesoy at gmail.com
Mon Mar 30 17:37:29 EDT 2009


On Mon, Mar 30, 2009 at 9:00 PM, Tim Hart <THart at picagroup.com> wrote:

> List,
>
> Given a Cucumber script like
>
> Then /^the (?:(first|second|third|fourth) line of the )?(.*) section of the
> (.*) should be (.*)$/ do |*args|
>    #...
> end
>
> Cucumber errors with
> expected 0 block argument(s), got 4 (Cucumber::ArityMismatchError)
>
> While it's perfectly legal in generic ruby to do this
>
> def foo(&block)
>  block.call 1,2,3,4,5
> end
>
> foo do |*args|
>  #...
> End
>
> Is this an intended limitation? I can work around it, but I'll end up with
> 2 different 'Then' calls that do nothing but call a common method


It's intended. Let me explain with an example:

http://gist.github.com/87890

Ruby 1.8 doesn't know how to distinguish between a Proc with no args (and no
pipes) and a Proc with varargs. They both have arity -1. This means Cucumber
(while running on Ruby 1.8) can't really tell whether you forgot to define
any args or if you're deliberately using varargs. Since the first case is
more likely than the second, this is what Cucumber assumes.

I don't want to sacrifice this aide just so people can use varargs. The
benefit of getting help when you forget to define prog args outweighs the
drawback of not being able to use varargs.

That said, I'd like to make Cucumber smart enough to accept varargs on Ruby
1.9.

Does this sound like an OK compromise?

Aslak


>
> --
> Tim Hart
> Senior Software Engineer
> PICA Group
> 615-713-9956 :cell
> timothyjhart :Y!
> tjhart at me.com :AIM
>
>
> *****************************************************************************
>
> Disclaimer: This electronic message may contain information that is
> Confidential or legally privileged. It is intended only for the use of the
> individual(s) and entity named in the message. If you are not an intended
> recipient of this message, please notify the sender immediately and delete
> the material from your computer. Do not deliver, distribute or copy this
> message and do not disclose its contents or take any action in reliance on
> the information it contains.
>
>
> *****************************************************************************
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090330/e5137fe1/attachment-0001.html>


More information about the rspec-users mailing list