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 は nil です: テストの setup メソッドで必ず設定してください。
# ./spec/controllers/sessions_controller_spec.rb:22
# ./magazine_slave.rb:22:in `run' # magazine_slave_provider.rb:17
before(:all) を before(:each) に変更すると、テストはパスします。
@route は「before(:all)」の後と「before(:each)」の前に作成されますか?