【发布时间】:2010-08-12 08:59:03
【问题描述】:
我想知道 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
我不太明白。
我的理解是,声明式让你只要结果通过就可以为所欲为,而命令式则更冗长。
但是,我觉得我没有明白这一点。
有人能解释一下吗?有什么区别,我应该选择哪一个?
【问题讨论】: