Ayd*_*kov 18 bdd rspec ruby-on-rails
这行代码有什么作用?
assigns(:articles).should eq([article])
Run Code Online (Sandbox Code Playgroud)
在下面的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
Run Code Online (Sandbox Code Playgroud)
apn*_*ing 18
assigns 涉及在控制器动作中创建的实例变量(并分配给视图).
在评论中回答你的评论,我想:
1)你的索引动作看起来像@articles = Articles.all(我希望你使用分页)
2)在上面的spec块之前,你有一篇在db中创建的文章(或者我希望你在db中存根db查询)
1 + 2 => @articles应包含一篇文章,这是您的规格期望
| 归档时间: |
|
| 查看次数: |
7123 次 |
| 最近记录: |