Ruby on rails RSpec rails |查找关联模型的说明

Ruby on rails RSpec rails |查找关联模型的说明,ruby-on-rails,rspec,rspec-rails,Ruby On Rails,Rspec,Rspec Rails,我如何描述在RSpec rails控制器示例中查找关联模型的过程 我尝试以下方法: 文章 class Article < ActiveRecord::Base has_many :comments end 评论控制器 class CommentsController < ApplicationController def update Article.find.comments.find end end class CommentsController

我如何描述在RSpec rails控制器示例中查找关联模型的过程

我尝试以下方法:

文章

class Article < ActiveRecord::Base
  has_many :comments
end
评论控制器

class CommentsController < ApplicationController
  def update
    Article.find.comments.find
  end
end
class CommentsController
但不幸的是,它不起作用。有什么想法吗

谢谢。

我想说,替换:

before { article.stub(:comments) { [comment] } }
与:


我自己解决了这个问题

下面是在Rails的控制器中查找关联模型的大致操作列表

1.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
2.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
5.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
7.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
11.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
15.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
17.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
19.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
21.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
23.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
25。

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
27.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
29.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
31.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
35.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!
39.

describe CommentsController do
  describe 'update' do
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' # <=
  end
end
describe CommentsController do
  describe 'update' do
    it 'finds an article' do
      Article.should_receive(:find) # <=
      put :update                   # <=
    end
  end
end
No route matches {:controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article } # <=

    it 'finds a article' do
      Article.should_receive(:find)
      put :update, article_id: article.id # <=
    end
  end
end
No route matches \
  {:article_id=>"1025", :controller=>"comments", :action=>"update"}
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment } # <=

    it 'finds an article' do
      Article.should_receive(:find)
      put :update, article_id: article.id, id: comment.id # <=
    end
  end
end
(<Article (class)>).find(any args)
       expected: 1 time
       received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article) { stub_model Article }
    let(:comment) { stub_model Comment }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
<Article (class)> received :find with unexpected arguments
  expected: ("1025")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {                                    # <=
      mock(ActiveRecord::Associations::HasManyAssociation) # <=
    }                                                      # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do                               # <=
      article.stub(:comments) { association }             # <=
      association.should_receive(:find)                   # <=
      put :update, article_id: article.id, id: comment.id # <=
    end                                                   # <=
  end
end
Couldn't find Article with id=1027
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article } # <=
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
(Mock ActiveRecord::Associations::HasManyAssociation).find(any args)
    expected: 1 time
    received: 0 times
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find # <=
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

undefined method `comments' for nil:NilClass
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article } # <=
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      article.stub(:comments) { association }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Couldn't find Comment without an ID
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation)
    }

    before { article.stub(:comments) { association } } # <=

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      # -> article.stub(:comments) { association } <-
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
update
  finds an article (fail!)
  finds a comment  (success!)

Mock ActiveRecord::Associations::HasManyAssociation \
  received unexpected message :find with (no args)
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find)
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      mock(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s) # <=
      put :update, article_id: article.id, id: comment.id
    end
  end
end
Mock ActiveRecord::Associations::HasManyAssociation \
  received :find with unexpected arguments
  expected: ("1028")
       got: (no args)
class CommentsController < ApplicationController
  def update
    Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object # <=
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @comment' do                              # <=
      Article.stub(:find) { article }                     # <=
      association.stub(:find) { comment }                 # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:comment].should eq comment                 # <=
    end                                                   # <=
  end
end
expected: #<Comment >
     got: nil
class CommentsController < ApplicationController
  def update
    @comment = Article.find(params[:article_id]).comments.find(params[:id]) # <=
  end
end
Success!
describe CommentsController do
  describe 'update' do
    let(:article)     { stub_model Article }
    let(:comment)     { stub_model Comment }
    let(:association) {
      double(ActiveRecord::Associations::HasManyAssociation).as_null_object
    }

    before { article.stub(:comments) { association } }

    it 'finds an article' do
      Article.should_receive(:find).with(article.id.to_s) { article }
      put :update, article_id: article.id, id: comment.id
    end

    it 'finds a comment' do
      Article.stub(:find) { article }
      association.should_receive(:find).with(comment.id.to_s)
      put :update, article_id: article.id, id: comment.id
    end

    it 'assigns @article' do                              # <=
      Article.stub(:find) { article }                     # <=
      put :update, article_id: article.id, id: comment.id # <=
      assigns[:article].should eq article                 # <=
    end                                                   # <=

    it 'assigns @comment' do
      Article.stub(:find) { article }
      association.stub(:find) { comment }
      put :update, article_id: article.id, id: comment.id
      assigns[:comment].should eq comment
    end
  end
end
expected: #<Article >
     got: nil
class CommentsController < ApplicationController
  def update
    @article = Article.find(params[:article_id])   # <=
    @comment = @article.comments.find(params[:id]) # <=
  end
end
Success!
class CommentsController < ApplicationController
  before_filter :find_article, only: :update # <=
  before_filter :find_comment, only: :update # <=

  def update
    # -> @article = Article.find(params[:article_id])   <-
    # -> @comment = @article.comments.find(params[:id]) <-
  end

  private                                          # <=
    def find_article                               # <=
      @article = Article.find(params[:article_id]) # <=
    end                                            # <=

    def find_comment                                 # <=
      @comment = @article.comments.find(params[:id]) # <=
    end                                              # <=
end
Success!

谢谢你的回答,亲爱的。就“理解”
obj.stub
obj.should\u receive
而言,它们的行为方式类似——它们为double创建了一个方法。那么,为什么我要两次指定
find
方法:在before块
article.stub\u链(:comments,:find)
和示例
article.comments.should\u receive(:find)
?@Shamaoke:使用
stub
设置方法调用的返回值。你可以使用
should\u receive
来设定期望值。我是Rails的粉丝,但这就是人们讨厌Rails的原因。