【发布时间】:2013-11-18 00:55:02
【问题描述】:
在 Michael Hartl 的 Rails Tutorial 中,许多示例使用 expect() 方法。这是黄瓜步骤定义中的一个这样的示例:
Then /^she should see her profile page$/ do
expect(page).to have_title(@user.name)
end
同样的例子可以写成同样的效果:
Then /^she should see her profile page$/ do
page.should have_title(@user.name)
end
为什么使用expect()?它增加了什么价值?
【问题讨论】:
-
myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax 对两者都有很好的描述。 expect() 和 .should 之间存在细微差别,但如果您知道自己在做什么,两者都会很有用。
标签: ruby-on-rails ruby testing rspec cucumber