Ruby on rails 是否在“之后创建@routes”;在(:all)之前;及在「;在(:each)之前;?
在rails项目中,当我编写一些控制器规范时,如下所示:Ruby on rails 是否在“之后创建@routes”;在(:all)之前;及在「;在(:each)之前;?,ruby-on-rails,rspec,rspec-rails,Ruby On Rails,Rspec,Rspec Rails,在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_attr
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
我遇到了如下错误:
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\u属性
运行时错误:
@路由为零:确保在测试的设置方法中设置了路由
#./spec/controller/sessions\u controller\u spec.rb:22
#/杂志_slave.rb:22:in'run'
#杂志_slave _provider.rb:17
当我将before(:all)更改为before(:each)时,测试将通过
@routes是在“before(:all)”和“before(:each)”之前创建的吗?是的,我想这在中得到了回答。从对话来看,似乎有一个解决方案即将到来。是的,我想这一点已经得到了回答。从对话中看,可能会有一个解决办法