Test validate_key_format method - #48032
Conversation
| @object_to_validate.stubs(:key).returns("") | ||
| refute @object_to_validate.validate_key_format |
There was a problem hiding this comment.
can you create a method that takes the jey and the expected string, and runs validate key_format since all the test do the same logic (copy/paste)
There was a problem hiding this comment.
Are you saying this method would make the assert itself, based on a parameter that says if it's valid (assert) or not valid (refute)?
There was a problem hiding this comment.
yeah,
def refute_object_validation(key, expected):
@object_to_validate.stubs(key).returns(expected)
refute @object_to_validate.validate_key_format
end
There was a problem hiding this comment.
Ahh, good call! I was thinking the one test for the valid key (that uses assert) would also be part of this method, but this is better. Just updated!
davidsbailey
left a comment
There was a problem hiding this comment.
thanks for the follow up!
| @errors.stubs(:add) | ||
| @object_to_validate = Object.new | ||
| @object_to_validate.extend(CurriculumHelper) | ||
| @object_to_validate.stubs(:errors).returns(@errors) |
There was a problem hiding this comment.
I love this strategy! this seems way more transparent vs what I had suggested 👍
There was a problem hiding this comment.
Shoutout to @bethanyaconnor for the help with that one!
|
I ended up needing to use |
yes, |
Ah, cool. I played around with this a little and couldn't get it working –– I'll ask you more about it during our 1:1 |
| @object_to_validate.stubs(:errors).returns(@errors) | ||
| end | ||
|
|
||
| def refute_valid_key(key_value) |
There was a problem hiding this comment.
beautiful, thanks for integrating the feedback!
Links
Testing story
Deployment strategy
Follow-up work
Privacy
Security
Caching
PR Checklist: