'Shoulda matchers - delegate_method not working

I have a simple delegator class

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

from my rails console, everything works fine

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

This my spec for Account delegator class

require 'spec_helper'

describe Service::Fs::Account do
  describe 'delegations' do
    it { should delegate_method(:all).to(Bank::Account) }
  end
end

tests are failing with the following error

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

can anyone help me figure out why this test is failing? Thank you



Solution 1:[1]

I think the assertion expects a symbol. I have this working for me:

it { should delegate_method(:all).to(:account) }

Or with the new expect syntax:

it { is_expected.to delegate_method(:all).to(:account) }

See; https://thoughtbot.com/blog/shoulda-matchers-2-6-0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rimian