Railsでテスト
参考にしたもの
詰まった事
ユーザーのモデルテストでfollowのテストを下記の様に書き、followingをどう書こうか悩んだ。 でもこの中にfollowing?入っちゃってるし、これもしfollowing?メソッドが間違えていたらこのテスト自体が意味ないどころかややこしくなってしまうのでは😵と訳が分からなくなる。 1つのテストにはメソッドは1つにしないと危険だと思われる。
test "follow" do
me = users(:alice)
other_user = users(:bob)
assert_not me.following?(other_user)
me.follow(other_user)
assert me.following?(other_user)
end
test "follow" do
me = users(:alice)
other_user = users(:bob)
assert_difference 'other_user.followers.count', 1 do
me.follow(other_user)
end
end