1

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)」の前に作成されますか?

4

1 に答える 1

1

はい、これは別の質問で回答されていると思います。ここでの会話から、修正が行われる可能性があるようです。

于 2012-04-29T01:31:00.743 に答える