In the开发者_StackOverflow社区 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)"
Yes, I think this is answered in another question. From the conversation here, it looks like a fix might be coming.
精彩评论