SlideShare a Scribd company logo
1 of 22
Download to read offline
Cucumber-Rails

Integration Testing Tool for Rails 3
About Cucumber...
Acceptance Test Driven Development
Collaborative effort between the customer and the delivery
team
Cucumber Representation Requirements
Cucumber Representationofof Requirements

Customer Review
Customer Review
Automation
Automation
Why Cucumber ?? ( Advantages )


Clarity of Requirements



Communication Medium used viz Gherkin syntax



Self explanatory notes for 3rd person.



Communication gap is overcomed.
Cucumber Advantages (Cont...)





Can be used with other programming languages as
well.
Works with Ruby, Java, .NET, Flex or web applications
written in any language. It has been translated to over
40 spoken languages.
Relation between Rspec & Cucumber !

Cucumber

RSpec
Cucumber

- High Level Features
- Integration Testing

- Granular Level
- Unit Testing
Main Elements of Cucumber !!
Cucumber

Features

Step Definitions

.feature

.rb
Example

e.g user.feature

User

e.g user.rb
Features...
Example:
Feature: pay bill on-line
- In order to reduce the time I spend paying bills
- As a bank customer with a checking account
- I want to pay my bills on-line
Scenario: pay a bill
Given checking account with $50
And a payee named XYZ
And a bill for $37
When I pay the bill to XYZ
Then I should have $13 remaining in my checking account
And the payment of $37 to XYZ should be listed in Recent Payments
Step Definitions...
Given /^checking account with $(d+)$/ do |bill_amount|
# Ruby code here
End
Given /^a payee named (.*)$/ do |payee_name|
# Ruby code here
End
Given /^a bill for $(d+)$/ do |bill_amount|
# Ruby code here
end

Given checking account with $50
And a payee named XYZ
And a bill for $37
Step Definitions (Continued...)
When I pay the bill to XYZ
Then I should have $13 remaining in my checking account
And the payment of $37 to XYZ should be listed in Recent Payments
When /^I pay the bill to (.*)$/ do |payee_name|
# Ruby code here
End
Then /^I should have $(d+) remaining in my checking account$/ do |bill_amount|
# Ruby code here
End
Then /^the payment of $(d+) to (.*) should be listed in Recent Payments$/
do |amount,payee_name|
# Ruby code here
end
Cucumber with Rails 3...
gem 'cucumber-rails'
group :test do
gem 'cucumber-rails'
end

Bootstrap Cucumber
rails g cucumber:install
- config/cucumber.yml
- script/cucumber
- features/step_definitions
- features/support
- features/support/env.rb
- lib/tasks/cucumber.rake
”Background” feature
Feature: User Authorization
As an account owner
I should be able to view all the reports for my account
Background:
Given the user "xyz" is logged-in
And has the role as "account owner"
Scenario: User "xyz" view his reports
When the user "xyz" access the reports page
Then user "xyz" should see all his reports
Scenario Outlines
Feature: User Authorization
As an account owner
I should be able to view all the reports & employees for my account
Background:
Given the user "xyz" is logged-in
And has the role as "account owner"
Scenario Outline: User "xyz" view his reports & employees
When the account owner <user> access the <page> page
Then account owner <user> should see <count> <page>
Examples:
|user|page|count|
|abc|reports|500|
|xyz|reports|700|
|xyz|employees|20|
Tags...


To organize your features and schenario's
@signin
Feature: Signin

@signup
Feature: Signup

@login
Scenario: Login
Given Credentails...
When logged in
Then...

@signup @resourcename
Scenario: Signup
Given Information...
When Signed up
Then...

@fyp
Scenario: Forgot your password
Given registered email
When clicked on forgot your password
Then email should be delivered
Execution...


All Features
> cucumber
OR
> cucumber features/



Particular Feature
> cucumber features/<file>.feature



Particular Test case scenario
> cucumber features/ --tags @signin
Cucumber.yml
default: --format progress features
html_report: --format html --out=features_report.html features
signup_report : --tags @signup features

Execution:

Feature:

> cucumber --profile html_report
> cucumber --profile signup_report

@signup
Scenario:ABC
Given...

Scenario:XYZ
Given...

When...

When...

Then...

Then...
Ambiguous Steps !!
Scenario1: Different users view reports
When the user "xyz" access the reports page

Feature

Then user "xyz" should see all his reports
When /^the user (.*) access the reports page$/ do | user_name |
# Ruby code here

Step-Defn

End
Scenario2: User ”xyz” view different pages
When the user xyz access the ”reports” page

Feature

Then user xyz should see all his ”reports”
When /^the user xyz access the (.*) page$/ do | page_name |
# Ruby code here
End

Step-Defn
Redundant Steps !!
Scenario: User ”xyz” view his reports
When the user ”xyz” access the ”reports” page
Then user ”xyz” should see all his reports

Reports.feature

Scenario: User ”xyz” view his transactions
When the user ”xyz” access the ”transactions” page
Then user ”xyz” should see all his transactions

Trans.feature

When /^the user (.*) access the (.*) page$/ do | user_name, page |
# Ruby code here
End
”Spork” ( What &

Why

)



To speed up the running of an application’s tests



Preloads the Rails Environment once at the start





The whole Rails initialization process is skipped, saving
valuable seconds off of your spec runs
A little analysis reveals that execution time gets
reduced by about 3.5 min or so in case of 900
examples
When to restart Spork ??




No need to restart the Spork server if there are any changes in your test
cases written under ”model-spec” or say ”controller-spec”
Need to restart the Spork server for any changes in the configuration in
your application.
examples:
- change in Factory's
- spec_helpers
- spec/support/...
- .rspec
Get Spork working on Rails 3 & Rspec 2


Add ”Spork” gem into your Gemfile



Configure the option --drb on a new line in your .rspec file



Modify your spec_helper.rb as follows:
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
...
end



Finally start the ”Spork” server as :$ bundle exec spork

.rspec
--color
--drb
Get Spork working on Rails 3 & Cuke


Add ”Spork” gem into your Gemfile



Configure the option --drb on a new line in your cucumber.yml file



Modify your features/support/env.rb as follows:
Cucumber.yml
require 'spork'
Spork.prefork do

pretty_format: --drb --format pretty features

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) +
'/../../config/environment')
require 'cucumber/rails/rspec'
end


Finally start the ”Spork” server as : $ bundle exec spork cucumber
Thank You !!

More Related Content

What's hot

What's hot (20)

Brief Introduction to Ember
Brief Introduction to EmberBrief Introduction to Ember
Brief Introduction to Ember
 
Ruby On Grape
Ruby On GrapeRuby On Grape
Ruby On Grape
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumber
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
Using assm in service object
Using assm in service object Using assm in service object
Using assm in service object
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Workshop 24: React Native Introduction
Workshop 24: React Native IntroductionWorkshop 24: React Native Introduction
Workshop 24: React Native Introduction
 
The Evolution of Airbnb's Frontend
The Evolution of Airbnb's FrontendThe Evolution of Airbnb's Frontend
The Evolution of Airbnb's Frontend
 
What's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overviewWhat's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overview
 
Symfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processingSymfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processing
 
Wire once, rewire twice! (Haskell exchange-2018)
Wire once, rewire twice! (Haskell exchange-2018)Wire once, rewire twice! (Haskell exchange-2018)
Wire once, rewire twice! (Haskell exchange-2018)
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Rack
RackRack
Rack
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
Rack
RackRack
Rack
 
How to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorialHow to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorial
 
RoR 101: Session 6
RoR 101: Session 6RoR 101: Session 6
RoR 101: Session 6
 
AngularJS meets Rails
AngularJS meets RailsAngularJS meets Rails
AngularJS meets Rails
 
How angularjs saves rails
How angularjs saves railsHow angularjs saves rails
How angularjs saves rails
 

Similar to Ninad cucumber rails

Socket applications
Socket applicationsSocket applications
Socket applications
João Moura
 

Similar to Ninad cucumber rails (20)

End-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemEnd-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystem
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails
 
Serverless Apps with AWS Step Functions
Serverless Apps with AWS Step FunctionsServerless Apps with AWS Step Functions
Serverless Apps with AWS Step Functions
 
Speedy TDD with Rails
Speedy TDD with RailsSpeedy TDD with Rails
Speedy TDD with Rails
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
Cucumber
CucumberCucumber
Cucumber
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
How to build 1000 microservices with Kafka and thrive
How to build 1000 microservices with Kafka and thriveHow to build 1000 microservices with Kafka and thrive
How to build 1000 microservices with Kafka and thrive
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
 
Advanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesAdvanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutes
 
AWS Lambda from the trenches
AWS Lambda from the trenchesAWS Lambda from the trenches
AWS Lambda from the trenches
 
10 Lessons Learned from using Kafka in 1000 microservices - ScalaUA
10 Lessons Learned from using Kafka in 1000 microservices - ScalaUA10 Lessons Learned from using Kafka in 1000 microservices - ScalaUA
10 Lessons Learned from using Kafka in 1000 microservices - ScalaUA
 
Streamlined Geek Talk
Streamlined Geek TalkStreamlined Geek Talk
Streamlined Geek Talk
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Serverless Beyond Functions - CTO Club Made in JLM
Serverless Beyond Functions - CTO Club Made in JLMServerless Beyond Functions - CTO Club Made in JLM
Serverless Beyond Functions - CTO Club Made in JLM
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Ninad cucumber rails

  • 2. About Cucumber... Acceptance Test Driven Development Collaborative effort between the customer and the delivery team Cucumber Representation Requirements Cucumber Representationofof Requirements Customer Review Customer Review Automation Automation
  • 3. Why Cucumber ?? ( Advantages )  Clarity of Requirements  Communication Medium used viz Gherkin syntax  Self explanatory notes for 3rd person.  Communication gap is overcomed.
  • 4. Cucumber Advantages (Cont...)   Can be used with other programming languages as well. Works with Ruby, Java, .NET, Flex or web applications written in any language. It has been translated to over 40 spoken languages.
  • 5. Relation between Rspec & Cucumber ! Cucumber RSpec Cucumber - High Level Features - Integration Testing - Granular Level - Unit Testing
  • 6. Main Elements of Cucumber !! Cucumber Features Step Definitions .feature .rb Example e.g user.feature User e.g user.rb
  • 7. Features... Example: Feature: pay bill on-line - In order to reduce the time I spend paying bills - As a bank customer with a checking account - I want to pay my bills on-line Scenario: pay a bill Given checking account with $50 And a payee named XYZ And a bill for $37 When I pay the bill to XYZ Then I should have $13 remaining in my checking account And the payment of $37 to XYZ should be listed in Recent Payments
  • 8. Step Definitions... Given /^checking account with $(d+)$/ do |bill_amount| # Ruby code here End Given /^a payee named (.*)$/ do |payee_name| # Ruby code here End Given /^a bill for $(d+)$/ do |bill_amount| # Ruby code here end Given checking account with $50 And a payee named XYZ And a bill for $37
  • 9. Step Definitions (Continued...) When I pay the bill to XYZ Then I should have $13 remaining in my checking account And the payment of $37 to XYZ should be listed in Recent Payments When /^I pay the bill to (.*)$/ do |payee_name| # Ruby code here End Then /^I should have $(d+) remaining in my checking account$/ do |bill_amount| # Ruby code here End Then /^the payment of $(d+) to (.*) should be listed in Recent Payments$/ do |amount,payee_name| # Ruby code here end
  • 10. Cucumber with Rails 3... gem 'cucumber-rails' group :test do gem 'cucumber-rails' end Bootstrap Cucumber rails g cucumber:install - config/cucumber.yml - script/cucumber - features/step_definitions - features/support - features/support/env.rb - lib/tasks/cucumber.rake
  • 11. ”Background” feature Feature: User Authorization As an account owner I should be able to view all the reports for my account Background: Given the user "xyz" is logged-in And has the role as "account owner" Scenario: User "xyz" view his reports When the user "xyz" access the reports page Then user "xyz" should see all his reports
  • 12. Scenario Outlines Feature: User Authorization As an account owner I should be able to view all the reports & employees for my account Background: Given the user "xyz" is logged-in And has the role as "account owner" Scenario Outline: User "xyz" view his reports & employees When the account owner <user> access the <page> page Then account owner <user> should see <count> <page> Examples: |user|page|count| |abc|reports|500| |xyz|reports|700| |xyz|employees|20|
  • 13. Tags...  To organize your features and schenario's @signin Feature: Signin @signup Feature: Signup @login Scenario: Login Given Credentails... When logged in Then... @signup @resourcename Scenario: Signup Given Information... When Signed up Then... @fyp Scenario: Forgot your password Given registered email When clicked on forgot your password Then email should be delivered
  • 14. Execution...  All Features > cucumber OR > cucumber features/  Particular Feature > cucumber features/<file>.feature  Particular Test case scenario > cucumber features/ --tags @signin
  • 15. Cucumber.yml default: --format progress features html_report: --format html --out=features_report.html features signup_report : --tags @signup features Execution: Feature: > cucumber --profile html_report > cucumber --profile signup_report @signup Scenario:ABC Given... Scenario:XYZ Given... When... When... Then... Then...
  • 16. Ambiguous Steps !! Scenario1: Different users view reports When the user "xyz" access the reports page Feature Then user "xyz" should see all his reports When /^the user (.*) access the reports page$/ do | user_name | # Ruby code here Step-Defn End Scenario2: User ”xyz” view different pages When the user xyz access the ”reports” page Feature Then user xyz should see all his ”reports” When /^the user xyz access the (.*) page$/ do | page_name | # Ruby code here End Step-Defn
  • 17. Redundant Steps !! Scenario: User ”xyz” view his reports When the user ”xyz” access the ”reports” page Then user ”xyz” should see all his reports Reports.feature Scenario: User ”xyz” view his transactions When the user ”xyz” access the ”transactions” page Then user ”xyz” should see all his transactions Trans.feature When /^the user (.*) access the (.*) page$/ do | user_name, page | # Ruby code here End
  • 18. ”Spork” ( What & Why )  To speed up the running of an application’s tests  Preloads the Rails Environment once at the start   The whole Rails initialization process is skipped, saving valuable seconds off of your spec runs A little analysis reveals that execution time gets reduced by about 3.5 min or so in case of 900 examples
  • 19. When to restart Spork ??   No need to restart the Spork server if there are any changes in your test cases written under ”model-spec” or say ”controller-spec” Need to restart the Spork server for any changes in the configuration in your application. examples: - change in Factory's - spec_helpers - spec/support/... - .rspec
  • 20. Get Spork working on Rails 3 & Rspec 2  Add ”Spork” gem into your Gemfile  Configure the option --drb on a new line in your .rspec file  Modify your spec_helper.rb as follows: require 'spork' Spork.prefork do ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' ... end  Finally start the ”Spork” server as :$ bundle exec spork .rspec --color --drb
  • 21. Get Spork working on Rails 3 & Cuke  Add ”Spork” gem into your Gemfile  Configure the option --drb on a new line in your cucumber.yml file  Modify your features/support/env.rb as follows: Cucumber.yml require 'spork' Spork.prefork do pretty_format: --drb --format pretty features ENV["RAILS_ENV"] ||= 'test' require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'cucumber/rails/rspec' end  Finally start the ”Spork” server as : $ bundle exec spork cucumber