dimanche 1 février 2015

Getting data out of my app code and into my rspec test

I'm not sure how exactly to approach this kind of test in rspec, or if it is even possible.


My specific scenario is about email confirmation:


1) The user#save method uses SecureRandom to generate a string of bytes (the email confirmation code), Bcrypts it, and stores the result in the database. The original random code (unhashed) is also emailed to the user.


2) My user#confirm_email method takes in the email confirmation code and uses BCrypt to hash it and compare it against the existing hash in the database.'


Everything works fine but I'm unclear how to test the scenario, given that the input to #confirm_email is random, created within #save, and not stored anywhere that my test can access.


Is there a clean way for my code to pass information to my test, outside of method return values? I've considered storing the code in a temp file and then reading the file from the test, but I'm curious if there is a better way.


Aucun commentaire:

Enregistrer un commentaire