2011-07-27 36 views
1

在Rails項目,當我寫了一些控制器的規格是這樣的:在「before(:all)」之前和「before(:each)」之前創建@routes嗎?

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 

我得到了一些象這樣的錯誤:

故障/錯誤:職務:創建:用戶=> @ 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

當我之前(:所有)更改爲之前(:每個)時,測試將通過。

是在@routes被後「之前(:所有)」創建和之前的「前(:每個)」

回答

1

是的,我認爲這是another question回答。從談話here,它看起來像一個修復可能即將到來。

相關問題