Guest User

Untitled

a guest
Nov 19th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. # WARNING: pseudo code
  2.  
  3. class Authenticator
  4. def initialize(user_repository = User)
  5. @user_repository = user_repository
  6. end
  7.  
  8. def authenticate(identifier, hashed_password)
  9. @user_repository.find(:username => identifier, :password => hashed_password).present?
  10. end
  11. end
  12.  
  13. describe Authenticator
  14. let(:repo) { double("user repo") }
  15. let(:authenticator) { Authenticator.new(repo) }
  16.  
  17. context "with invalid credentials"
  18. before { repo.stub(:find => nil) }
  19.  
  20. it "returns false" do
  21. authenticator.authenticate("invalid", "invalid").should_not be
  22. end
  23. end
  24.  
  25. context "with valid credentials"
  26. before { repo.stub(:find => double) }
  27.  
  28. it "returns true" do
  29. authenticator.authenticate("valid", "valid").should be
  30. end
  31. end
  32. end
Add Comment
Please, Sign In to add comment