Cucmber/Ruby - Scenario Outline - Decimals, hyphens treated as multiple arguments

I have the basic cucumber scenario outline where I am using decimal values:

Given I have clicked the Search Button
When I select <MinEngineSize> and <MaxEngineSize> dropdown fields from the Engine size filter
And I click the Show results button 
Then the search results are displayed

Examples:

|MinEngineSize|MaxEngineSize|
|1.1 Litres|1.6 Litres| 

For some reason ruby seems to split the number before and after the decimal into separate args When /^I select (\d+).(\d+) Litres and (\d+).(\d+) Litres dropdown fields from the Engine size filter$/ do |arg1, arg2, arg3, arg4|

When I execute the .rb file I get the follwing error:

"1" not found in select list (Watir::Exception::NoValueFoundException)

How do I get ruby to treate the decimal values as one arg? probably a newbie mistake but thats my level at the mo.

Thanks!

Answers


I assume you are using the suggested step definition by Cucumber? These are not always correct for the data you are using, so you sometimes need to tweak the step definition's regex.

You want:

When /^I select (.+) Litres and (.+) Litres dropdown fields from the Engine size filter$/ do |arg1, arg2|

If you need a regex tutorial, I have found this one to be pretty good - http://www.regular-expressions.info/tutorial.html.

Note that arg1 and arg2 will be strings. If you want them as decimals, you will need to convert them using to_f(). For example:

When /^I select (.+) Litres and (.+) Litres dropdown fields from the Engine size filter$/ do |arg1, arg2|
  numeric_arg1 = arg1.to_f
  numeric_arg2 = arg2.to_f

Update

It looks like you are trying to select the value from a dropdown using Watir. In that case, I am guessing you actually want arg1 to actually be "1.1 Litres" not "1.1". If so, you will want to include Litres in the brackets:

When /^I select (.+ Litres) and (.+ Litres) dropdown fields from the Engine size filter$/ do |arg1, arg2|

Need Your Help

Usage of rtmp-dump/librtmp

ios red5 rtmp rtmpd

I am using compiled version of rtmp-dump from github in my iOS project. Following is the code to connect to the server.

XmlAttribute for an unbounded primitive type

python spyne

I've not found a way to describe an xml attribute for a repeatable primitive type; my best guess so far: