使用Rails模型的stub_chain缺少Rspec方法

时间:2013-02-17 20:56:28

标签: ruby-on-rails-3 rspec rspec2 stub

我正在尝试使用stub_chain来模拟控制器操作中的一系列调用。然而,它抱怨一个方法没有找到错误。经过一番搜索后,我没有找到任何与此特定错误有关的信息,所以我想我错过了一些相当明显的信息。有什么想法吗?

感谢。

这是错误:

Admin::AccountsController GET #index with accounts 
 Failure/Error: before(:each) { Account.stub_chain(:scoped, :page, :order).returns([account]) }
 NoMethodError:
   undefined method `stub_chain' for #<Class:0x007f96c6448158>
 # ./spec/controllers/admin/accounts_controller_spec.rb:11:in `block (4 levels) in <top (required)>'

规范的来源:

#spec/controllers/admin/accounts_controller.rb
describe 'GET #index' do

  context 'with accounts' do

    let(:account) { FactoryGirl.build_stubbed(:account) }
    before(:each) { Account.stub_chain(:scoped, :page, :order).returns([account]) }

    subject { get :index }

    it { should render_template(:index) }
    it { should assign_to(:accounts) }
    it { should respond_with(:success) }
    it { should_not set_the_flash }
  end
end

0 个答案:

没有答案