@routes 是否在“before(:all)”之后创建?和“before(:each)”之前?
在 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
我收到了一些这样的错误:
Failure/Error: post :create, :user=>@user_attributes
运行时错误:
@routes 为零:确保在测试的设置方法中设置它。
# ./spec/controllers/sessions_controller_spec.rb:22
# ./magazine_slave.rb:22:在“运行”中 # magazine_slave_provider.rb:17
当我将 before(:all) 更改为 before(:each) 时,测试将通过。
@routes 是否在“before(:all)”之后和“before(:each)”之前创建
In the rails project, when i write some controller's spec like this:
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
I got some errors like this:
Failure/Error: post :create, :user=>@user_attributes
RuntimeError:
@routes is nil: make sure you set it in your test's setup method.
# ./spec/controllers/sessions_controller_spec.rb:22
# ./magazine_slave.rb:22:in `run'
# magazine_slave_provider.rb:17
When I change before(:all) to before(:each),the test will be pass.
Is the @routes be created after "before(:all)" and before "before(:each)"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,我认为这在另一个问题中得到了回答。从此处的对话来看,修复似乎即将到来。
Yes, I think this is answered in another question. From the conversation here, it looks like a fix might be coming.