SlideShare a Scribd company logo
SPEED UP RSPEC TESTS - PART1
Kamil Baćkowski
EXAMPLE FEATURE SPEC
describe 'Lists', type: :feature, js: true do
before do
# time consuming setup which takes about 6s
end
# each it takes about 1 second
it 'should be able to browse lists' do
end
it 'should be able to edit a list' do
end
it 'should be able to add companies to list' do
end
it 'should be able to remove companies from list' do
end
it 'should be able to delete a list' do
end
end
HOW LONG IT TAKES ?
rspec spec/features/lists_spec.rb
.....
Finished in 35.34 seconds (files took 9.99 seconds to load)
5 examples, 0 failures
HOW TO SPEED UP ?
We can combine all tests cases into one so that before
hook will execute only once.
describe 'Lists', type: :feature, js: true do
before do
# time consuming setup which takes about 6s
end
it "should be able to manage lists" do
#should be able to edit a list
...
#should be able to add companies to list
...
#should be able to remove companies from list
...
#should be able to delete a list
...
end
end
WE CAN DO IT BETTER!
Use aggregate_failures from rspec
require 'spec_helper'
describe 'Lists', type: :feature, js: true do
before do
# time consuming setup which takes about 6s
end
it 'should be able to manage lists' do
aggregate_failures 'should be able to browse lists' do
end
aggregate_failures 'should be able to edit a list' do
end
aggregate_failures 'should be able to add companies to list' do
end
aggregate_failures 'should be able to remove companies from list' do
end
aggregate_failures 'should be able to delete a list' do
end
end
end
HOW LONG IT TAKES ?
rspec spec/features/lists_spec.rb
.
Finished in 11.23 seconds (files took 9.99 seconds to load)
1 example, 0 failures
PROS & CONS
Tests runs 3x times faster
Tests becomes dependant on each other
WHAT HAPPENS WHEN
SOME TEST FAILS ?
By default all next aggregate_failures within block
will not execute
We can change this by adding aggregate_failures
metadata and then all aggregate_failures will be
executed and rspec will report all errors.
WHAT ABOUT
CONTROLLERS ?
describe CompanyOfficesController, type: :controller do
describe '#create' do
it 'validates params' do
sign_in user
post :create, name: ''
expect(response).to render_template('new')
expect(flash[:error]).not_to be_nil
end
it 'creates record when params are valid' do
sign_in user
expect do
post :create, name: 'My office'
end.to change(CompanyOffice, :count).by 1
end
it 'creates record when params are valid and redirect to index' do
sign_in user
post :create, name: 'My office'
expect(response).to redirect_to(company_offices_path)
end
end
end
USING
AGGREGATE_FAILURES
describe CompanyOfficesController, type: :controller do
describe '#create' do
it 'creates office' do
sign_in user
aggregate_failures 'validates params' do
post :create, name: ''
expect(response).to render_template('new')
expect(flash[:error]).not_to be_nil
end
aggregate_failures 'creates record when params are valid and redirect' do
expect do
post :create, name: 'My office'
end.to change(CompanyOffice, :count).by 1
expect(response).to redirect_to(company_offices_path)
end
end
end
end
SUMMARY
I encourage to use this for all features specs and some
controller specs which uses the same setup.
Questions ?

More Related Content

What's hot

From Web Developer to Hardware Developer
From Web Developer to Hardware DeveloperFrom Web Developer to Hardware Developer
From Web Developer to Hardware Developer
alexshenoy
 
.NET Conf 2018: Build Great Libraries using .NET Standard
.NET Conf 2018: Build Great Libraries using .NET Standard.NET Conf 2018: Build Great Libraries using .NET Standard
.NET Conf 2018: Build Great Libraries using .NET Standard
Immo Landwerth
 
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
D
 
The Dog Ate My Deployment - PHP Uncoference September 2013
The Dog Ate My Deployment - PHP Uncoference September 2013The Dog Ate My Deployment - PHP Uncoference September 2013
The Dog Ate My Deployment - PHP Uncoference September 2013
D
 
Dennis Benkert - The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
Dennis Benkert -  The Dog Ate My Deployment - Symfony Usergroup Berlin March ...Dennis Benkert -  The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
Dennis Benkert - The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
D
 
Compensation
CompensationCompensation
Compensation
prathap kumar
 
Cool stuff in E4 for developers
Cool stuff in E4 for developersCool stuff in E4 for developers
Cool stuff in E4 for developers
Mickael Istria
 
Ajax pagination using j query in rails3
Ajax pagination using j query in rails3Ajax pagination using j query in rails3
Ajax pagination using j query in rails3
Andolasoft Inc
 

What's hot (8)

From Web Developer to Hardware Developer
From Web Developer to Hardware DeveloperFrom Web Developer to Hardware Developer
From Web Developer to Hardware Developer
 
.NET Conf 2018: Build Great Libraries using .NET Standard
.NET Conf 2018: Build Great Libraries using .NET Standard.NET Conf 2018: Build Great Libraries using .NET Standard
.NET Conf 2018: Build Great Libraries using .NET Standard
 
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
The Dog Ate My Deployment - Symfony Usergroup Cologne July 2013
 
The Dog Ate My Deployment - PHP Uncoference September 2013
The Dog Ate My Deployment - PHP Uncoference September 2013The Dog Ate My Deployment - PHP Uncoference September 2013
The Dog Ate My Deployment - PHP Uncoference September 2013
 
Dennis Benkert - The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
Dennis Benkert -  The Dog Ate My Deployment - Symfony Usergroup Berlin March ...Dennis Benkert -  The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
Dennis Benkert - The Dog Ate My Deployment - Symfony Usergroup Berlin March ...
 
Compensation
CompensationCompensation
Compensation
 
Cool stuff in E4 for developers
Cool stuff in E4 for developersCool stuff in E4 for developers
Cool stuff in E4 for developers
 
Ajax pagination using j query in rails3
Ajax pagination using j query in rails3Ajax pagination using j query in rails3
Ajax pagination using j query in rails3
 

Similar to Speed up rspec tests - part 1

TDD & BDD
TDD & BDDTDD & BDD
TDD & BDD
Arvind Vyas
 
Rspec
RspecRspec
wtst3_pettichord3
wtst3_pettichord3wtst3_pettichord3
wtst3_pettichord3
tutorialsruby
 
wtst3_pettichord3
wtst3_pettichord3wtst3_pettichord3
wtst3_pettichord3
tutorialsruby
 
Performance testing using Jmeter for apps which needs authentication
Performance testing using Jmeter for apps which needs authenticationPerformance testing using Jmeter for apps which needs authentication
Performance testing using Jmeter for apps which needs authentication
Jay Jha
 
Rtt preso
Rtt presoRtt preso
Rtt preso
fdschoeneman
 
Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)
Yan Cui
 
Watch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML UtilitiesWatch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML Utilities
dpcobb
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
Rabble .
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
Jim Lynch
 
RSpec
RSpecRSpec
Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)
Yan Cui
 
AWS Lambda from the trenches
AWS Lambda from the trenchesAWS Lambda from the trenches
AWS Lambda from the trenches
Yan Cui
 
Serverless in production, an experience report (Going Serverless, 28 Feb 2018)
Serverless in production, an experience report (Going Serverless, 28 Feb 2018)Serverless in production, an experience report (Going Serverless, 28 Feb 2018)
Serverless in production, an experience report (Going Serverless, 28 Feb 2018)
Domas Lasauskas
 
Testing survival Guide
Testing survival GuideTesting survival Guide
Testing survival Guide
Thilo Utke
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
Scott van Kalken
 
Rspec
RspecRspec
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
Kerry Buckley
 
UI Testing
UI TestingUI Testing
UI Testing
Josh Black
 
Ruby on Rails testing with Rspec
Ruby on Rails testing with RspecRuby on Rails testing with Rspec
Ruby on Rails testing with Rspec
Bunlong Van
 

Similar to Speed up rspec tests - part 1 (20)

TDD & BDD
TDD & BDDTDD & BDD
TDD & BDD
 
Rspec
RspecRspec
Rspec
 
wtst3_pettichord3
wtst3_pettichord3wtst3_pettichord3
wtst3_pettichord3
 
wtst3_pettichord3
wtst3_pettichord3wtst3_pettichord3
wtst3_pettichord3
 
Performance testing using Jmeter for apps which needs authentication
Performance testing using Jmeter for apps which needs authenticationPerformance testing using Jmeter for apps which needs authentication
Performance testing using Jmeter for apps which needs authentication
 
Rtt preso
Rtt presoRtt preso
Rtt preso
 
Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)
 
Watch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML UtilitiesWatch Re-runs on your SQL Server with RML Utilities
Watch Re-runs on your SQL Server with RML Utilities
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
 
RSpec
RSpecRSpec
RSpec
 
Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)
 
AWS Lambda from the trenches
AWS Lambda from the trenchesAWS Lambda from the trenches
AWS Lambda from the trenches
 
Serverless in production, an experience report (Going Serverless, 28 Feb 2018)
Serverless in production, an experience report (Going Serverless, 28 Feb 2018)Serverless in production, an experience report (Going Serverless, 28 Feb 2018)
Serverless in production, an experience report (Going Serverless, 28 Feb 2018)
 
Testing survival Guide
Testing survival GuideTesting survival Guide
Testing survival Guide
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
 
Rspec
RspecRspec
Rspec
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
 
UI Testing
UI TestingUI Testing
UI Testing
 
Ruby on Rails testing with Rspec
Ruby on Rails testing with RspecRuby on Rails testing with Rspec
Ruby on Rails testing with Rspec
 

More from Railwaymen

How to start application development?
How to start application development?How to start application development?
How to start application development?
Railwaymen
 
We digitize your business vision
We digitize your business visionWe digitize your business vision
We digitize your business vision
Railwaymen
 
Railwaymen Booklet 2017
Railwaymen Booklet 2017Railwaymen Booklet 2017
Railwaymen Booklet 2017
Railwaymen
 
Railwaymen Presentation 2017
Railwaymen Presentation 2017Railwaymen Presentation 2017
Railwaymen Presentation 2017
Railwaymen
 
Will it pass or not? - A few words about automation
Will it pass or not?  - A few words about automationWill it pass or not?  - A few words about automation
Will it pass or not? - A few words about automation
Railwaymen
 
Using assm in service object
Using assm in service object Using assm in service object
Using assm in service object
Railwaymen
 
Mobile App Development
Mobile App Development Mobile App Development
Mobile App Development
Railwaymen
 
The evil scientist - Railwaymen DevDay vol.1
The evil scientist - Railwaymen DevDay vol.1The evil scientist - Railwaymen DevDay vol.1
The evil scientist - Railwaymen DevDay vol.1
Railwaymen
 
Smartwatch - something more than an additional screen for notifications?
Smartwatch - something more than an additional screen for notifications?Smartwatch - something more than an additional screen for notifications?
Smartwatch - something more than an additional screen for notifications?
Railwaymen
 
Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?
Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?
Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?
Railwaymen
 
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails exampleRoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
Railwaymen
 

More from Railwaymen (11)

How to start application development?
How to start application development?How to start application development?
How to start application development?
 
We digitize your business vision
We digitize your business visionWe digitize your business vision
We digitize your business vision
 
Railwaymen Booklet 2017
Railwaymen Booklet 2017Railwaymen Booklet 2017
Railwaymen Booklet 2017
 
Railwaymen Presentation 2017
Railwaymen Presentation 2017Railwaymen Presentation 2017
Railwaymen Presentation 2017
 
Will it pass or not? - A few words about automation
Will it pass or not?  - A few words about automationWill it pass or not?  - A few words about automation
Will it pass or not? - A few words about automation
 
Using assm in service object
Using assm in service object Using assm in service object
Using assm in service object
 
Mobile App Development
Mobile App Development Mobile App Development
Mobile App Development
 
The evil scientist - Railwaymen DevDay vol.1
The evil scientist - Railwaymen DevDay vol.1The evil scientist - Railwaymen DevDay vol.1
The evil scientist - Railwaymen DevDay vol.1
 
Smartwatch - something more than an additional screen for notifications?
Smartwatch - something more than an additional screen for notifications?Smartwatch - something more than an additional screen for notifications?
Smartwatch - something more than an additional screen for notifications?
 
Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?
Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?
Smartwatch - jednak coś więcej niż dodatkowy ekran na notyfikacje?
 
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails exampleRoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
 

Recently uploaded

Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 

Recently uploaded (20)

Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 

Speed up rspec tests - part 1

  • 1. SPEED UP RSPEC TESTS - PART1 Kamil Baćkowski
  • 2. EXAMPLE FEATURE SPEC describe 'Lists', type: :feature, js: true do before do # time consuming setup which takes about 6s end # each it takes about 1 second it 'should be able to browse lists' do end it 'should be able to edit a list' do end it 'should be able to add companies to list' do end it 'should be able to remove companies from list' do end it 'should be able to delete a list' do end end
  • 3. HOW LONG IT TAKES ? rspec spec/features/lists_spec.rb ..... Finished in 35.34 seconds (files took 9.99 seconds to load) 5 examples, 0 failures
  • 4. HOW TO SPEED UP ? We can combine all tests cases into one so that before hook will execute only once. describe 'Lists', type: :feature, js: true do before do # time consuming setup which takes about 6s end it "should be able to manage lists" do #should be able to edit a list ... #should be able to add companies to list ... #should be able to remove companies from list ... #should be able to delete a list ... end end
  • 5. WE CAN DO IT BETTER! Use aggregate_failures from rspec require 'spec_helper' describe 'Lists', type: :feature, js: true do before do # time consuming setup which takes about 6s end it 'should be able to manage lists' do aggregate_failures 'should be able to browse lists' do end aggregate_failures 'should be able to edit a list' do end aggregate_failures 'should be able to add companies to list' do end aggregate_failures 'should be able to remove companies from list' do end aggregate_failures 'should be able to delete a list' do end end end
  • 6. HOW LONG IT TAKES ? rspec spec/features/lists_spec.rb . Finished in 11.23 seconds (files took 9.99 seconds to load) 1 example, 0 failures
  • 7. PROS & CONS Tests runs 3x times faster Tests becomes dependant on each other
  • 8. WHAT HAPPENS WHEN SOME TEST FAILS ? By default all next aggregate_failures within block will not execute We can change this by adding aggregate_failures metadata and then all aggregate_failures will be executed and rspec will report all errors.
  • 9. WHAT ABOUT CONTROLLERS ? describe CompanyOfficesController, type: :controller do describe '#create' do it 'validates params' do sign_in user post :create, name: '' expect(response).to render_template('new') expect(flash[:error]).not_to be_nil end it 'creates record when params are valid' do sign_in user expect do post :create, name: 'My office' end.to change(CompanyOffice, :count).by 1 end it 'creates record when params are valid and redirect to index' do sign_in user post :create, name: 'My office' expect(response).to redirect_to(company_offices_path) end end end
  • 10. USING AGGREGATE_FAILURES describe CompanyOfficesController, type: :controller do describe '#create' do it 'creates office' do sign_in user aggregate_failures 'validates params' do post :create, name: '' expect(response).to render_template('new') expect(flash[:error]).not_to be_nil end aggregate_failures 'creates record when params are valid and redirect' do expect do post :create, name: 'My office' end.to change(CompanyOffice, :count).by 1 expect(response).to redirect_to(company_offices_path) end end end end
  • 11. SUMMARY I encourage to use this for all features specs and some controller specs which uses the same setup. Questions ?