How about the following:
expect(object.new.public_methods(false)).to include(:method)
That allows you to explicitly check on method in one object; you can easily
alter it to check for multiple methods. But that’s explicit checking; I assume
you would prefer something more implicit, but I don’t know of anything that
would do that.
> On Jul 21, 2020, at 11:30 AM, 'Daniel Vandersluis' via rspec
> <[email protected]> wrote:
>
> We recently accidentally moved a method from public to private and it was not
> caught by our test suite because expect(obj).to receive(:method) succeeds
> regardless of whether or not obj.method is actually accessible or not.
>
> I'm not sure if there's an easy way to get around this (because it should be
> possible to stub out private methods of course). I can't think off hand of a
> way to determine if the object has access to a method without calling it,
> which obviously an expectation shouldn't be doing generally. Maybe we can
> check if the receiver is self?
>
> If there's a way to do this, it'd be nice to have this as a configuration
> option!
>
> Thanks,
> Daniel Vandersluis
>
> --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rspec/c0d84ace-2f0d-4730-83d9-e4649a36d02en%40googlegroups.com
>
> <https://groups.google.com/d/msgid/rspec/c0d84ace-2f0d-4730-83d9-e4649a36d02en%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/3AF97A19-BC7E-4EEC-9CA1-129D941E9552%40pobox.com.