2017年7月3日 星期一

rspec- assigns

    it "assigns the requested contact to @contact" do 
      contact = create(:contact)
      get :show, id: contact
      expect(assigns(:contact)).to eq contact
    end
    def set_contact
      @contact = Contact.find(params[:id])
    end

可以用來檢查controller裡面的實體變數,上面那個的話就會檢查show裡面的@contact是不是等於我們傳給他的contact
然後我常常忘了後面有s…

Written with StackEdit.

沒有留言:

張貼留言