Last active
December 20, 2015 14:29
-
-
Save jacegu/6146725 to your computer and use it in GitHub Desktop.
First steps with a mock-less testing.
This file contains hidden or 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
require 'factory' | |
describe 'A user' do | |
let(:user_service) { Tddeo::Factory.user_service } | |
let(:user_repository) { Tddeo::Factory.user_repository } | |
before(:all) do | |
ENV['RACK_ENV'] = 'test' | |
end | |
before(:each) do | |
user_repository.clear | |
end | |
describe 'a user signing up' do | |
it 'creates the user' do | |
user_service.sign_up(email: DUMMY_EMAIL, password: DUMMY_PASSWORD) | |
expect(user_repository.count).to be 1 | |
end | |
it 'returns the signed up user' do | |
signed_up_user = user_service.sign_up(email: DUMMY_EMAIL, password: DUMMY_PASSWORD) | |
expect(signed_up_user.email).to eq DUMMY_EMAIL | |
end | |
context 'when the email is taken' do | |
it 'reports an error' do | |
user_service.sign_up(email: DUMMY_EMAIL, password: DUMMY_PASSWORD) | |
expect { | |
user_service.sign_up(email: DUMMY_EMAIL, password: OTHER_PASSWORD) | |
}.to raise_error Tddeo::EmailTaken | |
end | |
end | |
end | |
describe 'a user signing in' do | |
before do | |
@signed_up_user = user_service.sign_up(email: DUMMY_EMAIL, password: DUMMY_PASSWORD) | |
end | |
it 'authenticates the user' do | |
authenticated_user = user_service.sign_in(email: DUMMY_EMAIL, password: DUMMY_PASSWORD) | |
expect(authenticated_user).to eq @signed_up_user | |
end | |
context 'when the password is incorrect' do | |
it 'reports an error' do | |
expect { | |
user_service.sign_in(email: DUMMY_EMAIL, password: 'wrong password') | |
}.to raise_error Tddeo::IncorrectPassword | |
end | |
end | |
context 'when no user with given email exists' do | |
it 'reports an error' do | |
expect { | |
user_service.sign_in(email: '[email protected]', password: DUMMY_PASSWORD) | |
}.to raise_error Tddeo::UserNotFound | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment