-
Notifications
You must be signed in to change notification settings - Fork 184
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
Support for RSpec's instance_double
#197
Comments
I'm sorry, I don't have much experience working with RSpec but would appreciate a PR if you think it's valuable. I also wouldn't be opposed to having a spec suite in parallel to the minitest one if this is something that's easy to break. |
Is this still an issue, @delner? Would you be willing to work with us to PR it into the gem? |
I haven't used this in some time, but I think Although we'd have to verify it with RSpec, you might be able to remedy this by adding an override of |
@delner did you check it on master https://github.com/JsonApiClient/json_api_client/blob/master/lib/json_api_client/resource.rb#L259 |
I have not; I don't think I've checked it since 2016, so there's a fair chance that things might behave a bit differently... |
As a developer using the
JsonApiClient
gem to implement a client, I'd like to test code that uses this client.Take for example this client resource:
If I write an RSpec test that uses a
double
to stand in for aWidget
object obtained from this API:...the test passes. If instead I use an
instance_double
, because I want to verify I'm not mocking a property that doesn't exist:...then the same test fails, despite the
Widget
class having aserial_number
property defined, which can be accessed like an instance method.Looking at the
JsonApiClient::Resource
object, it appears the likely explanation comes from the use ofmethod_missing
to implement these properties. I would suggest either adding arespond_to?
or other mechanism that allowsinstance_double
to be used, or refactoring out the use ofmethod_missing
(the latter of which is probably a tall order.)I think there's a lot of value in adding support for
instance_double
for developers who want to useJsonApiClient
. As developers write more unit tests against clients that useJsonApiClient
, they will rely heavily on mocks and stubs to prevent actual API calls from being made in their tests. And as highly encouraged by the RSpec folks, usinginstance_double
overdouble
will prevent those tests from errantly stubbing properties that don't exist on rapidly changing APIs, that otherwise could result in false negative tests.The text was updated successfully, but these errors were encountered: