-
Notifications
You must be signed in to change notification settings - Fork 223
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
Ability to specify override objects #82
Comments
I think this could be done via an option argument on the objection_register_singleton macro. Something like So whenever an instance of a targetClass or targetProtocol an instance of the class is created. If multiple class register then either an option can be added to the macro to decide which one used or last in best dressed could be used. |
I've used Objection's modules to accomplish this, (documented here) and it's worked out pretty well. In an integration test where I want to substitute some testing classes I'll create an injector like this:
And the TestingObjectionModule would have a
Now, that being said... it would be convenient to be able to change the configuration of an injector after it's been created, but before an instance of a particular class has been requested. Something more lightweight than having to create a new Objection module. |
This is exactly what I did. I wrote a category for In our code this is pretty transparent to the developer writing tests, since every spec is initializing an injector with this module (and basic modules we configure specifically for testing), and we have macros such as |
Ahh, I was wondering if modules could somehow do this. It wasn't clear to me from reading the documentation. Might be a good idea to add an example showing how this can work in a test situation as I think some people (like myself) will be interested. Thanks. |
@StatusReport yeah +1 to @drekka's suggestion, it would be great if you could add this as an example. |
This is to support testing. It would be nice to be able to specify that a particular class registered with Objection is the preferred one to be instantiated. For example, when testing, I could specify a test class (or mock of some sort) will be returned by Objection instead of the one from the app.
The Spring framework has this concept (for Java) and I've found it very useful for providing stubbed out classes for predictable testing scenarios.
Thanks
The text was updated successfully, but these errors were encountered: