Date post: | 16-Aug-2015 |
Category: |
Software |
Upload: | david-paluy |
View: | 32 times |
Download: | 1 times |
Testing with RSpec 3David PaluyJul 2015
Agenda
● RSpec intro● Expectation - Matcher● Mocks vs Stubs● Model Specs● Controller Specs● FactoryGirl● API specs
RSpec 3
Start from reading other people's code
Read:https://relishapp.com/rspechttp://betterspecs.org/
RSpec 3
RSpec 2
Subject
let
RSpec Expectations
http://www.rubydoc.info/gems/rspec-expectations/frames
Mocks & Stubs
http://www.rubydoc.info/gems/rspec-mocks/frames
RSpec with Rails
RSpec Rails
Model spec
● Attributes existence
● Association
● Validation
● Class & Instance methods
Controller spec
https://www.relishapp.com/rspec/rspec-rails/v/2-13/docs/controller-specs
Controller spec
Simulate HTTP request:GET, POST, PUT, DELETE, XHR
Variables:controller, request, response,assigns, flash, session
Factories vs Fixtures
Factories
● YML files loaded on start
● Bypass ActiveRecord
● Easy to generate from Real Data
FactoryGirl
FactoryGirl - instantiation options
❖ create: saves object to the database, and saves any associated objects too
❖ build: builds object in memory only, but still saves any associated objects to the database
❖ build_stubbed: builds object in memory only, as well as any associated objects
Shared Examples
https://www.relishapp.com/rspec/rspec-core/v/3-3/docs/example-groups/shared-examples
API Testing - best practices
HTTP response status codeResponse body
API Testing is Integration Testing
RSpec Request specs
JSON Helper for RSpec
https://gist.github.com/dpaluy/b43821d086211bb10cda
References
RSpec 3Migrating to RSpec 3RSpec Style GuideShoulda Matchers