我目前的集成测试有问题,我在 before 子句中填写表格,单击提交按钮。然后我用
it "has ..." do end
检查重定向的路径是否正确,它是正确的。但是,在完成第一个“it”语句后,我被重定向到不同的页面,并且几个连续的“it”语句失败,因为我不再在页面上。
这是一个示例代码片段。
...
context "when the correct information is entered" do
before {
fill_in 'Email', :with => 'test@test.test'
fill_in 'Username', :with => 'some_user'
fill_in 'Password', :with => 'Password'
fill_in 'Password Confirmation', :with => 'Password'
select 'foo', :from => 'user_type'
click_button 'Save'
}
it "has valid html" do
page.should have_valid_html
end
it "has current_path users/2" do
current_path.should == users_path+'/2'
end
...
因此,在这里,“具有有效的 html”测试通过,但第二个测试失败,因为我被重定向到“用户”而不是停留在“用户/2”上。同样,如果我切换“it”语句的顺序,我会得到相同的结果。
我应该以不同的方式做我的“之前”,还是我需要考虑其他一些事情?
感谢您的帮助,博卡
编辑:推论的一些信息;我在代码的其他部分做了几乎完全相同的事情,除了没有选择字段。如果它在所有其他情况下都有效,那可能是问题吗?