我正在测试一个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"元素包含不在该范围内的日期吗?
感谢您的任何帮助。
将块传递给have_selector不起作用,但within
确实如此:
within('.year') do
text.to_i.should be_between(1970, 1990)
end
尝试如下操作:
page.should have_selector('.year') do |year|
range(1970..1990).should include(year.text.to_i)
end
在我看来
,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