Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delegate_method doesn't work when delegated to private method #526

Closed
freemanoid opened this issue May 21, 2014 · 3 comments
Closed

delegate_method doesn't work when delegated to private method #526

freemanoid opened this issue May 21, 2014 · 3 comments
Milestone

Comments

@freemanoid
Copy link

Class which delegates to private method:

class UserPresenter 
  delegate :name, to: :user

  def initialize(user)
    @user = user
  end

  private
  attr_reader :user
end

Spec

describe UserPresenter do
  let(:user) { mock_model(User) }
  subject { described_class.new(user) }

  it { should delegate_method(:name).to(:user) }
end

Error:

Failure/Error: it { should delegate_method(:name).to(:user) }
       Expected UserPresenter#name to delegate to UserPresenter#user
       Calls on UserPresenter#user: (none)

Moving attr_reader :user out of the private section fixes the issue.

shoulda-matchers (2.6.1)

@mcmire
Copy link
Collaborator

mcmire commented May 21, 2014

Okay, thanks for the report, I'll look into this soon.

@mcmire mcmire added the Bug label May 21, 2014
@mcmire mcmire modified the milestones: 2.6.2, 2.7.0 May 21, 2014
@mrageh
Copy link

mrageh commented May 24, 2014

Hey @mcmire
I have started to work on this and I hope to fix it soon.

mrageh pushed a commit that referenced this issue May 24, 2014
Issue #526
Previously if a class delegated to a private method the `matches?` method would
return `false`. This was because`respond_to?` always returns `false` for private methods, this commit fixes this by making `respond_to?` evaluate private methods.
@mcmire
Copy link
Collaborator

mcmire commented May 26, 2014

Sweet, closing this in favor of that PR.

@mcmire mcmire closed this as completed May 26, 2014
mrageh pushed a commit that referenced this issue Jun 14, 2014
Issue #526
Previously if a class delegated to a private method the `matches?` method would
return `false`. This was because`respond_to?` always returns `false` for private methods, this commit fixes this by making `respond_to?` evaluate private methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants