SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
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 ?

Weitere ähnliche Inhalte

Was ist angesagt?

From Web Developer to Hardware Developer
From Web Developer to Hardware DeveloperFrom Web Developer to Hardware Developer
From Web Developer to Hardware Developeralexshenoy
 
.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 StandardImmo 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 2013D
 
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 2013D
 
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
 
Cool stuff in E4 for developers
Cool stuff in E4 for developersCool stuff in E4 for developers
Cool stuff in E4 for developersMickael 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 rails3Andolasoft Inc
 

Was ist angesagt? (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
 

Ähnlich wie Speed up rspec tests - part 1

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 authenticationJay Jha
 
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 Utilitiesdpcobb
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails AppsRabble .
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It'sJim Lynch
 
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 trenchesYan 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 GuideThilo Utke
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test communityKerry Buckley
 
Ruby on Rails testing with Rspec
Ruby on Rails testing with RspecRuby on Rails testing with Rspec
Ruby on Rails testing with RspecBunlong Van
 

Ähnlich wie 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
 

Mehr von 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 visionRailwaymen
 
Railwaymen Booklet 2017
Railwaymen Booklet 2017Railwaymen Booklet 2017
Railwaymen Booklet 2017Railwaymen
 
Railwaymen Presentation 2017
Railwaymen Presentation 2017Railwaymen Presentation 2017
Railwaymen Presentation 2017Railwaymen
 
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 automationRailwaymen
 
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.1Railwaymen
 
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 exampleRailwaymen
 

Mehr von 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
 

Kürzlich hochgeladen

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Kürzlich hochgeladen (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

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 ?