Created
June 20, 2011 03:44
-
-
Save andrewpthorp/1035087 to your computer and use it in GitHub Desktop.
Book Spec
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
STATES = %w(reading pending completed wishlist) | |
STATES.each do |state| | |
define_method "#{state}?" do | |
self.state == state | |
end | |
end |
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
Factory.define :book do |book| | |
book.name "The Pragmatic Programmer" | |
book.url "http://www.pragprog.com" | |
book.description "Lorem Ipsum" | |
book.state "completed" | |
book.author "Someone Famous" | |
book.rating 5 | |
end |
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
#wrong version | |
it 'should have a boolean method for it\'s state' do | |
subject { Factory :book } | |
subject.should be_completed | |
subject.should_not be_pending | |
end | |
#corrected version | |
it 'should have the right boolean method' do | |
@book = Factory(:book, :state => 'pending') | |
@book.should be_pending | |
@book.should_not be_reading | |
@book.should_not be_wishlist | |
@book.should_not be_completed | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment