4

我正在测试一个 Rails 3.2.6 应用程序。

是否有可能做出表达的 Rspec/Capybara 断言,例如:

“如果我要 1970 年到 1990 年之间的电影,页面应该包含这些日期之间的电影:”

例如

it "should show films in the the chosen date range" do
  page.should have_selector '.year',  # then something like text: range(1970..1990)
end

相反,我可以检查没有“.year”元素包含不在该范围内的日期吗?

谢谢你的帮助。

4

3 回答 3

9

将块传递给 have_selector 不起作用,但within确实:

within('.year') do 
  text.to_i.should be_between(1970, 1990)
end
于 2012-07-08T09:05:11.027 回答
1

尝试类似:

page.should have_selector('.year') do |year|
  range(1970..1990).should include(year.text.to_i)
end
于 2012-07-07T21:30:29.010 回答
1

在我看来,target.should be_between(x, y)rspec 语法更具可读性:

page.should have_selector('.year') do |year|
  i_year = year.text.to_i
  i_year.should be_between(1970, 1990)
end
于 2012-07-07T21:55:49.650 回答