philnash / pwned

😱 An easy, Ruby way to use the Pwned Passwords API.
https://rubygems.org/gems/pwned/
MIT License
426 stars 22 forks source link

testing #35

Open alec-c4 opened 1 day ago

alec-c4 commented 1 day ago

Hi! I’d like to ask you to share your thoughts on how to use gem in testing. Currently, I’ve disabled the validator in the model to speed up tests, but I’m not sure if that’s the best approach. Perhaps we should consider mocking the HIBP service instead?

philnash commented 11 hours ago

I think that mocking the API from within your tests is likely the best way to handle this.

You can actually see how this is done within this repo. There is an Rspec helper registered here that stubs out network requests using Webmock and returns the contents of a fixture file. The not_pwned_validator_spec actually shows this in use in specs with an ActiveRecord model.

Let me know if that helps at all.