SlideShare a Scribd company logo
Service objects as a way
of testing Rails apps
@andrzejkrzywda
@arkency
In love/hate relationship with Rails, since 2004
Service objects
The things you call
from your controllers
Rails is not your app
Your app is below controllers
Most of the things
without HTTP
AddProductToCart
ChangeAmount
CreateNewBlogPost
PublishBlogPost
AssignTestToPupils
CreateNewKlass
CheckoutOrder
LogTimeEntry
ChangeInsurancePolicy
http://blog.arkency.com/2014/02/rails-refactoring-the-aha-
moments/
Things that “do”
something
Query objects - read
the system
ListOfOrders
UserQuery
PupilsInKlass
BlogPostsByAuthor
Reads are easy
Commands are more
difficult
Rails-way is good for
Reads
Rails-way is not ideal
for Commands
Testing
System tests
vs
Unit tests
Good tests tell a story
1. User adds a product to the cart

2. User looks at the cart to see the current total amount 	

3. User changes the amount

4. User goes to checkout
How to setup the
state?
factory_girl
Service objects in
tests
What makes a good
unit?
Unit == a set of
service objects
scenario == service
objects
Wins?
hides implementation
details
tests in sync with
production code
Easy to write
Fast
Problems?
Tests are one layer below
!
Easy to make mistakes when
calling services from controllers
Not so easy to extract
services from an existing,
legacy Rails codebase
Examples
http://blog.arkency.com/2014/06/setup-your-tests-with-
services/
Thanks!

More Related Content

PPTX
Run the load down your mobile app
PDF
Reasons To Automate API Testing Process
PPTX
Data Driven API Testing: Best Practices for Real-World Testing Scenarios
PDF
The what why and how of web analytics testing
PDF
10 Must-Use Components for Your Mobile Apps, James Clancey
PDF
API TESTING
PDF
How to Automate API Testing
PDF
API Testing: Answers to Your Top 3 Questions
Run the load down your mobile app
Reasons To Automate API Testing Process
Data Driven API Testing: Best Practices for Real-World Testing Scenarios
The what why and how of web analytics testing
10 Must-Use Components for Your Mobile Apps, James Clancey
API TESTING
How to Automate API Testing
API Testing: Answers to Your Top 3 Questions

What's hot (20)

PPTX
Testing soapui
PPTX
What's new in visual studio 2013
PPTX
An introduction to api testing | David Tzemach
PDF
4 Major Advantages of API Testing
PPT
Mobile + cloud = heaven
PPTX
Azure Mobile Services
PPTX
Evaluating and Testing Web APIs
PPTX
Build Modern Web Apps Using ASP.NET Web API and AngularJS
PDF
Startup Pitching and Mobile App Startup
PDF
Automation Awesomeness: Scaling JIRA Service Desk
PPTX
The Works 2018 - Software Track - Integration Partners Overview
PPT
P2P & O2C
PPTX
Successful Teams are TDD Teams
PDF
Ship chung
PPTX
API Proxy Auto Discovery
PPTX
Speed upyourtest with_appium
PPTX
Angular: An Introduction
PPTX
Your Tests Are Not Your Specs
PDF
0529구조
PPTX
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
Testing soapui
What's new in visual studio 2013
An introduction to api testing | David Tzemach
4 Major Advantages of API Testing
Mobile + cloud = heaven
Azure Mobile Services
Evaluating and Testing Web APIs
Build Modern Web Apps Using ASP.NET Web API and AngularJS
Startup Pitching and Mobile App Startup
Automation Awesomeness: Scaling JIRA Service Desk
The Works 2018 - Software Track - Integration Partners Overview
P2P & O2C
Successful Teams are TDD Teams
Ship chung
API Proxy Auto Discovery
Speed upyourtest with_appium
Angular: An Introduction
Your Tests Are Not Your Specs
0529구조
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
Ad

Similar to Service objects in Rails tests - factory_girl replacement (20)

PDF
Rails request & middlewares
PDF
A Practical Guide to Automating End-to-End API Testing
PDF
Next-Level API Automation Testing Techniques – Part 1
PPTX
Soap UI and postman
PPTX
Api testing
PPTX
E-TAIL QA: Approach to E-commerce testing in an Agile environment
PPTX
RESTful API Design: Illustrated
PDF
Cqrs api
PPTX
B4USolution_API-Testing
PDF
Things you must know on ruby on rails single page application
PDF
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
PDF
API Check Overview - Rigor Monitoring
PDF
How to implement ruby on rails testing practices to build a successful web ap...
PPTX
Do not automate GUI testing
PDF
Sensor thingsapi webinar-#3-rest-for-iot-api-20151210
PPTX
Test execution
PPT
Creating a World-Class RESTful Web Services API
PDF
From legacy to DDD (slides for the screencast)
PDF
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
PPT
RAML - The architecture
Rails request & middlewares
A Practical Guide to Automating End-to-End API Testing
Next-Level API Automation Testing Techniques – Part 1
Soap UI and postman
Api testing
E-TAIL QA: Approach to E-commerce testing in an Agile environment
RESTful API Design: Illustrated
Cqrs api
B4USolution_API-Testing
Things you must know on ruby on rails single page application
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
API Check Overview - Rigor Monitoring
How to implement ruby on rails testing practices to build a successful web ap...
Do not automate GUI testing
Sensor thingsapi webinar-#3-rest-for-iot-api-20151210
Test execution
Creating a World-Class RESTful Web Services API
From legacy to DDD (slides for the screencast)
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
RAML - The architecture
Ad

More from Andrzej Krzywda (20)

PDF
[PL] PRUG Luty 2022 - Service objecty to za mało - jak żyć z Railsami?
PDF
[PL] Service objecty to za mało - jak żyć z Railsami?
PDF
Audit log with event sourcing
PDF
Event driven without microservices
PDF
From legacy to DDD - 5 starting steps
PDF
Slack protips from Arkency
PDF
From Rails legacy to DDD - Pivorak, Lviv
PDF
From legacy to DDD
PDF
DCI - the architecture from the future
PDF
Refactoring Rails applications with RubyMine
PDF
Beyond The Rails Way
PDF
Developer oriented
PDF
Can you TDD Rails?
PDF
A programmer or a business consultant?
PDF
Rails refactoring call for help
PDF
[Polish] Praca zdalna, praca asynchroniczna
KEY
Use cases in the code with AOP
KEY
Single Page Applications with CoffeeScript [Polish]
PDF
Madeleine on Rails
PDF
TDD with Rails
[PL] PRUG Luty 2022 - Service objecty to za mało - jak żyć z Railsami?
[PL] Service objecty to za mało - jak żyć z Railsami?
Audit log with event sourcing
Event driven without microservices
From legacy to DDD - 5 starting steps
Slack protips from Arkency
From Rails legacy to DDD - Pivorak, Lviv
From legacy to DDD
DCI - the architecture from the future
Refactoring Rails applications with RubyMine
Beyond The Rails Way
Developer oriented
Can you TDD Rails?
A programmer or a business consultant?
Rails refactoring call for help
[Polish] Praca zdalna, praca asynchroniczna
Use cases in the code with AOP
Single Page Applications with CoffeeScript [Polish]
Madeleine on Rails
TDD with Rails

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
sap open course for s4hana steps from ECC to s4
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
KodekX | Application Modernization Development
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
MIND Revenue Release Quarter 2 2025 Press Release
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Per capita expenditure prediction using model stacking based on satellite ima...
Programs and apps: productivity, graphics, security and other tools
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
sap open course for s4hana steps from ECC to s4
NewMind AI Weekly Chronicles - August'25 Week I
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KodekX | Application Modernization Development
The AUB Centre for AI in Media Proposal.docx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Big Data Technologies - Introduction.pptx

Service objects in Rails tests - factory_girl replacement