应该匹配 - delegate_method不工作

时间:2017-12-28 08:23:35

标签: ruby-on-rails ruby rspec shoulda

我有一个简单的委托人类

2.1.8 :002 > Service::Fs::Account.all
  Bank::Account Load (1.2ms)  SELECT "bank_accounts".* FROM "bank_accounts"
 => #<ActiveRecord::Relation []> 

从我的rails控制台,一切正常

Account

这是require 'spec_helper' describe Service::Fs::Account do describe 'delegations' do it { should delegate_method(:all).to(Bank::Account) } end end 委托人类

的规范
 Failure/Error: it { should delegate_method(:all).to(Bank::Account) }
   Expected Service::Fs::Account to delegate #all to #Bank::Account object
   Method calls sent to Service::Fs::Account#Bank::Account: (none)
 # ./spec/models/service/fs/account_spec.rb:5:in `block (3 levels) in <top (required)>'

测试失败并出现以下错误

Visitors

任何人都可以帮我弄清楚为什么这个测试失败了?谢谢

1 个答案:

答案 0 :(得分:2)

您可以使用RSpec模拟

显式测试此行为,而不是使用should matchers
it "delegates 'all' to Bank::Account" do
  expect(Bank::Account).to receive(:all)
  Service::Fs::Account.all
end