Rspec: testing assignment of instance variable

前端 未结 2 1574
天涯浪人
天涯浪人 2021-02-03 19:43

Using Rspec with Factory Girl. Trying to check out what data is being assigned in my controller (and test against it). Every post I\'ve read says I should be able to get someth

相关标签:
2条回答
  • 2021-02-03 19:48

    If you are using the rspec > 2.99 you can use:

    expect(assigns(:stickies)).not_to be_nil

    0 讨论(0)
  • 2021-02-03 20:03

    You have to invoke the action first

    
    describe StickiesController do
      describe "GET index" do
        it "should assign stickies" do
          get :index
          assigns(:stickies).should_not be_nil
        end
      end
    end
    
    0 讨论(0)
提交回复
热议问题