I use a script table ( multi-line step arguments ) to check some screen data with a cucumber using the built-in .diff! method on the table. Aroma of cucumber.
I would like to check for content matching with regular expressions.
Scenario: One Then the table appears as: | One | Two | Three | | /\d+/ | /\d+/ | /\d+/ |
The actual table may look something like
| One | Two | Three | | 123 | 456 | 789 |
which this script translates to "as long as there are some numbers, I don't care"
Implementing the sample step:
Then /^the table appears as:$/ do |expected_table| actual_table = [['One','Two', 'Three'],['123', '456', '789']] expected_table.diff! actual_table end
Error:
Then the table appears as: # features/step_definitions/my_steps.rb:230 | One | Two | Three | | /\\d+/ | /\\d+/ | /\\d+/ | | 123 | 456 | 789 | Tables were not identical (Cucumber::Ast::Table::Different)
I tried using step transforms to convert cells to regular expressions, but they are still not identical.
Convert code:
expected_table.raw[0].each do |column| expected_table.map_column! column do |cell| if cell.respond_to? :start_with? if cell.start_with? "/" cell.to_regexp else cell end else cell end end end
which provides eror:
Then the table appears as: # features/step_definitions/my_steps.rb:228 | One | Two | Three | | (?-mix:\\d+) | (?-mix:\\d+) | (?-mix:\\d+) | | 123 | 456 | 789 | Tables were not identical (Cucumber::Ast::Table::Different)
Any ideas? I am stuck.
source share