-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
A "targeted" version of #any_instance #653
Comments
Thanks for your interest in Mocha.
Not specifically. I suppose you could stub
My initial reaction is probably not. In the past I've even contemplated disabling
Can you expand on this a bit? Do you mean you don't want to stub the |
Thanks for the response, and I agree that I was writing an integration-style test for a background job, and wanted to test that only some objects were processed. "Processed" in this scenario means "receive a method call". I know the preferred surface to test is the outcome of the I agree with getting rid of def test_only_the_correct_objects_call_an_api
obj1 = SomeClass.new(ready_to_be_processed: true)
obj2 = SomeClass.new(ready_to_be_processed: true)
obj3 = SomeClass.new(ready_to_be_processed: false)
SomeClass.instance_like(responds_with(:id, obj1.id)).expects(:make_api_call)
SomeClass.instance_like(responds_with(:id, obj2.id)).expects(:make_api_call)
SomeClass.instance_like(responds_with(:id, obj3.id)).expects(:make_api_call).never
MakeApiCallsJob.perform_now
end In my opinion, this is less-bad than using |
I should add, there isn't a |
Sorry for the slow response - I've been on leave. Thanks for providing more context. I understand a bit more about where you're coming from.
I've had some more time to think about this. I'm still pretty sceptical about it's usefulness - it's worth noting that you're the first person in over 10 years to have asked for anything like this feature. I don't have as much time as I would like to work on Mocha and since I think this would be a non-trivial amount of work to implement, I can't see me finding the time to add it myself. The only thing that might change my mind on that is if you need this on a commercial project and your company is willing to pay for the development of the feature... I'm not completely ruling out accepting the feature into the library, but I think it would depend a lot on how much complexity it added and how I felt about the likelihood of an additional maintenance overhead. I think I could only make that judgement call if I saw a working implementation and it feels unfair to ask you to do that without a guarantee that I would end up accepting it... The other thing worth bearing in mind is that the code is already a lot more complicated than I would like in places - mainly because it's been around for so long and because I haven't had as much time as I would like to tidy it up. Thus I suspect it might be more dificult than you would expect to add such a feature! I'm sorry not to be more positive, but I wanted to be honest and realistic with you. |
I appreciate the honesty, no need to apologize. I will close this for now, and consider writing a proof of concept if it comes back up for me. |
I often need to assert that an object representing a specific database row (ActiveRecord instance, for example). This falls apart when the database query is made in a place outside the control of the test. Without mocking pieces of the system such as ActiveRecord queries, there isn't any way to access the instances and add expectations to them. The problem is, I don't always want to mock. For example, I'm currently writing a test that runs a background job and makes sure that only the correct objects receive a method call. If I mock the ActiveRecord call, that makes the whole test worthless.
Is there a way to do something like this?
If there isn't, is this something that you would consider adding or accepting into the library?
The text was updated successfully, but these errors were encountered: