SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Cucumber	
  
  Use	
  it,	
  bitches	
  
Here’s	
  how	
  to	
  get	
  started	
  
                                                 (it’s	
  surprisingly	
  easy)	
  


•  I’m	
  assuming	
  you’ve	
  got	
  Rails	
  3/RVM/all	
  that	
  
   jazz	
  working.	
  
•  If	
  you	
  don’t,	
  I	
  can’t	
  help	
  you…	
  



	
   	
  …and,	
  someIme	
  when	
  you	
  least	
  expect	
  it,	
  MaK	
  will	
  hurt	
  you.	
  
Here’s	
  how	
  to	
  get	
  started	
  
                            (it’s	
  surprisingly	
  easy)	
  

•  Add	
  to	
  Gemfile:	
  
            group :test do	
               gem 'capybara'	
	
   	
        gem 'database_cleaner'	
               gem 'cucumber-rails'	
               gem 'cucumber'	
               gem 'rspec-rails'	
               gem 'spork'	
               gem 'launchy'	
               gem 'machinist', '>= 2.0.0.beta2'	
               gem 'faker'	
            end	

•  Bundle	
  install	
  

	
   	
  
Here’s	
  how	
  to	
  get	
  started	
  
                                   (it’s	
  surprisingly	
  easy)	
  

    •  Now,	
  to	
  set	
  up	
  your	
  rails	
  app.	
  
	    	    bundle exec rails g cucumber:install --capybara	
	    	    bundle exec rails g machinist:install	

	    	    touch features/support/blueprints.rb	


    •  Add	
  this	
  line	
  to	
  blueprints.rb:	
  
	    	    require 'machinist/active_record’	


    •  Edit	
  this	
  line	
  in	
  env.rb	
  (in	
  features/support)	
  
Cucumber::Rails::World.use_transactional_fixtures = false
Why	
  we’re	
  using	
  Machinist	
  
•  I	
  wanted	
  to	
  start	
  from	
  with	
  a	
  blank	
  slate,	
  
   installing	
  Cucumber	
  and	
  nothing	
  else.	
  
•  However,	
  I	
  quickly	
  found	
  that	
  Machinist	
  makes	
  
   things	
  a	
  lot	
  easier.	
  

•  Machinist	
  gives	
  you	
  blueprints,	
  greatly	
  
   simplifying	
  the	
  creaIon	
  of	
  mock	
  objects.	
  
•  More	
  later…	
  
WriIng	
  features	
  
@classifieds	
Feature: Classified Ads	
  In order to buy and sell things	
  As a logged in user	
  I want to be able to view, add and manage classified ads	

  Background:	
    Given I am logged into cas as "Peter" "Portal" with an
username of "00700001"	
    And I have created another user	
    And I am on the classifieds index page	
	    	
  Scenario: Should be able to see the ads	
    Then I should see "Glamlife Marketplace"	

  Scenario: Should be able to add an ad	
    When I follow "Create a new ad"	
    And I fill in "classified_title" with "Testing title"	
    And I select "For Sale" from "classified_ad_type"
Baby	
  steps	
  
•  Each	
  of	
  those	
  lines,	
  aUer	
  the	
  feature	
  definiIon,	
  is	
  
   called	
  a	
  ‘step’.	
  
•  There	
  are	
  a	
  bunch	
  of	
  simple	
  steps	
  that	
  Cucumber	
  
   knows	
  all	
  about,	
  but	
  someImes	
  you	
  will	
  want	
  to	
  
   do	
  something	
  more	
  complex	
  than	
  “click	
  this	
  link”.	
  
•  A	
  good	
  example	
  is	
  logging	
  in	
  using	
  CAS:	
  
    Given I am logged into cas as "Peter" "Portal" with an
    username of "00700001"	
  



•  How	
  does	
  cucumber	
  know	
  what	
  to	
  do	
  with	
  this?	
  
Defining	
  steps	
  
•  So	
  that	
  Cucumber	
  understands	
  our	
  steps,	
  we	
  
   have	
  to	
  define	
  them:	
  
       Given /^I am logged into cas as "(.*)" "(.*)" with an username of
       "(.*)"$/ do | firstname, surname, username |	
       	    @user = User.make!(	
       	        :username => username, 	
       	        :firstname => firstname, 	
       	        :surname => surname, 	
       	        :dob => "01/01/1990",	
                :home_address1 => "1 Street Street",	
                :home_email => "pedro@portal.po",	
                :home_phone => "1234567890",	
                :term_address1 => "5 Glam Street",	
                :term_phone => "0987654321",	
                :term_mobile => "5674839201",	
                :user_status => "Student",	
                :user_type => "UGStudent"	
       	        )	
            CASClient::Frameworks::Rails::Filter.fake(username)	
            visit("/cas_session?force_cas_user=#{@user.username}")	
       end
CAS	
  hates	
  green	
  salad	
  fruits	
  
•  CAS	
  and	
  Cucumber	
  don’t	
  get	
  on	
  at	
  all	
  well.	
  
•  Luckily	
  the	
  rubycas-­‐client	
  gem	
  developer	
  has	
  
   put	
  in	
  a	
  way	
  for	
  Cucumber	
  to	
  get	
  around	
  CAS	
  
   without	
  taking	
  a	
  beaIng.	
  
       CASClient::Frameworks::Rails::Filter.fake(username)	
  

•  Adding	
  this	
  line	
  to	
  our	
  step	
  definiIon	
  lets	
  
   Cucumber	
  in	
  the	
  back	
  door.	
  
•  Green	
  peppers,	
  however,	
  can	
  get	
  bent.	
  
Blueprints	
  and	
  ‘make!’	
  
•  Blueprints	
  allow	
  you	
  to	
  pre-­‐define	
  instances	
  of	
  
   your	
  models,	
  so	
  you	
  don’t	
  have	
  to	
  fill	
  in	
  all	
  the	
  
   details.	
  
•  Using	
  make!	
  instead	
  of	
  create	
  uses	
  these	
  
   blueprints.	
  	
  




•  Let’s	
  have	
  a	
  look	
  at	
  a	
  blueprint.rb	
  file…	
  
Blueprints	
  and	
  ‘make’	
  
Chunk.blueprint do	
  title             { sentence }	
  content           { sentence }	
end	

Classified.blueprint do	
  title             { sentence }	
  ad_type           { ad_type }	
  body              { paragraphs }	
  reason            { sentence }	
  image             { File.new("#{Rails.root.to_s}/
  features/support/upload-files/image.png") }	
  moderated         { 0 }	
  completed         { 0 }	
end
Faking	
  data	
  
•  The	
  variables	
  in	
  the	
  last	
  slide	
  are	
  set	
  up	
  to	
  
   create	
  random	
  data,	
  oUen	
  using	
  Faker.	
  
      sentence	
  =	
  Faker::Lorem.sentence	
  
      paragraphs	
  =	
  Faker::Lorem.paragraphs.join("nn")	
  
      ad_type	
  =	
  "For	
  Sale"	
  
      name	
  =	
  Faker::Name.name	
  
      first_name	
  =	
  Faker::Name.first_name	
  
      last_name	
  =	
  Faker::Name.last_name	
  
      username	
  =	
  rand(99999999).to_s	
  
Paths	
  
•  In	
  olden	
  Imes,	
  people	
  used	
  to	
  have	
  to	
  put	
  paths	
  
     to	
  pages	
  into	
  their	
  features.	
  
•  This	
  is	
  ‘briKle’	
  because	
  if	
  a	
  path	
  changes,	
  your	
  
     test	
  will	
  break.	
  To	
  miIgate	
  this	
  problem,	
  paths	
  
     are	
  defined	
  in	
  paths.rb	
  in	
  features/support,	
  eg:	
  
	
   	
  	
   when /the homes?page/	
	       		 '/'	
•  This	
  way,	
  you	
  only	
  have	
  to	
  update	
  one	
  file	
  when	
  
   something	
  changes.	
  
•  The	
  same	
  can	
  be	
  done	
  with	
  selectors…	
  
Selectors	
  
•  Selectors	
  are	
  used	
  to	
  ‘select’	
  a	
  specific	
  instance	
  of	
  
     something	
  on	
  a	
  page.	
  
•  For	
  example,	
  you	
  might	
  have	
  the	
  same	
  text	
  
     appear	
  in	
  more	
  than	
  one	
  place	
  and	
  want	
  to	
  
     restrict	
  it	
  to	
  checking	
  a	
  specific	
  div.	
  
•  For	
  example:	
  
	
   	
   Then I should see "Ad was successfully created"
   	within ".flash.notice”	
•  This	
  checks	
  for	
  the	
  text	
  within	
  a	
  div	
  with	
  the	
  
   classes	
  “flash”	
  and	
  “noIce”.
Selectors	
  
•  But	
  this	
  doesn’t	
  look	
  very	
  nice,	
  and	
  it	
  is	
  briKle.	
  
•  So,	
  we	
  can	
  introduce	
  a	
  selectors.rb	
  file,	
  similar	
  to	
  
   paths.rb,	
  to	
  provide	
  natural	
  language	
  shortcuts:	
  
	 	when /the flash (notice|error|info)/

  		 ".flash.#{$1} "	
•  Now	
  we	
  can	
  say:	
  
	 	Then I should see "Ad was successfully created"
  	within the flash notice	
  
•  See	
  this	
  site	
  for	
  how	
  to	
  set	
  this	
  up:	
  
	
   http://bjeanes.com/2010/09/19/selector-free-cucumber-
   scenarios
Running	
  the	
  tests	
  
 •  Once	
  you	
  have	
  wriKen	
  your	
  features,	
  simply	
  
    run:	
  
	   	   bundle exec cucumber	

	•  	 	to	
  run	
  a	
  single	
  feature,	
  use	
  tags:	
  
    Or,	
  
	   	   bundle exec cucumber –t tagname	

 •  You	
  should	
  see	
  loads	
  of	
  red	
  –	
  now	
  write	
  your	
  
    code	
  and	
  make	
  it	
  green!	
  

Weitere ähnliche Inhalte

Was ist angesagt?

Cucumber Ru09 Web
Cucumber Ru09 WebCucumber Ru09 Web
Cucumber Ru09 WebJoseph Wilk
 
Testing web APIs
Testing web APIsTesting web APIs
Testing web APIsFDConf
 
BOOM Performance
BOOM PerformanceBOOM Performance
BOOM Performancedapulse
 
Angular Directives from Scratch
Angular Directives from ScratchAngular Directives from Scratch
Angular Directives from ScratchChristian Lilley
 
You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011andrewnacin
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tipsJack Franklin
 
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...andrewnacin
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fabio Akita
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheetschriseppstein
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyLindsay Holmwood
 
Front End Development - Beyond Javascript (Robin Cannon)
Front End Development - Beyond Javascript (Robin Cannon)Front End Development - Beyond Javascript (Robin Cannon)
Front End Development - Beyond Javascript (Robin Cannon)Future Insights
 

Was ist angesagt? (20)

Rails vu d'un Javaiste
Rails vu d'un JavaisteRails vu d'un Javaiste
Rails vu d'un Javaiste
 
Cucumber Ru09 Web
Cucumber Ru09 WebCucumber Ru09 Web
Cucumber Ru09 Web
 
Using java beans(ii)
Using java beans(ii)Using java beans(ii)
Using java beans(ii)
 
Testing web APIs
Testing web APIsTesting web APIs
Testing web APIs
 
BOOM Performance
BOOM PerformanceBOOM Performance
BOOM Performance
 
Angular Directives from Scratch
Angular Directives from ScratchAngular Directives from Scratch
Angular Directives from Scratch
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Dev In Rio 2009
Dev In Rio 2009Dev In Rio 2009
Dev In Rio 2009
 
You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011
 
Enecomp 2009
Enecomp 2009Enecomp 2009
Enecomp 2009
 
jQuery quick tips
jQuery quick tipsjQuery quick tips
jQuery quick tips
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tips
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
 
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheets
 
Your own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with RubyYour own (little) gem: building an online business with Ruby
Your own (little) gem: building an online business with Ruby
 
Front End Development - Beyond Javascript (Robin Cannon)
Front End Development - Beyond Javascript (Robin Cannon)Front End Development - Beyond Javascript (Robin Cannon)
Front End Development - Beyond Javascript (Robin Cannon)
 

Ähnlich wie Cucumber

Does my DIV look big in this?
Does my DIV look big in this?Does my DIV look big in this?
Does my DIV look big in this?glen_a_smith
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumberBachue Zhou
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsIgnacio Martín
 
Web development basics (Part-3)
Web development basics (Part-3)Web development basics (Part-3)
Web development basics (Part-3)Rajat Pratap Singh
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on RailsAvi Kedar
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010singingfish
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAmir Barylko
 
MonoRails - GoGaRuCo 2012
MonoRails - GoGaRuCo 2012MonoRails - GoGaRuCo 2012
MonoRails - GoGaRuCo 2012jackdanger
 
The Enterprise Architecture you always wanted: A Billion Transactions Per Mon...
The Enterprise Architecture you always wanted: A Billion Transactions Per Mon...The Enterprise Architecture you always wanted: A Billion Transactions Per Mon...
The Enterprise Architecture you always wanted: A Billion Transactions Per Mon...Thoughtworks
 
URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5jakemallory
 
Merb Slices
Merb SlicesMerb Slices
Merb Sliceshassox
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
Surviving javascript.pptx
Surviving javascript.pptxSurviving javascript.pptx
Surviving javascript.pptxTamas Rev
 

Ähnlich wie Cucumber (20)

Does my DIV look big in this?
Does my DIV look big in this?Does my DIV look big in this?
Does my DIV look big in this?
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumber
 
File Upload 2015
File Upload 2015File Upload 2015
File Upload 2015
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worlds
 
Web development basics (Part-3)
Web development basics (Part-3)Web development basics (Part-3)
Web development basics (Part-3)
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 
Download It
Download ItDownload It
Download It
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Juggling
JugglingJuggling
Juggling
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
 
MonoRails - GoGaRuCo 2012
MonoRails - GoGaRuCo 2012MonoRails - GoGaRuCo 2012
MonoRails - GoGaRuCo 2012
 
The Enterprise Architecture you always wanted: A Billion Transactions Per Mon...
The Enterprise Architecture you always wanted: A Billion Transactions Per Mon...The Enterprise Architecture you always wanted: A Billion Transactions Per Mon...
The Enterprise Architecture you always wanted: A Billion Transactions Per Mon...
 
URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5URUG Ruby on Rails Workshop - Sesssion 5
URUG Ruby on Rails Workshop - Sesssion 5
 
Merb Slices
Merb SlicesMerb Slices
Merb Slices
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Surviving javascript.pptx
Surviving javascript.pptxSurviving javascript.pptx
Surviving javascript.pptx
 

Kürzlich hochgeladen

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Kürzlich hochgeladen (20)

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

Cucumber

  • 1. Cucumber   Use  it,  bitches  
  • 2. Here’s  how  to  get  started   (it’s  surprisingly  easy)   •  I’m  assuming  you’ve  got  Rails  3/RVM/all  that   jazz  working.   •  If  you  don’t,  I  can’t  help  you…      …and,  someIme  when  you  least  expect  it,  MaK  will  hurt  you.  
  • 3. Here’s  how  to  get  started   (it’s  surprisingly  easy)   •  Add  to  Gemfile:   group :test do gem 'capybara'     gem 'database_cleaner' gem 'cucumber-rails' gem 'cucumber' gem 'rspec-rails' gem 'spork' gem 'launchy' gem 'machinist', '>= 2.0.0.beta2' gem 'faker' end •  Bundle  install      
  • 4. Here’s  how  to  get  started   (it’s  surprisingly  easy)   •  Now,  to  set  up  your  rails  app.   bundle exec rails g cucumber:install --capybara bundle exec rails g machinist:install touch features/support/blueprints.rb •  Add  this  line  to  blueprints.rb:   require 'machinist/active_record’ •  Edit  this  line  in  env.rb  (in  features/support)   Cucumber::Rails::World.use_transactional_fixtures = false
  • 5. Why  we’re  using  Machinist   •  I  wanted  to  start  from  with  a  blank  slate,   installing  Cucumber  and  nothing  else.   •  However,  I  quickly  found  that  Machinist  makes   things  a  lot  easier.   •  Machinist  gives  you  blueprints,  greatly   simplifying  the  creaIon  of  mock  objects.   •  More  later…  
  • 6. WriIng  features   @classifieds Feature: Classified Ads In order to buy and sell things As a logged in user I want to be able to view, add and manage classified ads Background: Given I am logged into cas as "Peter" "Portal" with an username of "00700001" And I have created another user And I am on the classifieds index page Scenario: Should be able to see the ads Then I should see "Glamlife Marketplace" Scenario: Should be able to add an ad When I follow "Create a new ad" And I fill in "classified_title" with "Testing title" And I select "For Sale" from "classified_ad_type"
  • 7. Baby  steps   •  Each  of  those  lines,  aUer  the  feature  definiIon,  is   called  a  ‘step’.   •  There  are  a  bunch  of  simple  steps  that  Cucumber   knows  all  about,  but  someImes  you  will  want  to   do  something  more  complex  than  “click  this  link”.   •  A  good  example  is  logging  in  using  CAS:   Given I am logged into cas as "Peter" "Portal" with an username of "00700001"   •  How  does  cucumber  know  what  to  do  with  this?  
  • 8. Defining  steps   •  So  that  Cucumber  understands  our  steps,  we   have  to  define  them:   Given /^I am logged into cas as "(.*)" "(.*)" with an username of "(.*)"$/ do | firstname, surname, username | @user = User.make!( :username => username, :firstname => firstname, :surname => surname, :dob => "01/01/1990", :home_address1 => "1 Street Street", :home_email => "pedro@portal.po", :home_phone => "1234567890", :term_address1 => "5 Glam Street", :term_phone => "0987654321", :term_mobile => "5674839201", :user_status => "Student", :user_type => "UGStudent" ) CASClient::Frameworks::Rails::Filter.fake(username) visit("/cas_session?force_cas_user=#{@user.username}") end
  • 9. CAS  hates  green  salad  fruits   •  CAS  and  Cucumber  don’t  get  on  at  all  well.   •  Luckily  the  rubycas-­‐client  gem  developer  has   put  in  a  way  for  Cucumber  to  get  around  CAS   without  taking  a  beaIng.   CASClient::Frameworks::Rails::Filter.fake(username)   •  Adding  this  line  to  our  step  definiIon  lets   Cucumber  in  the  back  door.   •  Green  peppers,  however,  can  get  bent.  
  • 10. Blueprints  and  ‘make!’   •  Blueprints  allow  you  to  pre-­‐define  instances  of   your  models,  so  you  don’t  have  to  fill  in  all  the   details.   •  Using  make!  instead  of  create  uses  these   blueprints.     •  Let’s  have  a  look  at  a  blueprint.rb  file…  
  • 11. Blueprints  and  ‘make’   Chunk.blueprint do title { sentence } content { sentence } end Classified.blueprint do title { sentence } ad_type { ad_type } body { paragraphs } reason { sentence } image { File.new("#{Rails.root.to_s}/ features/support/upload-files/image.png") } moderated { 0 } completed { 0 } end
  • 12. Faking  data   •  The  variables  in  the  last  slide  are  set  up  to   create  random  data,  oUen  using  Faker.   sentence  =  Faker::Lorem.sentence   paragraphs  =  Faker::Lorem.paragraphs.join("nn")   ad_type  =  "For  Sale"   name  =  Faker::Name.name   first_name  =  Faker::Name.first_name   last_name  =  Faker::Name.last_name   username  =  rand(99999999).to_s  
  • 13. Paths   •  In  olden  Imes,  people  used  to  have  to  put  paths   to  pages  into  their  features.   •  This  is  ‘briKle’  because  if  a  path  changes,  your   test  will  break.  To  miIgate  this  problem,  paths   are  defined  in  paths.rb  in  features/support,  eg:         when /the homes?page/ '/' •  This  way,  you  only  have  to  update  one  file  when   something  changes.   •  The  same  can  be  done  with  selectors…  
  • 14. Selectors   •  Selectors  are  used  to  ‘select’  a  specific  instance  of   something  on  a  page.   •  For  example,  you  might  have  the  same  text   appear  in  more  than  one  place  and  want  to   restrict  it  to  checking  a  specific  div.   •  For  example:       Then I should see "Ad was successfully created" within ".flash.notice” •  This  checks  for  the  text  within  a  div  with  the   classes  “flash”  and  “noIce”.
  • 15. Selectors   •  But  this  doesn’t  look  very  nice,  and  it  is  briKle.   •  So,  we  can  introduce  a  selectors.rb  file,  similar  to   paths.rb,  to  provide  natural  language  shortcuts:   when /the flash (notice|error|info)/
 ".flash.#{$1} " •  Now  we  can  say:   Then I should see "Ad was successfully created" within the flash notice   •  See  this  site  for  how  to  set  this  up:     http://bjeanes.com/2010/09/19/selector-free-cucumber- scenarios
  • 16. Running  the  tests   •  Once  you  have  wriKen  your  features,  simply   run:   bundle exec cucumber •  to  run  a  single  feature,  use  tags:   Or,   bundle exec cucumber –t tagname •  You  should  see  loads  of  red  –  now  write  your   code  and  make  it  green!