Cucumber :: Ast :: Table:如何使用:surplus_row正确处理“内部”行?

时间:2014-02-24 13:44:24

标签: ruby cucumber

我想将(至少)期望值的Cucumber :: Ast :: Table与包含我的实际值的数组进行比较,但我想忽略其他行。为此,我想我可以将diff!方法与:surplus_row => false一起使用。

这符合预期(黄瓜报告成功):

table (Cucumber::Ast::Table):

  |id|name |
  |1 |one  |
  |2 |two  |

@actual:
  |id|name |
  |1 |one  |
  |2 |two  |
  |3 |three|

但这不是(我得到Cucumber::Ast::Table::Different):

table (Cucumber::Ast::Table):

  |id|name |
  |2 |two  |

@actual:
  |id|name |
  |1 |one  |
  |2 |two  |
  |3 |three|

因此,如果我的@actual仅包含“内部”行,那么Cucumber似乎会报告误报。这是黄瓜的一个错误吗?还是我犯了一些愚蠢的错误?

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

黄瓜版本1.2.1

1 个答案:

答案 0 :(得分:1)

原来这是我正在使用的旧黄瓜版本中的一个错误。从1.2.1升级到1.3.10解决了这个问题。

有关该错误的详细信息,请参阅Cucumber Github Issue