Skip to content

Instantly share code, notes, and snippets.

@andrewpthorp
Created June 20, 2011 03:44
Show Gist options
  • Save andrewpthorp/1035087 to your computer and use it in GitHub Desktop.
Save andrewpthorp/1035087 to your computer and use it in GitHub Desktop.
Book Spec
STATES = %w(reading pending completed wishlist)
STATES.each do |state|
define_method "#{state}?" do
self.state == state
end
end
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
#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