- RSpec
- Associations + validations
- Scopes
- A few custom model methods
- JSON API
- A few complex routes
- RSpec + Capybara
- Maybe build off Day 1's project
- Add views
- Sign up, login, logout
- Multiple high-level user features
- Why test? refresher
- Syntax refresher
-
Models + Integration
-
Models
- Validations
- Associations
- Scopes
- Important methods
-
Integration (i.e. Features)
- Sign up, login, logout
- Any and all important features
-
API
- Test JSON responses w/ rspec (no Capybara)
Code:
rails new MyApp -T (excludes default test framework)
OR rm -rf test/ (if you already have the default test framework setup)
group :development, :test do
gem 'rspec-rails'
end
bundle install
rails generate rspec:install
- specs will be generated automatically anytime you use a rails generator
.rspec
file:
--format documentation
- Capybara
Gemfile
: gem 'capybara'
spec_helper.rb
: require 'capybara/rspec'
spec/
folder structure
models/
controllers/
features/
spec_helper.rb
-
What is integration testing? Feature testing
- Visit the site, do X, Y, and Z, check to make sure it worked
-
Test database
- Clears each time automatically
rake db:test:prepare
:- Checks for pending migrations
- Loads schema into test database
-
Other supporting gems:
gem 'factory_girl_rails'
gem 'guard-rspec'
gem 'faker'
- Faker:
spec/factories/contacts.rb
:
require 'faker'
FactoryGirl.define do
factory :contact do |f|
f.firstname { Faker::Name.first_name }
f.lastname { Faker::Name.last_name }
end
end