Skip to content

Models say they don't respond_to :object #82

Open

Description

@jaynetics

Many (all?) Chargebee models respond to the "object" method. E.g.

session = ChargeBee::PortalSession.create(...).portal_session
session.object # => 'portal_session'

however, they say that they don't:

session.respond_to?(:object) # => false

presumably this is because the return value is fetched via method_missing here.

this is not ideal for code with type checks.

also respond_to_missing? has not been implemented, though there is a PR for it.

similarly, this:

ChargeBee::PortalSession.public_method_defined?(:object) # => false

prevents the usage of verified doubles with rspec:

instance_double(ChargeBee::PortalSession, object: 'portal_session')
# => error: the ChargeBee::PortalSession class does not implement the instance method: object

i hacked around this in my code with:

ChargeBee::Model.class_eval { attr_reader :object }

but i don't know if this is correct and whether all models include the "object" information.

ideally, each model that has the "object" information would have an attr_reader/accessor for it (or it could be added to Model if its all of them).

Activity

  1. cb-alish commented on Jun 3, 2025

    @cb-alish
    Collaborator

    Hi @jaynetics, this was fixed in v2.55.0. Could you please give it a try and let us know if you're still facing the issue?

  2. jaynetics commented on Jun 3, 2025

    @jaynetics
    Author

    hi!

    instances respond correctly now, but unfortunately, that neither helps with type checks nor with rspec-mocks.

    rspec-mocks' #instance_double method takes a class or module as argument, not an instance, so it can only verify the stubbed methods based on currently defined methods, not based on respond_to_missing? return values that would depend on an instance.

  3. gastonrey commented on Dec 23, 2025

    @gastonrey

    Hi, I'm also getting this error related to respond_to_missing? after upgrading the lib, any workaround?

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions