2017-12-28 27 views
0

내가 간단한 위임자 클래스 내 레일 콘솔에서진작 정합 -

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

아무도 왜이 테스트가 실패하는지 파악할 수 있습니까? 해야 매처 (matcher)를 사용하는

답변

2

대신 주셔서 감사합니다, 당신은 명시 적으로 RSpec에이

it "delegates 'all' to Bank::Account" do 
    expect(Bank::Account).to receive(:all) 
    Service::Fs::Account.all 
end 
를 조롱 사용하여이 동작을 테스트 할 수 있습니다