在 rails 项目中,当我像这样编写一些控制器的规范时:
describe "POST 'create'" do
context "valid user" do
before(:all) {
@user_attributes = Factory.attributes_for(:user)
@user = Factory(:user, @user_attributes)
post :create, :user=>@user_attributes
}
specify { flash[:notice].should eq("Welcome")}
specify { response.should redirect_to(:action=> :index) }
end
end
我遇到了一些这样的错误:
失败/错误:post :create, :user=>@user_attributes
运行时错误:
@routes 为零:确保在测试的设置方法中设置它。
# ./spec/controllers/sessions_controller_spec.rb:22
# ./magazine_slave.rb:22:in `run' # magazine_slave_provider.rb:17
当我将 before(:all) 更改为 before(:each) 时,测试将通过。
@routes 是在“before(:all)”之后和“before(:each)”之前创建的吗