Turns out it was a bug in the old cucumber version I was using. Upgrading from 1.2.1 to 1.3.10 fixed the issue.
See Cucumber Github Issue for details regarding the bug.
Question
I'd like to compare a Cucumber::Ast::Table of (at least) expected values with an array containing my actual values, but I want to ignore additional rows. For this, I thought I could use the diff!
method with :surplus_row => false
.
This works as expected (Cucumber reports success):
table (Cucumber::Ast::Table):
|id|name |
|1 |one |
|2 |two |
@actual:
|id|name |
|1 |one |
|2 |two |
|3 |three|
But this does not (I get Cucumber::Ast::Table::Different
):
table (Cucumber::Ast::Table):
|id|name |
|2 |two |
@actual:
|id|name |
|1 |one |
|2 |two |
|3 |three|
So it seems Cucumber is reporting a false positive if my @actual contains only "inner" rows. Is this a bug in Cucumber? Or am I making some stupid mistake?
CODE
table.feature:
Feature: Comparing Cucumber tables
Scenario: Comparing with a table with additional rows
Given I have a table with three rows and two columns
When I compare this table with an additional row and the same columns
Then I should get at least these rows
|id|name |
|2 |two |
table_steps.rb:
Given /^I have a table with three rows and two columns$/ do
@actual = [ { "id" => "1", "name" => "one" },
{ "id" => "2", "name" => "two"},
{ "id" => "3", "name" => "three" } ]
end
When /^I compare this table with an additional row and the same columns$/ do
# no-op
end
Then /^I should get at least these rows$/ do |table|
table.diff!(@actual, { :surplus_row => false } )
end
Cucumber version 1.2.1
La solution
Turns out it was a bug in the old cucumber version I was using. Upgrading from 1.2.1 to 1.3.10 fixed the issue.
See Cucumber Github Issue for details regarding the bug.