2013-01-08 2 views
1

저는 rspec을 처음 사용했습니다. 다음 코드에 대한 기능 테스트를 작성하려면 어떻게해야합니까?어떻게이 기능 테스트를 작성합니까?

class FooController < ApplicationController 
     def new 
    @title = "Log in to Mint" 
    @msg = session[:msg] 
    session[:msg] = nil 
    end 
end 

답변

2

어떻게 이런 일에 대해 :

describe FooController do 

    describe "GET new" do 
    it "assigns 'Log in to Mint' to @title" do 
     get :new 
     assigns(:title).should == "Log in to Mint" 
    end 

    it "assigns message session to @msg" do 
     session[:msg] = "a message" 
     get :new 
     assigns(:msg).should == "a message" 
    end 

    it "sets message session to nil" do 
     get :new 
     session[:msg].should be_nil 
    end 
    end 

end 

항목 : Rspec: testing assignment of instance variable