-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Verify ActiveJob job signature matches arguments #2745
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work, I'd love to see the mailer implementation included in this as well.
Hmm... I think the CI failures are unrelated flakes:
Matrix is passing on my fork: |
Thanks, I have one last thing I'd like to change which is I'm not sure that it should raise an |
@JonRowe switched to the matcher failing in 232ea6b. Turns out this is much neater when it fails:
Thanks for the suggestion |
Guards against false-positives where both the implementation and have_enqueued_job or have_been_enqueued matchers are passed the wrong arguments which don't match the job's signature. Prior to this change it was possible for the implmentation and spec to pass whilst expecting the wrong number of arguments, or mixing up the positional/keyword arguments. This resulted in a passing test and the implementation failing at runtime.
Guards against false-positives where both the implementation and have_enqueued_mail matchers are passed the wrong arguments which don't match the mailer's signature.
Preferable for a matcher to fail instead of directly raising ArgumentError when a mismatch is detected. #2745 (comment)
Thanks so much for this |
It was a pleasure - glad to make a small contribution back to a tool I use almost every day. Thanks for you reviews & guidance @JonRowe. |
Released in 7.0.0 |
Hello,
I'd like to suggest an improvement to the
have_enqueued_job
andhave_been_enqueued
matchers – ensuring the arguments passed by the subject/caller actually match the job's method signature.Motivation
At the moment it's possible to write an implementation and spec which calls & expects the wrong number of arguments, or mix up the positional/keyword arguments. This results in a passing test, but the implementation will fail at runtime.
This improvement would guard against these false-positives. This approach was inspired by RSpec's awesome verifying doubles.
Example
ArgumentError: Missing required keyword arguments: a, b
Notes / questions
I wasn't sure if this behaviour should initially be opt-in, then become the default in the next major version. For the initial PR I've not made the verifying arguments behaviour configurable because it seems like any resulting failures will always be underlying bugs which should be fixed.