現在、Ruby on Rails チュートリアルのソースコードをgithubからダウンロードして、勉強のために閲覧しています。 Twitterのようにつぶやいたことを表示するアプリです。
下記はフォローとフォロワーの関係を表すRelationshipモデルのテストです。このモデルはUserモデル1対多の関係にあります。
ruby
1require 'spec_helper' 2 3describe Relationship do 4 5 let(:follower) { FactoryGirl.create(:user) } 6 let(:followed) { FactoryGirl.create(:user) } 7 let(:relationship) { follower.relationships.build(followed_id: followed.id) } 8 9 subject { relationship } 10 11 it { should be_valid } 12 13 describe "follower methods" do 14 it { should respond_to(:follower) } 15 it { should respond_to(:followed) } 16 its(:follower) { should eq follower } 17 its(:followed) { should eq followed } 18 end
このテストの中でits(:follower) { should eq follower }
の必要性がわかりません。これはfollowerという変数がfollowerと等しいことをテストしていると思います。このfollowerという変数は let(:followed) { FactoryGirl.create(:user) }
で定義されています。このように自分が自分自身と等しいということをテストするのは何のためでしょうか?
お手数おかけしますが、お答え頂ければ幸いです。
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/08/18 05:04 編集