Rspec find方法收到两次,而预期收到一次

Rspec find方法收到两次,而预期收到一次,rspec,ruby-on-rails-3.2,Rspec,Ruby On Rails 3.2,我在编写一些规范时遇到了一个错误 QuestionsController GET #edit finds question to edit Failure/Error: Question.should_receive(:find).with("#{question.id}").and_return(question) (<Question(id: integer, title: string, body: text, created_at: datetime, update

我在编写一些规范时遇到了一个错误

QuestionsController GET #edit finds question to edit
     Failure/Error: Question.should_receive(:find).with("#{question.id}").and_return(question)
   (<Question(id: integer, title: string, body: text, created_at: datetime, updated_at: datetime, user_id: integer, up_votes: integer, down_votes: integer) (class)>).find("9")
       expected: 1 time
       received: 2 times

class QuestionsController < ApplicationController
  def edit
    @question = Question.find(params[:id])
  end
end
我使用Rspec、工厂女孩、数据库清洁剂、Postgres

规范帮助程序中的数据库\u清理器配置

  config.before(:suite) do
    DatabaseCleaner.clean_with :truncation
    DatabaseCleaner.strategy = :transaction
  end

  config.before(:each) do |group|
    # The strategy needs to be set before we call DatabaseCleaner.start
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end
  config.use_transactional_fixtures = false
我正在测试编辑操作。我在第一个示例中设置了接收find的期望,在第二个示例中设置了stubfind方法调用。我在第一个例子中遇到了一个错误
我认为这两个示例没有完全相互隔离。

您应该执行PUT请求:

put :edit, id: question.id

错误消息似乎与规范不符。首先,错误消息以“GET#edit”开头,而规范以“GET edit”开头。其次,错误报告中的预期有一个
with
子句,而规范没有。
put :edit, id: question.id