我有一个看起来像这样的请求规范:
describe "Registering from the main page" do
before(:each) do
fill_in "username","my_username"
fill_in "password","my_password"
fill_in "password_confirmation","my_password"
click_button "Register"
end
it "should have created a new user" do
User.count.should == 1
end
it "should have changed the message on the homepage" do
find("#element").value.should == "You registered!"
end
# ... other tests like this
end
第一个问题,如何在提交表单之前确保我有 0 个用户?
其次,这before
对我来说似乎不太正确,即使它确实有效。是否有另一种方法可以为整个注册用例编写测试?也许以某种方式重新制定之前的部分,或者我这样做的方式是否可以接受?
更新:我将其更改before(:all)
为before(:each)
因为测试开始失败。当我使用before(:all)
. 你碰巧知道为什么吗?