Skip to content

Instantly share code, notes, and snippets.

@ccschmitz
Created July 20, 2013 15:22
Show Gist options
  • Save ccschmitz/6045435 to your computer and use it in GitHub Desktop.
Save ccschmitz/6045435 to your computer and use it in GitHub Desktop.
How I typically structure my Rspec model specs.
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