1

I am pretty new to rspec. How do I write functional test for following piece of code.

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

 

4

1 回答 1

2

How about something like this:

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

See also: Rspec: testing assignment of instance variable

于 2013-01-08T05:38:15.933 回答