【185日目】【1日20分のRailsチュートリアル】【第12章】演習の1.
今日は「12.5 演習」から。
12.5 演習
なお、演習とチュートリアル本編の食い違いを避ける方法については、演習用のトピックブランチに追加したメモ (3.6) を参考にしてください。
いつものように演習用のブランチ作りましょう。
$ git checkout following-users $ git checkout -b following-users-exercises
1. HomeページとProfileページにある統計情報のテストを書いてみてください。ヒント: リスト11.27のテストに追加してください。(Homeページの統計情報は別のテストにしてみませんか。)
「統計情報」って
- ユーザー名
- アイコン
- フォロー数/フォローされている数
- マイクロポスト(or フィード)
のことかな…??
Profileページの統計情報はすでにベースがあるのでそこにフォロー数/フォローされている数のテストを追加すればいいのかな。
マイクロポスト数のテストを参考に下記を追加。
test/integration/users_profile_test.rb
test "profile display" do : assert_match @user.following.count.to_s, response.body assert_match @user.followers.count.to_s, response.body : end
テストは通りました。
$ bundle exec rake test 74 tests, 375 assertions, 0 failures, 0 errors, 0 skips
問題はHomeページの統計情報。
フィードってどうやってテストするんだ…!!!
てのが分からなかったのでまず他の情報についてテスト作りました。
test/integration/users_profile_test.rb
test "home display" do log_in_as(@user) get root_path assert_template 'static_pages/home' assert_select 'h1', text: @user.name assert_select 'img.gravatar' assert_match @user.following.count.to_s, response.body assert_match @user.followers.count.to_s, response.body assert_match @user.feed.count.to_s, response.body assert_select 'div.pagination' end
ここまでは通りました。
$ bundle exec rake test 75 tests, 385 assertions, 0 failures, 0 errors, 0 skips
フィードに対するテスト書けてないけど今日はとりあえずここまで。
書き方思いつかない~
今日の学習時間は【36分】。
次は「12.5 演習」の2.から。