Skip to content

Test validate_key_format method - #48032

Merged
megcrenshaw merged 4 commits into
stagingfrom
test-helper-class
Sep 12, 2022
Merged

Test validate_key_format method#48032
megcrenshaw merged 4 commits into
stagingfrom
test-helper-class

Conversation

@megcrenshaw

Copy link
Copy Markdown

Links

Testing story

Deployment strategy

Follow-up work

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@megcrenshaw megcrenshaw mentioned this pull request Sep 9, 2022
8 tasks
Comment on lines +13 to +14
@object_to_validate.stubs(:key).returns("")
refute @object_to_validate.validate_key_format

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah,

def refute_object_validation(key, expected):
@object_to_validate.stubs(key).returns(expected)
refute @object_to_validate.validate_key_format
end

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 davidsbailey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this strategy! this seems way more transparent vs what I had suggested 👍

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoutout to @bethanyaconnor for the help with that one!

@megcrenshaw

Copy link
Copy Markdown
Author

I ended up needing to use setup instead of setup_all for the stubs to work. @davidsbailey does that change seem okay?

@davidsbailey

Copy link
Copy Markdown
Member

I ended up needing to use setup instead of setup_all for the stubs to work. @davidsbailey does that change seem okay?

yes, setup is fair game! One idea for next time you usesetup_all is to freeze any objects you define there, to more easily detect / prevent state being leaked between test cases.

@megcrenshaw

Copy link
Copy Markdown
Author

I ended up needing to use setup instead of setup_all for the stubs to work. @davidsbailey does that change seem okay?

yes, setup is fair game! One idea for next time you usesetup_all is to freeze any objects you define there, to more easily detect / prevent state being leaked between test cases.

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

@megcrenshaw
megcrenshaw merged commit d3eea5e into staging Sep 12, 2022
@megcrenshaw
megcrenshaw deleted the test-helper-class branch September 12, 2022 18:11
@object_to_validate.stubs(:errors).returns(@errors)
end

def refute_valid_key(key_value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful, thanks for integrating the feedback!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants