Tec*_*niX 3 rspec-rails ruby-on-rails-3 railstutorial.org
在阅读Michael Hartl撰写的Learn Rails书时,我对其中一个练习感到困惑. 通过Michael Hartl的例子学习Rails
"添加微博分页测试"
我的错误测试,放在登录用户"do"的'describe'中,如下所示:
describe "pagination" do
before(:all) do
30.times { FactoryGirl.create(:micropost, user: user) }
end
after(:all) { user.feed.delete_all }
page.should have_selector('div.pagination') }
it "should list each micropost" do
user.feed.paginate(page: 1).each do |user|
page.should have_selector('li', text: user.name)
end
end
end
Run Code Online (Sandbox Code Playgroud)
无论我是做page.should还是page.should_not,测试都会显示为pass.
任何'提示/帮助'将不胜感激
在浏览一些repos时,我找到了我的问题的答案 - 我需要在创建额外的微博后再次访问root_path.
describe "pagination" do
it "should paginate the feed" do
30.times { FactoryGirl.create(:micropost, user: user, content: "Consectetur adipiscing elit") }
visit root_path
page.should have_selector("div.pagination")
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1134 次 |
| 最近记录: |