# Variable argument matchers for Cucumber

**URL:** <https://www.ruby-forum.com/t/variable-argument-matchers-for-cucumber/164279>\
**Category:** RSpec\
**Created:** [March 30, 2009, 9:25pm UTC](https://www.ruby-forum.com/t/variable-argument-matchers-for-cucumber/164279 "2009-03-30T21:25:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [March 30, 2009, 9:25pm UTC](https://www.ruby-forum.com/t/variable-argument-matchers-for-cucumber/164279/1 "2009-03-30T21:25:24Z")

</div>

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!  
removed\_email\_address@domain.invalid :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.

* * *

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [March 31, 2009, 12:56am UTC](https://www.ruby-forum.com/t/variable-argument-matchers-for-cucumber/164279/2 "2009-03-31T00:56:21Z")

</div>

On Mon, Mar 30, 2009 at 9:00 PM, Tim H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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:

> <https://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

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [March 31, 2009, 2:05am UTC](https://www.ruby-forum.com/t/variable-argument-matchers-for-cucumber/164279/3 "2009-03-31T02:05:59Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [March 31, 2009, 1:37am UTC](https://www.ruby-forum.com/t/variable-argument-matchers-for-cucumber/164279/4 "2009-03-31T01:37:54Z")

</div>

On Mon, Mar 30, 2009 at 11:37 PM, aslak hellesoy  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > #…
> 
> [87890’s gists · GitHub](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](http://github.com/aslakhellesoy/cucumber/commit/e58e1ed376b06204d48c52371b16f657630cd6ac)

Aslak
