Upload
gourav-tiwari
View
129
Download
0
Embed Size (px)
DESCRIPTION
Test your application's controller, models, services and helpers by following simple patterns
Citation preview
Pattern● Where to begin?● What to test?● What not to test?● When to stub/mock?
QQ: How to learn syntax?Practice, cheat-sheet
Controller● Where to begin?
■ request and response● What to test?
■ response, flash, instance variables, conditions● What not to test?
■ filters, e.g. authorization; separate routing tests● When to stub/mock?
■ model calls, service calls, third party API calls
Services● Where to begin?
■ small methods● What to test?
■ logic written in services● What not to test?
■ connection● When to stub/mock?
■ external calls, third party calls
Tests should pass even when you are not connected to internet
Model● Where to begin?
■ small methods, least dependency● What to test?
■ custom logic that you are writing● What not to test?
■ libraries, e.g. ActiveRecord’s create method● When to stub/mock?
■ calls to methods which are outside the model
Helpers● Where to begin?
■ small methods, least dependency● What to test?
■ custom logic● What not to test?
■ libraries, e.g. ActionView::Helpers’ methods● When to stub/mock?
■ methods outside helper
Mocking frameworksMock in Ralis with: Mocha/Rspec/flexmock/RR
Interesting articles/links:http://www.martinfowler.com/articles/mocksArentStubs.htmlhttps://github.com/rspec/rspec-mocks