Created
July 20, 2013 15:22
-
-
Save ccschmitz/6045435 to your computer and use it in GitHub Desktop.
How I typically structure my Rspec model specs.
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
require 'spec_helper' | |
describe Order do | |
describe '.responds_to' do | |
# attributes | |
it { should respond_to(:recipient_name) } | |
it { should respond_to(:shipping_to_address) } | |
it { should respond_to(:shipping_to_city) } | |
it { should respond_to(:shipping_to_state) } | |
it { should respond_to(:shipping_to_zip) } | |
it { should respond_to(:phone) } | |
it { should respond_to(:status) } | |
it { should respond_to(:cost) } | |
# associations | |
it { should respond_to(:coupon) } | |
end | |
describe '.valid?' do | |
# check to make sure our factory is valid | |
it 'has a valid factory' do | |
order = FactoryGirl.build(:order) | |
order.should be_valid | |
end | |
# test validations with shoulda_matchers | |
it { should validate_presence_of(:recipient_name) } | |
it { should validate_presence_of(:shipping_to_address) } | |
... | |
end | |
# Now test all methods in the model. For more good info on writing specs: | |
# http://blog.carbonfive.com/2010/10/21/rspec-best-practices/ | |
describe '.create' do | |
before do | |
@order = FactoryGirl.build(:order) | |
end | |
it 'sends a notification email to the user' ... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment