What does assigns mean in rspec

前端 未结 1 1935
陌清茗
陌清茗 2021-02-18 14:44

What does that line of code do?

assigns(:articles).should eq([article])

in the following rspec

  describe \"GET #index\" do
         


        
相关标签:
1条回答
  • 2021-02-18 14:45

    assigns relates to the instance variables created within a controller action (and assigned to the view).


    to answer your remark in comments, I guess that:

    • 1) your index action looks like @articles = Articles.all (I hope you use pagination though)

    • 2) prior to the spec block above, you have one article created in db (or I hope you stub db queries in db)

    • 1 + 2 => @articles should contain one article, that's your spec expectation

    0 讨论(0)
提交回复
热议问题