我对rspec很新。如何为下面的代码编写功能测试。
class FooController < ApplicationController
def new
@title = "Log in to Mint"
@msg = session[:msg]
session[:msg] = nil
end
end
答案 0 :(得分: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