SlideShare a Scribd company logo
1 of 37
Autotesting Rails 
Covering Rails MVP with autotests
Contents 
● Why? 
● Rspec, shoulda-matchers, FactoryGirl 
● Cucumber 
● Simplecov 
● What next?
WHY?
Problem 
● MVP is ready 
● First customers 
● Not stable 
FAIL
Solution 
● Manual testing = expensive (time + $) 
● Autotesting? 
● Yes, we can!
TDD - Rspec, shoulda-matchers, FactoryGirl
Rspec - testing framework 
● All instructions 
https://github.com/rspec/rspec-rails
Rspec - update Gemfile 
group :development, :test do 
gem 'rspec-rails', '~> 3.0' 
end
Rspec - install and generate files 
$ bundle install --without production 
$ rails generate rspec:install 
$ bundle exec rspec
Shoulda-matchers - testing one liners 
● All instructions 
https://github.com/thoughtbot/shoulda-matchers
Shoulda - update Gemfile 
group :test do 
gem 'shoulda-matchers', require: false 
end 
Run 
$ bundle install --without production
Shoulda - update rails_helper 
● in spec/rails_helper.rb 
● after 
require 'rspec/rails' 
● add 
require 'shoulda/matchers'
FactoryGirl - setting up test objects 
● All instructions 
https://github.com/thoughtbot/factory_girl
FactoryGirl - update Gemfile 
group :test do 
gem 'factory_girl' 
end 
Run 
$ bundle install --without production
FactoryGirl - update Gemfile 
group :test do 
gem 'factory_girl' 
end 
Run 
$ bundle install --without production
Generate test files for existing model 
Run (replace Post with your existing model) 
$ rails generate model Post -s 
See generated spec and factory files
BDD - Cucumber
Cucumber - testing framework 
● All instructions specific to Rails 
https://github.com/cucumber/cucumber-rails 
● And overall http://cukes.info/
Cucumber - update Gemfile 
group :test do 
gem 'cucumber-rails', :require => false 
gem 'database_cleaner' 
end
Cucumber - update env.rb 
Add to the end of features/support/env.rb 
World FactoryGirl::Syntax::Methods
Cucumber - install 
$ bundle install --without production 
$ rails generate cucumber:install 
$ bundle exec cucumber
Capybara-webkit - testing javascript 
● All instructions 
o https://github.com/thoughtbot/capybara-webkit 
o https://github.com/leonid-shevtsov/headless
Capybara-webkit - update Gemfile 
group :test do 
gem 'capybara-webkit', '~> 1.3.0' 
gem 'headless' 
end 
Run 
$ sudo apt-get install xvfb 
$ bundle install --without production
Cucumber - update env.rb 
Add to features/support/env.rb 
Capybara.app = Rack::ShowExceptions.new(Rails.application) 
# use webkit driver for javascript testing 
Capybara.javascript_driver = :webkit 
if Capybara.javascript_driver == :webkit 
require 'headless' 
headless = Headless.new 
headless.start 
end
Code coverage with tests
Simplecov - code coverage 
● All instructions 
https://github.com/colszowka/simplecov
Simplecov - update Gemfile 
group :test do 
gem 'simplecov', :require => false 
end 
Run 
$ bundle install --without production
Simplecov - update rails_helper 
Add at the very top of spec/rails_helper.rb 
require 'simplecov' 
SimpleCov.command_name 'RSpec'
Simplecov - update env.rb 
Add at the very top of features/support/env.rb 
require 'simplecov' 
SimpleCov.command_name 'Cucumber'
Add file .simplecov to rails app root 
SimpleCov.start 'rails' do 
end
Update .gitignore 
Append to the file 
/coverage
Code coverage 
Run 
$ bundle exec rspec 
$ bundle exec cucumber 
Open in the browser 
coverage/index.html
Code coverage report
What next?
Get down to work and write tests 
● https://www.google.com.ua/search?q=rspec 
+tutorial 
● https://www.google.com.ua/search?q=cucum 
ber+tutorial
Setup continuous integration 
● $$$ Jira + Stash + Bamboo 
● Free (even private) Bitbucket + Jenkins* 
● Free Github + Jenkins* 
* you need servers
Anton Naumenko 
www.syndicode.co

More Related Content

What's hot

Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Puppet
 
Vagrant Binding JayDay 2013
Vagrant Binding JayDay 2013Vagrant Binding JayDay 2013
Vagrant Binding JayDay 2013
Hendrik Ebbers
 

What's hot (20)

JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
 
OSCamp 2019 | #3 Ansible: Automated Tests of Ansible code with GitLab, Vagran...
OSCamp 2019 | #3 Ansible: Automated Tests of Ansible code with GitLab, Vagran...OSCamp 2019 | #3 Ansible: Automated Tests of Ansible code with GitLab, Vagran...
OSCamp 2019 | #3 Ansible: Automated Tests of Ansible code with GitLab, Vagran...
 
Puppet in the Pipeline
Puppet in the PipelinePuppet in the Pipeline
Puppet in the Pipeline
 
Developing and Testing with Enhanced Oscar
Developing and Testing with Enhanced OscarDeveloping and Testing with Enhanced Oscar
Developing and Testing with Enhanced Oscar
 
Puppet Camp Denver 2015: Developing and Testing with Enhanced Oscar
Puppet Camp Denver 2015: Developing and Testing with Enhanced OscarPuppet Camp Denver 2015: Developing and Testing with Enhanced Oscar
Puppet Camp Denver 2015: Developing and Testing with Enhanced Oscar
 
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
Oscar: Rapid Iteration with Vagrant and Puppet Enterprise - PuppetConf 2013
 
Automated Drupal deployment with Git and Capistrano
Automated Drupal deployment with Git and CapistranoAutomated Drupal deployment with Git and Capistrano
Automated Drupal deployment with Git and Capistrano
 
Capybara
CapybaraCapybara
Capybara
 
Using Vagrant
Using VagrantUsing Vagrant
Using Vagrant
 
Log monitoring with Logstash and Icinga
Log monitoring with Logstash and IcingaLog monitoring with Logstash and Icinga
Log monitoring with Logstash and Icinga
 
Vagrant Binding JayDay 2013
Vagrant Binding JayDay 2013Vagrant Binding JayDay 2013
Vagrant Binding JayDay 2013
 
Instrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con GitlabInstrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con Gitlab
 
Jenkins to Gitlab - Intelligent Build-Pipelines
Jenkins to Gitlab - Intelligent Build-PipelinesJenkins to Gitlab - Intelligent Build-Pipelines
Jenkins to Gitlab - Intelligent Build-Pipelines
 
Two-Step Deployment with Rails
Two-Step Deployment with RailsTwo-Step Deployment with Rails
Two-Step Deployment with Rails
 
Lifthub (rpscala #31)
Lifthub (rpscala #31)Lifthub (rpscala #31)
Lifthub (rpscala #31)
 
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
 
Lifthub (#rpscala 26)
Lifthub (#rpscala 26)Lifthub (#rpscala 26)
Lifthub (#rpscala 26)
 
Tomcat Maven Plugin
Tomcat Maven PluginTomcat Maven Plugin
Tomcat Maven Plugin
 
Painless Deployment with Capistrano
Painless Deployment with CapistranoPainless Deployment with Capistrano
Painless Deployment with Capistrano
 
Виталий Редько "React + Redux: performance & scalability"
Виталий Редько "React + Redux: performance & scalability"Виталий Редько "React + Redux: performance & scalability"
Виталий Редько "React + Redux: performance & scalability"
 

Similar to Autotesting rails app

Jenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh VuJenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh Vu
Framgia Vietnam
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
Clinton Dreisbach
 

Similar to Autotesting rails app (20)

Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Capybara with Rspec
Capybara with RspecCapybara with Rspec
Capybara with Rspec
 
Jenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh VuJenkins and rails app - Le Dinh Vu
Jenkins and rails app - Le Dinh Vu
 
oSC-2023-Cross-Build.pdf
oSC-2023-Cross-Build.pdfoSC-2023-Cross-Build.pdf
oSC-2023-Cross-Build.pdf
 
Using rbenv in Production
Using rbenv in ProductionUsing rbenv in Production
Using rbenv in Production
 
Capybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyCapybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using ruby
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Making TDD [Somewhat] Bearable on OpenStack
Making TDD [Somewhat] Bearable on OpenStackMaking TDD [Somewhat] Bearable on OpenStack
Making TDD [Somewhat] Bearable on OpenStack
 
Laravel Day / Deploy
Laravel Day / DeployLaravel Day / Deploy
Laravel Day / Deploy
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!
 
Generators
GeneratorsGenerators
Generators
 
ASP.NET 5 auf Raspberry PI & docker
ASP.NET 5 auf Raspberry PI & dockerASP.NET 5 auf Raspberry PI & docker
ASP.NET 5 auf Raspberry PI & docker
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Continuous Integration Testing in Django
Continuous Integration Testing in DjangoContinuous Integration Testing in Django
Continuous Integration Testing in Django
 
Deploy like a pro!
Deploy like a pro!Deploy like a pro!
Deploy like a pro!
 
Docker and DevOps --- new IT culture
Docker and DevOps --- new IT cultureDocker and DevOps --- new IT culture
Docker and DevOps --- new IT culture
 
Использование Docker в CI / Александр Акбашев (HERE Technologies)
Использование Docker в CI / Александр Акбашев (HERE Technologies)Использование Docker в CI / Александр Акбашев (HERE Technologies)
Использование Docker в CI / Александр Акбашев (HERE Technologies)
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modules
 

More from Anton Naumenko (6)

Bila kasa pitch
Bila kasa pitchBila kasa pitch
Bila kasa pitch
 
Syndicode software development - dedicated team
Syndicode   software development - dedicated teamSyndicode   software development - dedicated team
Syndicode software development - dedicated team
 
Address
AddressAddress
Address
 
Letsdoiter lessons learned
Letsdoiter   lessons learnedLetsdoiter   lessons learned
Letsdoiter lessons learned
 
Letsdoiter survey report
Letsdoiter   survey reportLetsdoiter   survey report
Letsdoiter survey report
 
Letsdoiter pitch deck
Letsdoiter pitch deckLetsdoiter pitch deck
Letsdoiter pitch deck
 

Recently uploaded

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 

Autotesting rails app

  • 1. Autotesting Rails Covering Rails MVP with autotests
  • 2. Contents ● Why? ● Rspec, shoulda-matchers, FactoryGirl ● Cucumber ● Simplecov ● What next?
  • 4. Problem ● MVP is ready ● First customers ● Not stable FAIL
  • 5. Solution ● Manual testing = expensive (time + $) ● Autotesting? ● Yes, we can!
  • 6. TDD - Rspec, shoulda-matchers, FactoryGirl
  • 7. Rspec - testing framework ● All instructions https://github.com/rspec/rspec-rails
  • 8. Rspec - update Gemfile group :development, :test do gem 'rspec-rails', '~> 3.0' end
  • 9. Rspec - install and generate files $ bundle install --without production $ rails generate rspec:install $ bundle exec rspec
  • 10. Shoulda-matchers - testing one liners ● All instructions https://github.com/thoughtbot/shoulda-matchers
  • 11. Shoulda - update Gemfile group :test do gem 'shoulda-matchers', require: false end Run $ bundle install --without production
  • 12. Shoulda - update rails_helper ● in spec/rails_helper.rb ● after require 'rspec/rails' ● add require 'shoulda/matchers'
  • 13. FactoryGirl - setting up test objects ● All instructions https://github.com/thoughtbot/factory_girl
  • 14. FactoryGirl - update Gemfile group :test do gem 'factory_girl' end Run $ bundle install --without production
  • 15. FactoryGirl - update Gemfile group :test do gem 'factory_girl' end Run $ bundle install --without production
  • 16. Generate test files for existing model Run (replace Post with your existing model) $ rails generate model Post -s See generated spec and factory files
  • 18. Cucumber - testing framework ● All instructions specific to Rails https://github.com/cucumber/cucumber-rails ● And overall http://cukes.info/
  • 19. Cucumber - update Gemfile group :test do gem 'cucumber-rails', :require => false gem 'database_cleaner' end
  • 20. Cucumber - update env.rb Add to the end of features/support/env.rb World FactoryGirl::Syntax::Methods
  • 21. Cucumber - install $ bundle install --without production $ rails generate cucumber:install $ bundle exec cucumber
  • 22. Capybara-webkit - testing javascript ● All instructions o https://github.com/thoughtbot/capybara-webkit o https://github.com/leonid-shevtsov/headless
  • 23. Capybara-webkit - update Gemfile group :test do gem 'capybara-webkit', '~> 1.3.0' gem 'headless' end Run $ sudo apt-get install xvfb $ bundle install --without production
  • 24. Cucumber - update env.rb Add to features/support/env.rb Capybara.app = Rack::ShowExceptions.new(Rails.application) # use webkit driver for javascript testing Capybara.javascript_driver = :webkit if Capybara.javascript_driver == :webkit require 'headless' headless = Headless.new headless.start end
  • 26. Simplecov - code coverage ● All instructions https://github.com/colszowka/simplecov
  • 27. Simplecov - update Gemfile group :test do gem 'simplecov', :require => false end Run $ bundle install --without production
  • 28. Simplecov - update rails_helper Add at the very top of spec/rails_helper.rb require 'simplecov' SimpleCov.command_name 'RSpec'
  • 29. Simplecov - update env.rb Add at the very top of features/support/env.rb require 'simplecov' SimpleCov.command_name 'Cucumber'
  • 30. Add file .simplecov to rails app root SimpleCov.start 'rails' do end
  • 31. Update .gitignore Append to the file /coverage
  • 32. Code coverage Run $ bundle exec rspec $ bundle exec cucumber Open in the browser coverage/index.html
  • 35. Get down to work and write tests ● https://www.google.com.ua/search?q=rspec +tutorial ● https://www.google.com.ua/search?q=cucum ber+tutorial
  • 36. Setup continuous integration ● $$$ Jira + Stash + Bamboo ● Free (even private) Bitbucket + Jenkins* ● Free Github + Jenkins* * you need servers