Skip to content

Instantly share code, notes, and snippets.

@vpivo
Last active December 21, 2015 05:08
Show Gist options
  • Save vpivo/6254270 to your computer and use it in GitHub Desktop.
Save vpivo/6254270 to your computer and use it in GitHub Desktop.
Rspec, Factory Girl, Faker and Capybara Questions and cheat sheet.
1. Should I shoulda-matchers in place of something like:
expect(Contact.new(firstname: nil)).to have(1).errors_on(:firstname)
2. When should I use let(:variable) {something} vs. using variable = something
expect(Contact.new(lastname: nil)).to have(1).errors_on(:lastname)
Assertions
.to
.to_be
.to_not
*.should
*.should_not
Matchers
eq
equal
be_true
be_valid
include
Hooks
Theses go within a describe block.
before [all, each]
*Don't use these
Factory Girl
##Creating Objects
build- creates without saving
create - creates and saves
add config.include FactoryGirl::Syntax::Methods for shortcuts
expect(build(:contact, firstname: nil)).to
Associations
FactoryGirl.define do factory :phone do
association :contact
phone { '123-555-1234' }
phone_type 'home'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment