【发布时间】:2014-01-03 19:22:18
【问题描述】:
我已经在 Michael Hartl 的 Rails 3 教程一书中添加了回复微博功能,但我现在正在尝试为它们编写测试(我知道我是倒着做的)。回复添加有效,但我正在尝试编写以下测试
- 创建用户和用户的两个帖子
- 从 other_user 创建 other_user 和两个帖子
- 让用户关注 other_user
- 检查用户的主页提要是否包含 other_user 的帖子
- ...
我的测试目前在第四步失败。以下是规范文件中的 sn-p、失败错误以及我的 repo 的链接。 (用户在此描述之前定义,但在此块范围内)
describe "replying to a micropost" do
let (:other_user) { FactoryGirl.create(:user) }
let (:first_post) { FactoryGirl.create(:micropost, user: other_user, content: "Whatever.") }
let (:second_post) { FactoryGirl.create(:micropost, user: other_user, content: "Nevermind.") }
before do
user.follow!(other_user)
visit root_path
end
it "should render the posts from other user" do
page.should have_selector("li##{first_post.id}", text: first_post.content)
page.should have_selector("li##{second_post.id}", text: second_post.content)
end
Failures:
1) Static pages Home page for signed-in users replying to a micropost should render the posts from other user
Failure/Error: page.should have_selector("li##{first_post.id}", text: first_post.content)
expected css "li#203" with text "Whatever." to return something
# ./spec/requests/static_pages_spec.rb:85:in `block (5 levels) in <top (required)>'
Finished in 3.43 seconds
17 examples, 1 failure
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:84 # Static pages Home page for signed-in users replying to a micropost should render the posts from other user
Done.
【问题讨论】:
-
请分享您遇到的具体故障。
-
刚刚添加了 rspec 失败...
-
很抱歉,但没有看到任何明显的内容,也不要向上梳理您的源存储库。 :-) 这很好地解释了为什么要使用小块进行 TDD,但是考虑到您所处的位置,您可能希望从在故障点打印出当前页面内容开始。
-
如何在故障点打印出当前页面内容?
标签: ruby-on-rails rspec