Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get white space or nil object from cucumber table?

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"=>" "} ?

like image 294
mef_ Avatar asked Nov 03 '22 22:11

mef_


1 Answers

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.

like image 78
Beat Richartz Avatar answered Nov 08 '22 06:11

Beat Richartz