当我wish
单独测试对象时,它可以工作:
before do
@wish1 = FactoryGirl.create(:wish)
@wish2 = FactoryGirl.create(:wish)
@wish3 = FactoryGirl.create(:wish)
visit wishes_path
end
it { should have_link(@wish1.destination)}
it { should have_link(@wish2.destination)}
it { should have_link(@wish3.destination)}
但是当我用数组尝试它并循环遍历时each
,它返回 nil。
[@wish1, @wish2, @wish3].each do |w|
it { should have_link(w.destination)}
end
结果
NoMethodError: undefined method `destination' for nil:NilClass
有什么方法可以改进这个测试吗?我的页面应该有很多Wishes的链接,而且大部分都不一样,所以会有很多重复。但我不能让它更简单。