I try to pass white space character in my test.
So I try the following in my cucumber step
If I enter:
|company_name|phone|
||#{nil}|
I get {"company_name"=>"", "phone"=>"\#{nil}"}
|company_name|phone|
| | |
I get {"company_name"=>"", "phone"=>""}
|company_name|phone|
|\s|\nil|
I get {"company_name"=>"\\s", "phone"=>"\nil"}
|company_name|phone|
|" "|' '|
I get {"company_name"=>"\" \"", "phone"=>"' '"}
What I should put in the table to get the following hash {"company_name"=>" ", "phone"=>" "}
?
There is no value you can put in a cucumber table that is interpreted as nil
by default. You can use a cucumber Transform to do what you want. For example, you could use it like this if you wanted to interpret an empty string as nil
:
Transform /^table:company_name,phone$/ do |table|
table.hashes.map! do |h|
h.each_pair do |k,v|
h[k] = nil if v == '' #here, you can map any value you want to be nil
end
end
table
end
Put this in a file in your support folder. There are also other methods like map_column!
etc you can use if you want to transform just one column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With