该行代码有什么作用?
assigns(:articles).should eq([article])
在以下rspec中
describe "GET #index" do
it "populates an array of articles" do
article = Factory(:article)
get :index
assigns(:articles).should eq([article])
end
it "renders the :index view" do
get :index
response.should render_template :index
end
end
最佳答案
assigns
与在 Controller Action 中创建(并分配给 View )的实例变量相关。
为了回答您的评论意见,我想:
@articles = Articles.all
(尽管我希望您使用分页)@articles
应该包含一篇文章,这是您对规范的期望关于ruby-on-rails - rspec中的赋值是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16133166/