ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# 12.5 练习 电子书中有练习的答案,如果想阅读参考答案,请[购买电子书](http://railstutorial-china.org/#purchase)。 避免练习和正文冲突的方法参见[第 3 章练习](chapter3.html#mostly-static-pages-exercises)中的说明。 1. 编写测试,检查首页和资料页面显示的数量统计。提示:写入[代码清单 11.27](chapter11.html#listing-user-profile-test) 的测试文件中。(想一下为什么没单独测试首页显示的数量统计。) 2. 编写测试,检查首页正确显示了动态流的第一页。模板参见[代码清单 12.49](#listing-home-feed-test)。注意,我们使用 `CGI.escapeHTML` 转义了 HTML,想一下为什么要这么做。(把转义的代码去掉,仔细查看不匹配的微博内容源码。) ##### 代码清单 12.49:测试动态流的 HTML GREEN test/integration/following_test.rb ``` require 'test_helper' class FollowingTest < ActionDispatch::IntegrationTest def setup @user = users(:michael) log_in_as(@user) end . . . test "feed on Home page" do get root_path @user.feed.paginate(page: 1).each do |micropost| assert_match CGI.escapeHTML(FILL_IN), FILL_IN end end end ```