行为驱动开发:Cucumber与Rails的结合实践
1. Cucumber基础概念
在使用Cucumber进行测试时,我们会遇到数组哈希的情况。每个哈希在数组中使用第一行的列标题作为键,示例如下:
[
{ :rank => '2', :suit => 'H' },
{ :rank => '2', :suit => 'S' },
{ :rank => '4', :suit => 'C' },
{ :rank => '4', :suit => 'D' },
{ :rank => 'A', :suit => 'H' }
]
Cucumber会将 Cucumber::Ast::Table 作为最后一个(在这种情况下也是唯一的)块参数传递给块。第一个步骤的步骤定义可能如下:
Given /^a hand with the following cards:$/ do |cards_table|
hands << Hand.new do |hand|
cards_table.hashes.each {|hash| hand << Card.new(hash)}
end
end
这个步骤定义引导我们编写 Card 的 initialize 方法,使其能够从包含 :rank
超级会员免费看
订阅专栏 解锁全文
2

被折叠的 条评论
为什么被折叠?



