我如何为此编写功能测试



我对rspec很陌生。如何为下面的代码段编写功能测试?

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

这样如何:

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赋值实例变量

相关内容

  • 没有找到相关文章

最新更新