Created
June 27, 2012 05:16
-
-
Save lucashungaro/3001641 to your computer and use it in GitHub Desktop.
DIP snippet 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WARNING: pseudo code | |
class Authenticator | |
def initialize(user_repository = User) | |
@user_repository = user_repository | |
end | |
def authenticate(identifier, hashed_password) | |
@user_repository.find(:username => identifier, :password => hashed_password).present? | |
end | |
end | |
describe Authenticator | |
let(:repo) { double("user repo") } | |
let(:authenticator) { Authenticator.new(repo) } | |
context "with invalid credentials" | |
before { repo.stub(:find => nil) } | |
it "returns false" do | |
authenticator.authenticate("invalid", "invalid").should_not be | |
end | |
end | |
context "with valid credentials" | |
before { repo.stub(:find => double) } | |
it "returns true" do | |
authenticator.authenticate("valid", "valid").should be | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment