2017-12-28 32 views
0

私はシンプルな委譲クラスに私のレールコンソールからShouldaはマッチャー -

class Service::Fs::Account < DelegateClass(Bank::Account) 
    extend SingleForwardable 

    def initialize(args={}) 
    @account = Bank::Account.new(args) 
    super(@account) 
    end 

    def_delegators :"Bank::Account", :all, :create, :update 
end 

を持って働いていないdelegate_method、すべてが正常に動作し

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

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)>' 

誰でもこのテストが失敗している理由を理解できますか?べきマッチャーを使用しての

答えて

2

代わりにありがとう、あなたは明示的にRSpecのは

it "delegates 'all' to Bank::Account" do 
    expect(Bank::Account).to receive(:all) 
    Service::Fs::Account.all 
end 
を皮肉って使用してこの動作をテストすることができます