Ruby on Rails Tutorial (37)

某所にて。spec/models/user_spec.rb の following なソレを。これはメソドなナニではないですね。follow 全般に関する、というカンジなのかどうか。

  • other_user な User オブジェクトを作っておいて
  • before なブロックで
    • @user.save
    • @user.follow!(other_user)

で、以下な形の試験があるのですが

    it { should be_following(other_user) }
    its(:followed_users) { should include(other_user) }

be_following って何かな。

どうやら

熟語なメソドの ? を取ったもののアタマに be_ って付けてマッチャにできる模様。User なクラスには以下なメソドが定義されています。

  def following?(other_user)
    relationships.find_by_followed_id(other_user.id)
  end

あとは other_user の followers に @user を含んでいる試験。

    describe "followed user" do
      subject { other_user }
      its(:followers) { should include(@user) }
    end

あるいは unfollowing な試験。

    describe "and unfollowing" do
      before { @user.unfollow!(other_user) }

      it { should_not be_following(other_user) }
      its(:followed_users) { should_not include(other_user) }
    end

継続としては controllers な試験の確認なのか。