Created
September 12, 2012 20:57
-
-
Save xunker/3709873 to your computer and use it in GitHub Desktop.
Classic RSpec vs rspec-given
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
# | |
# Classic Rspec Style | |
# | |
describe User do | |
before(:each) do | |
@user = User.new | |
end | |
describe '#last_login' do | |
it 'should return the last login record for the user if there is one' do | |
# given | |
logins = [] | |
3.times do |i| | |
logins << Login.new(:auth_hash => i) | |
end | |
@user.stub!(:logins).and_return(logins) | |
# expect | |
@user.last_login.should == logins.first | |
end | |
end | |
end | |
# | |
# Same with rspec-given sugar. | |
# | |
describe User do | |
Given(:user) { User.new } | |
describe '#last_login' do | |
context 'should return the last login record for the user if there is one' do | |
Given(:logins) do | |
logins = [] | |
3.times do |i| | |
logins << Login.new(:auth_hash => i) | |
end | |
logins | |
end | |
When { user.stub!(:logins).and_return(logins) } | |
Then { user.last_login.should == logins.first } | |
end | |
context 'should return nil if there is not a last login record for the user' do | |
When { user.stub!(:logins).and_return [] } | |
Then { user.last_login.should be_nil } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment