Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Factory Girl - Gabe Evans

Las Vegas Ruby Group
January 09, 2013
90

Factory Girl - Gabe Evans

Las Vegas Ruby Group

January 09, 2013
Tweet

Transcript

  1. FactoryGirl.define do factory :user do name ‘Joe Blow’ email ‘[email protected]

    password ‘p@ssw0rd’ admin false end end spec/factories/users.rb
  2. describe User do subject { FactoryGirl.create(:user) } its(:name) { should

    == ‘Joe Blow’ } end spec/models/user_spec.rb
  3. describe User do subject { FactoryGirl.create(:user) } its(:name) { should

    == ‘Joe Blow’ } its(:email) { should == ‘[email protected]’ } end spec/models/user_spec.rb
  4. describe User do subject { FactoryGirl.create(:user) } its(:name) { should

    == ‘Joe Blow’ } its(:email) { should == ‘[email protected]’ } it { should_not be_admin } end spec/models/user_spec.rb
  5. spec/models/user_spec.rb describe User do subject { create(:user) } its(:name) {

    should == ‘Joe Blow’ } its(:email) { should == ‘[email protected]’ } it { should_not be_admin } end
  6. context ‘a duplicate email address’ do let(:user) { create(:user) }

    subject { User.new(name: ‘Joe Duplicate’, email: user.email, password: ‘test123’) } it { should_not be_valid } end spec/models/user_spec.rb
  7. context ‘a duplicate email address’ do let(:user) { create(:user) }

    subject { build(:user, email: user.email) } it { should_not be_valid } end spec/models/user_spec.rb
  8. spec/factories/posts.rb FactoryGirl.define do factory :post do title ‘Worst presentation EVER!’

    content “Gabe’s presentations are long-winded. After the first 40 slides I passed out.” published_at { Time.now } end end