4
我想知道Rspec中的命令步骤和声明步骤是什么。Rspec中的命令步骤和说明步骤
下面是来自Rspec的书的示例代码:
Scenario: transfer money (declarative)
Given I have $100 in checking
And I have $20 in savings
When I transfer $15 from checking to savings
Then I should have $85 in checking
And I should have $35 in savings
Scenario: transfer money (imperative)
Given I have $100 in checking
And I have $20 in savings
When I go to the transfer form
And I select "Checking" from "Source Account"
And I select "Savings" from "Target Account"
And I fill in "Amount" with "15"
And I press "Execute Transfer"
Then I should see that I have $85 in checking
And I should see that I have $35 in savings
我不太明白了。
我的理解是,只要结果通过,声明式让你做任何你想做的事情,而且命令更加冗长。
但是,我不觉得我已经明白了这一点。
有人可以解释这一点多一点。有什么区别,我应该选择哪一个?
耦合问题的好例子,但是当您使用验收测试来定义用户故事中的预期内容时,明确定义这些步骤非常重要。声明性步骤隐藏了http://en.wikipedia.org/wiki/Specification_by_example所需的详细信息。 https://github.com/cheezy/page-object看起来像是一个很好的开始,以解决UI耦合而不牺牲所需的细节。 – Brenden 2013-10-18 00:18:48
我发现BDD最适合捕捉对话,而不是完全指定UI交互。这是Dan首先提出“测试”一词的原因之一。不过,请同意使用页面对象范例。 – Lunivore 2013-10-19 09:41:41