Variable argument matchers for Cucumber

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

Tim H.
Senior Software Engineer
PICA Group
615-713-9956 :cell
timothyjhart :Y!
[email protected] :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.


On Mon, Mar 30, 2009 at 9:00 PM, Tim H. [email protected] wrote:

expected 0 block argument(s), got 4 (Cucumber::ArityMismatchError)

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

Howdy,

Just an observation, hope it’s helpful…

I can work around it, but I’ll end up with 2 different ‘Then’ calls that do nothing but call a common method

Not sure this is necessary. If you provide all the arguments in the
one step then you can test them for value ( blank?) in the one method.


Tim 2

2009/3/30 aslak hellesoy [email protected]:

On Mon, Mar 30, 2009 at 11:37 PM, aslak hellesoy
[email protected]wrote:

#…

http://gist.github.com/87890

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

Does this sound like an OK compromise?

You can use varargs now, but only on Ruby 1.9

http://github.com/aslakhellesoy/cucumber/commit/e58e1ed376b06204d48c52371b16f657630cd6ac

Aslak

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs