SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
Testing in Ruby
    Joseph Wilk
    http://www.joesniff.co.uk
Examples

• Look at testing tools available for Ruby
• Run some examples taken from
  git clone git://github.com/eshopworks/rboss-gem.git


• Get the code and try for yourself
What to test

• Objects
• System
• Complexity
• Tests!
What to test



Everything
 • Objects
 • System
 • Complexity
 • Tests!
Rspec
Quick Intro:
RSpec is a Behaviour Driven Development
framework for Ruby.
Two frameworks
   •   Story
   •   Specs
Writing and executing examples of how your
Ruby application should behave
                                          http://rspec.info/
Objects
Spec’s (Rspec)
• A Spec Framework for describing behaviour
  at the object level
  describe ‘context’
  it ‘should behave like this’

• Mock/Stub to help isolated the System
  Under Test

   • Flexmock, RR (Test double framework),
     Mocha
require File.dirname(__FILE__) + '/../spec_helper'

describe Boss::Api do

  def mock_http_response(stubs={})
    mock('http_response', {:body => '{quot;ysearchresponsequot;:{}}', :code =>
quot;200quot;}.merge(stubs))
  end

 before(:each) do
   @api = Boss::Api.new( appid = 'test' )
   @api.endpoint = 'http://www.example.com/'
 end

 describe quot;responding to spelling searchquot; do

   it quot;should make a spelling request to yahoo servicequot; do
     Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }

      @api.search_spelling(quot;girafesquot;)
    end

   it quot;should build the spelling objectsquot; do
     Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
     Boss::ResultFactory.should_receive(:build).with('{quot;ysearchresponsequot;:{}}')

      @api.search_spelling(quot;girafesquot;)
    end

  end
System
Cucumber
  Re-implementation of RSpec's story
  framework, based on Treetop by Aslak
  Hellesoy
• Features rather than stories
• FIT (functional integration tests) tables
• Internalisation support
• Better Error reporting
                             http://github.com/aslakhellesoy/cucumber/tree/master/
Feature: Web Search

In order to get search results
As a API user
I want to query yahoo boss

Scenario: Search web
  Given a valid API key
  When I do a 'web' search for 'monkeys'
  Then I will receive search results
  And I will be able to see the total hits

|   type     |   term     |
|   web      |   monkey   |
|   images   |   monkey   |
|   news     |   monkey   |
|   spell    |   girafe   |
Feature: Web Search

In order to get search results
As a API user
I want to query yahoo boss

Scenario: Search web
  Given a valid API key
  When I do a 'web' search for 'monkeys'
  Then I will receive search results
  And I will be able to see the total hits

|   type     |   term     |
|   web      |   monkey   |
|   images   |   monkey   |
|   news     |   monkey   |
|   spell    |   girafe   |
Feature
            Feature: Web Search
not story

            In order to get search results
            As a API user
            I want to query yahoo boss

            Scenario: Search web
              Given a valid API key
              When I do a 'web' search for 'monkeys'
              Then I will receive search results
              And I will be able to see the total hits

            |   type     |   term     |
            |   web      |   monkey   |
            |   images   |   monkey   |
            |   news     |   monkey   |
            |   spell    |   girafe   |
Feature
            Feature: Web Search
not story

            In order to get search results
            As a API user
            I want to query yahoo boss

            Scenario: Search web
              Given a valid API key
              When I do a 'web' search for 'monkeys'
              Then I will receive search results
              And I will be able to see the total hits

            |   type     |   term     |
            |   web      |   monkey   |
            |   images   |   monkey   |
            |   news     |   monkey   |
            |   spell    |   girafe   |
Feature
              Feature: Web Search
not story
 Value first   In order to get search results
              As a API user
              I want to query yahoo boss

              Scenario: Search web
                Given a valid API key
                When I do a 'web' search for 'monkeys'
                Then I will receive search results
                And I will be able to see the total hits

              |   type     |   term     |
              |   web      |   monkey   |
              |   images   |   monkey   |
              |   news     |   monkey   |
              |   spell    |   girafe   |
Feature
              Feature: Web Search
not story
 Value first   In order to get search results
              As a API user
              I want to query yahoo boss

              Scenario: Search web
                Given a valid API key
                When I do a 'web' search for 'monkeys'
                Then I will receive search results
                And I will be able to see the total hits

              |   type     |   term     |
              |   web      |   monkey   |
              |   images   |   monkey   |
              |   news     |   monkey   |
              |   spell    |   girafe   |
Feature
               Feature: Web Search
not story
 Value first    In order to get search results
               As a API user
               I want to query yahoo boss

               Scenario: Search web
                 Given a valid API key
                 When I do a 'web' search for 'monkeys'
                 Then I will receive search results
                 And I will be able to see the total hits

   FIT table   |   type     |   term     |
               |   web      |   monkey   |
               |   images   |   monkey   |
               |   news     |   monkey   |
               |   spell    |   girafe   |
Feature
               Feature: Web Search
not story
 Value first    In order to get search results
               As a API user
               I want to query yahoo boss

               Scenario: Search web
                 Given a valid API key
                 When I do a 'web' search for 'monkeys'
                 Then I will receive search results
                 And I will be able to see the total hits

   FIT table   |   type     |   term     |
               |   web      |   monkey   |
               |   images   |   monkey   |
               |   news     |   monkey   |
               |   spell    |   girafe   |
Feature
               Feature: Web Search
not story
 Value first    In order to get search results
               As a API user
               I want to query yahoo boss

               Scenario: Search web
                 Given a valid API key
                 When I do a 'web' search for 'monkeys'
                 Then I will receive search results
                 And I will be able to see the total hits

   FIT table   |   type     |   term     |
               |   web      |   monkey   |
               |   images   |   monkey   |
  FIT values   |   news     |   monkey   |
               |   spell    |   girafe   |
>rake features
Webrat
•   Ruby Acceptance Testing   •   Supports
    for Web applications
                                  •   Form interaction
•   Simulates the DOM
                                  •   Clicking links
•   Does this all in memory
                                  •   Post/Gets
    •   FAST!
                              •   No handling for
                                  Javascript

                              •   Gets confused with
                                  complex HTML
                                       http://github.com/brynary/webrat/tree/master
Testing :through =>
       “browser”
• Watir - http://wtr.rubyforge.org/
   • Ruby powered
• Selenium - http://selenium.rubyforge.org/
   • Java server (Selenium-rc)
 Slow compared to Webrat
 Supports Javascript and complex HTML
Complexity
Flog
Flog essentially scores a complexity metric
based on:
   • Assignments
   • Branches
   • Calls
Excessive usage of these can be an indicator of
too complex code.
Thing at the top of the list are worth taking a
closer look at.
                                         http://ruby.sadi.st/Flog.html
>flog lib
ResultFactory#build: (54.7)     main#none: (26.0)
  21.8: branch                    15.4: require
                                   4.4: dirname
  14.3: assignment
                                   3.2: branch
  12.7: new                        2.4: include?
  10.0: <<                         1.4: expand_path
   7.1: []                         1.2: unshift
   4.1: each                       1.1: assignment
                                   1.0: each
   4.0: has_key?
                                Config#to_url: (14.9)
   2.2: discover_search_type       7.2: assignment
   2.1: set_instance_variable      3.6: []
   2.0: raise                      2.6: inject
   2.0: include?                   1.7: to_s
                                   1.5: escape
   1.9: parse
                                   1.5: +
Api#search_boss: (39.7)            1.5: marshal_dump
  12.1: branch                     1.3: branch
  11.5: assignment                 0.5: lit_fixnum
   5.6: raise
   3.2: format
   3.0: format?
   2.8: new
   2.6: empty?
   1.7: build
   1.6: body
   1.6: join
   1.6: parse_error
   1.5: count
   1.5: build_request_url
   1.4: include?
   1.4: yield
   1.3: parse
   1.3: block_given?
   1.3: get_response
   1.3: >
   1.3: code
Testing tests
Rcov
    Examine which parts of your
    code are
    not covered by your tests.
•   Generates pretty HTML reports
•   Ensure test coverage before commits
    >rake verify_rcov
    > Coverage: 99.7% (threshold: 99.7%)
                                     http://eigenclass.org/hiki.rb?rcov
>rake spec
>cd coverage
>rake spec
Spec Profile (Rspec)
Profiling enabled.
.................P..............
Top 10 slowest examples:
0.0343130 Boss::Api failed search should extract error from xml on failed search
0.0083660 Boss::Api failed search should raise error on failed search
0.0053660 Boss::Api configuring search should allow configuring through block
0.0052650 Boss::Api searching terms should encode invalid characters
0.0045870 Boss::Api responding to spelling search should build the spelling objects
0.0044650 Boss::Api configuring search should allow configuring through hash
0.0044360 Boss::Api responding to web search should build the web objects
0.0044270 Boss::Api responding to image search should build the image objects
0.0044130 Boss::Api responding to news search should build the news objects
0.0042030 Boss::Api formats should not return any objects when format is 'json'
Heckle
   Hurt your tests
                               if becomes unless
1. Your tests should pass.
                               calls get replaced
2. Break your code.
                               numbers get changed,
3. Now they should fail.
                               assignments get changed
   Mutates the code.
                               and more...
   Be warned! Can lead to
   infinite loops and general
   craziness.
                                               http://ruby.sadi.st/Heckle.html
>spec spec/boss/
result_collection_spec.
rb --heckle
Boss::ResultCollection
**********************************************************************
*** Boss::ResultCollection#set_instance_variable loaded with 2 possible mutations
**********************************************************************

2 mutations remaining...
1 mutations remaining...

The following mutations didn't cause test failures:

Binary files original and mutation differ

--- original
+++ mutation
 def set_instance_variable(name, value)
   instance_variable_set(quot;@#{name}quot;, value)
- instance_eval(quot;def #{name}n @#{name}n endquot;)
+ instance_eval(quot;def #{name}n @#{name}hzquot;)
 end

**********************************************************************
*** Boss::ResultCollection#<< loaded with 1 possible mutations
**********************************************************************

1 mutations remaining...
The following mutations didn't cause test failures:

--- original
+++ mutation
 def <<(element)
- (@results << element)
+ # do nothing
 end
Future

• Johnson wraps JavaScript in a loving Ruby
  embrace.   http://github.com/jbarnette/johnson/

  Webrat + Johnson?
• Cucumber merging with Rspec?
• Framework for testing CSS?
Questions?

Contenu connexe

Tendances

RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜崇之 清水
 
Mashups & APIs
Mashups & APIsMashups & APIs
Mashups & APIsPamela Fox
 
SearchLove Boston 2016 | Mike King | Developer Thinking for SEOs
SearchLove Boston 2016 | Mike King | Developer Thinking for SEOsSearchLove Boston 2016 | Mike King | Developer Thinking for SEOs
SearchLove Boston 2016 | Mike King | Developer Thinking for SEOsDistilled
 
Artificial Intelligence for Developers - OOP Munich
Artificial Intelligence for Developers - OOP MunichArtificial Intelligence for Developers - OOP Munich
Artificial Intelligence for Developers - OOP MunichBoaz Ziniman
 
Moving Forward with AI
Moving Forward with AIMoving Forward with AI
Moving Forward with AIAdrian Hornsby
 
Building Successful APIs Overnight - Orlando K - Codemotion Rome 2015
Building Successful APIs Overnight - Orlando K - Codemotion Rome 2015Building Successful APIs Overnight - Orlando K - Codemotion Rome 2015
Building Successful APIs Overnight - Orlando K - Codemotion Rome 2015Codemotion
 
AWS Machine Learning Week SF: Build an Image-Based Automatic Alert System wit...
AWS Machine Learning Week SF: Build an Image-Based Automatic Alert System wit...AWS Machine Learning Week SF: Build an Image-Based Automatic Alert System wit...
AWS Machine Learning Week SF: Build an Image-Based Automatic Alert System wit...Amazon Web Services
 
Testing web APIs
Testing web APIsTesting web APIs
Testing web APIsFDConf
 

Tendances (8)

RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
 
Mashups & APIs
Mashups & APIsMashups & APIs
Mashups & APIs
 
SearchLove Boston 2016 | Mike King | Developer Thinking for SEOs
SearchLove Boston 2016 | Mike King | Developer Thinking for SEOsSearchLove Boston 2016 | Mike King | Developer Thinking for SEOs
SearchLove Boston 2016 | Mike King | Developer Thinking for SEOs
 
Artificial Intelligence for Developers - OOP Munich
Artificial Intelligence for Developers - OOP MunichArtificial Intelligence for Developers - OOP Munich
Artificial Intelligence for Developers - OOP Munich
 
Moving Forward with AI
Moving Forward with AIMoving Forward with AI
Moving Forward with AI
 
Building Successful APIs Overnight - Orlando K - Codemotion Rome 2015
Building Successful APIs Overnight - Orlando K - Codemotion Rome 2015Building Successful APIs Overnight - Orlando K - Codemotion Rome 2015
Building Successful APIs Overnight - Orlando K - Codemotion Rome 2015
 
AWS Machine Learning Week SF: Build an Image-Based Automatic Alert System wit...
AWS Machine Learning Week SF: Build an Image-Based Automatic Alert System wit...AWS Machine Learning Week SF: Build an Image-Based Automatic Alert System wit...
AWS Machine Learning Week SF: Build an Image-Based Automatic Alert System wit...
 
Testing web APIs
Testing web APIsTesting web APIs
Testing web APIs
 

En vedette

Rubyconf lightning talk
Rubyconf lightning talkRubyconf lightning talk
Rubyconf lightning talkJoseph Wilk
 
Acceptance testing in the land of the startup
Acceptance testing in the land of the startupAcceptance testing in the land of the startup
Acceptance testing in the land of the startupJoseph Wilk
 
Testing outside of the Ruby World
Testing outside of the Ruby WorldTesting outside of the Ruby World
Testing outside of the Ruby WorldJoseph Wilk
 

En vedette (6)

Spa2011
Spa2011Spa2011
Spa2011
 
Musichackday
MusichackdayMusichackday
Musichackday
 
Rubyconf lightning talk
Rubyconf lightning talkRubyconf lightning talk
Rubyconf lightning talk
 
Acceptance testing in the land of the startup
Acceptance testing in the land of the startupAcceptance testing in the land of the startup
Acceptance testing in the land of the startup
 
Glädjestrategin som förändrade liv
Glädjestrategin som förändrade livGlädjestrategin som förändrade liv
Glädjestrategin som förändrade liv
 
Testing outside of the Ruby World
Testing outside of the Ruby WorldTesting outside of the Ruby World
Testing outside of the Ruby World
 

Similaire à Testing with Ruby

Behaviour driven infrastructure
Behaviour driven infrastructureBehaviour driven infrastructure
Behaviour driven infrastructureLindsay Holmwood
 
Building robust REST APIs
Building robust REST APIsBuilding robust REST APIs
Building robust REST APIsNejc Zupan
 
Green Light for the Apps with Calaba.sh - DroidCon Paris 2014
Green Light for the Apps with Calaba.sh - DroidCon Paris 2014Green Light for the Apps with Calaba.sh - DroidCon Paris 2014
Green Light for the Apps with Calaba.sh - DroidCon Paris 2014Jean-Loup Yu
 
State of Developer Tools (WDS09)
State of Developer Tools (WDS09)State of Developer Tools (WDS09)
State of Developer Tools (WDS09)bgalbs
 
Acceptance Testing of Web UI
Acceptance Testing of Web UIAcceptance Testing of Web UI
Acceptance Testing of Web UIVladimir Tsukur
 
Single Page Application Development with backbone.js and Simple.Web
Single Page Application Development with backbone.js and Simple.WebSingle Page Application Development with backbone.js and Simple.Web
Single Page Application Development with backbone.js and Simple.WebChris Canal
 
Riding the Edge with Ember.js
Riding the Edge with Ember.jsRiding the Edge with Ember.js
Riding the Edge with Ember.jsaortbals
 
Finding things on the web with BOSS
Finding things on the web with BOSSFinding things on the web with BOSS
Finding things on the web with BOSSChristian Heilmann
 
Your fist RubyMotion Application
Your fist RubyMotion ApplicationYour fist RubyMotion Application
Your fist RubyMotion Applicationtoamitkumar
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Confneal_kemp
 
APIs for modern web apps
APIs for modern web appsAPIs for modern web apps
APIs for modern web appsChris Mills
 
Selenium to Appium - how hard can it be (SauceCon).
Selenium to Appium - how hard can it be (SauceCon).Selenium to Appium - how hard can it be (SauceCon).
Selenium to Appium - how hard can it be (SauceCon).snevesbarros
 
ADF Mobile: 10 Things you don't get from the developers guide
ADF Mobile: 10 Things you don't get from the developers guideADF Mobile: 10 Things you don't get from the developers guide
ADF Mobile: 10 Things you don't get from the developers guideLuc Bors
 
Stackup New Languages Talk: Ember is for Everybody
Stackup New Languages Talk: Ember is for EverybodyStackup New Languages Talk: Ember is for Everybody
Stackup New Languages Talk: Ember is for EverybodyCory Forsyth
 

Similaire à Testing with Ruby (20)

Behaviour driven infrastructure
Behaviour driven infrastructureBehaviour driven infrastructure
Behaviour driven infrastructure
 
Building robust REST APIs
Building robust REST APIsBuilding robust REST APIs
Building robust REST APIs
 
Swift meetup22june2015
Swift meetup22june2015Swift meetup22june2015
Swift meetup22june2015
 
Green Light for the Apps with Calaba.sh - DroidCon Paris 2014
Green Light for the Apps with Calaba.sh - DroidCon Paris 2014Green Light for the Apps with Calaba.sh - DroidCon Paris 2014
Green Light for the Apps with Calaba.sh - DroidCon Paris 2014
 
State of Developer Tools (WDS09)
State of Developer Tools (WDS09)State of Developer Tools (WDS09)
State of Developer Tools (WDS09)
 
Practical Semantic Web
Practical Semantic WebPractical Semantic Web
Practical Semantic Web
 
Acceptance Testing of Web UI
Acceptance Testing of Web UIAcceptance Testing of Web UI
Acceptance Testing of Web UI
 
API_tutorial.ppt
API_tutorial.pptAPI_tutorial.ppt
API_tutorial.ppt
 
Single Page Application Development with backbone.js and Simple.Web
Single Page Application Development with backbone.js and Simple.WebSingle Page Application Development with backbone.js and Simple.Web
Single Page Application Development with backbone.js and Simple.Web
 
Riding the Edge with Ember.js
Riding the Edge with Ember.jsRiding the Edge with Ember.js
Riding the Edge with Ember.js
 
Finding things on the web with BOSS
Finding things on the web with BOSSFinding things on the web with BOSS
Finding things on the web with BOSS
 
Your fist RubyMotion Application
Your fist RubyMotion ApplicationYour fist RubyMotion Application
Your fist RubyMotion Application
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Conf
 
Cucumber
CucumberCucumber
Cucumber
 
APIs for modern web apps
APIs for modern web appsAPIs for modern web apps
APIs for modern web apps
 
Front-End UnitTesting
Front-End UnitTestingFront-End UnitTesting
Front-End UnitTesting
 
Selenium to Appium - how hard can it be (SauceCon).
Selenium to Appium - how hard can it be (SauceCon).Selenium to Appium - how hard can it be (SauceCon).
Selenium to Appium - how hard can it be (SauceCon).
 
ADF Mobile: 10 Things you don't get from the developers guide - Luc Bors
ADF Mobile: 10 Things you don't get from the developers guide - Luc BorsADF Mobile: 10 Things you don't get from the developers guide - Luc Bors
ADF Mobile: 10 Things you don't get from the developers guide - Luc Bors
 
ADF Mobile: 10 Things you don't get from the developers guide
ADF Mobile: 10 Things you don't get from the developers guideADF Mobile: 10 Things you don't get from the developers guide
ADF Mobile: 10 Things you don't get from the developers guide
 
Stackup New Languages Talk: Ember is for Everybody
Stackup New Languages Talk: Ember is for EverybodyStackup New Languages Talk: Ember is for Everybody
Stackup New Languages Talk: Ember is for Everybody
 

Plus de Joseph Wilk

Acceptance testing in the land of the startup
Acceptance testing in the land of the startup Acceptance testing in the land of the startup
Acceptance testing in the land of the startup Joseph Wilk
 
Rubykaigi 2011 Limited Red talk
Rubykaigi 2011 Limited Red talkRubykaigi 2011 Limited Red talk
Rubykaigi 2011 Limited Red talkJoseph Wilk
 
The Limited Red Society
The Limited Red SocietyThe Limited Red Society
The Limited Red SocietyJoseph Wilk
 
The Limited Red Society
The Limited Red Society The Limited Red Society
The Limited Red Society Joseph Wilk
 
Cucumber Patterns Workshop
Cucumber Patterns WorkshopCucumber Patterns Workshop
Cucumber Patterns WorkshopJoseph Wilk
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled CucumbersJoseph Wilk
 
Cucumber Ru09 Web
Cucumber Ru09 WebCucumber Ru09 Web
Cucumber Ru09 WebJoseph Wilk
 
Dynamic Workflow Pulling the Strings
Dynamic Workflow Pulling the StringsDynamic Workflow Pulling the Strings
Dynamic Workflow Pulling the StringsJoseph Wilk
 
Outside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecOutside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecJoseph Wilk
 

Plus de Joseph Wilk (11)

Frozenrails2011
Frozenrails2011Frozenrails2011
Frozenrails2011
 
Acceptance testing in the land of the startup
Acceptance testing in the land of the startup Acceptance testing in the land of the startup
Acceptance testing in the land of the startup
 
Rubykaigi 2011 Limited Red talk
Rubykaigi 2011 Limited Red talkRubykaigi 2011 Limited Red talk
Rubykaigi 2011 Limited Red talk
 
The Limited Red Society
The Limited Red SocietyThe Limited Red Society
The Limited Red Society
 
The Limited Red Society
The Limited Red Society The Limited Red Society
The Limited Red Society
 
Cucumber Patterns Workshop
Cucumber Patterns WorkshopCucumber Patterns Workshop
Cucumber Patterns Workshop
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled Cucumbers
 
Cucumber Ru09 Web
Cucumber Ru09 WebCucumber Ru09 Web
Cucumber Ru09 Web
 
Cucumbered
CucumberedCucumbered
Cucumbered
 
Dynamic Workflow Pulling the Strings
Dynamic Workflow Pulling the StringsDynamic Workflow Pulling the Strings
Dynamic Workflow Pulling the Strings
 
Outside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecOutside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and Rspec
 

Dernier

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
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 educationjfdjdjcjdnsjd
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
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.pdfsudhanshuwaghmare1
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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 WorkerThousandEyes
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 

Dernier (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
+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...
 

Testing with Ruby

  • 1. Testing in Ruby Joseph Wilk http://www.joesniff.co.uk
  • 2. Examples • Look at testing tools available for Ruby • Run some examples taken from git clone git://github.com/eshopworks/rboss-gem.git • Get the code and try for yourself
  • 3. What to test • Objects • System • Complexity • Tests!
  • 4. What to test Everything • Objects • System • Complexity • Tests!
  • 5. Rspec Quick Intro: RSpec is a Behaviour Driven Development framework for Ruby. Two frameworks • Story • Specs Writing and executing examples of how your Ruby application should behave http://rspec.info/
  • 7. Spec’s (Rspec) • A Spec Framework for describing behaviour at the object level describe ‘context’ it ‘should behave like this’ • Mock/Stub to help isolated the System Under Test • Flexmock, RR (Test double framework), Mocha
  • 8. require File.dirname(__FILE__) + '/../spec_helper' describe Boss::Api do def mock_http_response(stubs={}) mock('http_response', {:body => '{quot;ysearchresponsequot;:{}}', :code => quot;200quot;}.merge(stubs)) end before(:each) do @api = Boss::Api.new( appid = 'test' ) @api.endpoint = 'http://www.example.com/' end describe quot;responding to spelling searchquot; do it quot;should make a spelling request to yahoo servicequot; do Net::HTTP.should_receive(:get_response).and_return{ mock_http_response } @api.search_spelling(quot;girafesquot;) end it quot;should build the spelling objectsquot; do Net::HTTP.stub!(:get_response).and_return{ mock_http_response } Boss::ResultFactory.should_receive(:build).with('{quot;ysearchresponsequot;:{}}') @api.search_spelling(quot;girafesquot;) end end
  • 10. Cucumber Re-implementation of RSpec's story framework, based on Treetop by Aslak Hellesoy • Features rather than stories • FIT (functional integration tests) tables • Internalisation support • Better Error reporting http://github.com/aslakhellesoy/cucumber/tree/master/
  • 11. Feature: Web Search In order to get search results As a API user I want to query yahoo boss Scenario: Search web Given a valid API key When I do a 'web' search for 'monkeys' Then I will receive search results And I will be able to see the total hits | type | term | | web | monkey | | images | monkey | | news | monkey | | spell | girafe |
  • 12. Feature: Web Search In order to get search results As a API user I want to query yahoo boss Scenario: Search web Given a valid API key When I do a 'web' search for 'monkeys' Then I will receive search results And I will be able to see the total hits | type | term | | web | monkey | | images | monkey | | news | monkey | | spell | girafe |
  • 13. Feature Feature: Web Search not story In order to get search results As a API user I want to query yahoo boss Scenario: Search web Given a valid API key When I do a 'web' search for 'monkeys' Then I will receive search results And I will be able to see the total hits | type | term | | web | monkey | | images | monkey | | news | monkey | | spell | girafe |
  • 14. Feature Feature: Web Search not story In order to get search results As a API user I want to query yahoo boss Scenario: Search web Given a valid API key When I do a 'web' search for 'monkeys' Then I will receive search results And I will be able to see the total hits | type | term | | web | monkey | | images | monkey | | news | monkey | | spell | girafe |
  • 15. Feature Feature: Web Search not story Value first In order to get search results As a API user I want to query yahoo boss Scenario: Search web Given a valid API key When I do a 'web' search for 'monkeys' Then I will receive search results And I will be able to see the total hits | type | term | | web | monkey | | images | monkey | | news | monkey | | spell | girafe |
  • 16. Feature Feature: Web Search not story Value first In order to get search results As a API user I want to query yahoo boss Scenario: Search web Given a valid API key When I do a 'web' search for 'monkeys' Then I will receive search results And I will be able to see the total hits | type | term | | web | monkey | | images | monkey | | news | monkey | | spell | girafe |
  • 17. Feature Feature: Web Search not story Value first In order to get search results As a API user I want to query yahoo boss Scenario: Search web Given a valid API key When I do a 'web' search for 'monkeys' Then I will receive search results And I will be able to see the total hits FIT table | type | term | | web | monkey | | images | monkey | | news | monkey | | spell | girafe |
  • 18. Feature Feature: Web Search not story Value first In order to get search results As a API user I want to query yahoo boss Scenario: Search web Given a valid API key When I do a 'web' search for 'monkeys' Then I will receive search results And I will be able to see the total hits FIT table | type | term | | web | monkey | | images | monkey | | news | monkey | | spell | girafe |
  • 19. Feature Feature: Web Search not story Value first In order to get search results As a API user I want to query yahoo boss Scenario: Search web Given a valid API key When I do a 'web' search for 'monkeys' Then I will receive search results And I will be able to see the total hits FIT table | type | term | | web | monkey | | images | monkey | FIT values | news | monkey | | spell | girafe |
  • 21.
  • 22. Webrat • Ruby Acceptance Testing • Supports for Web applications • Form interaction • Simulates the DOM • Clicking links • Does this all in memory • Post/Gets • FAST! • No handling for Javascript • Gets confused with complex HTML http://github.com/brynary/webrat/tree/master
  • 23. Testing :through => “browser” • Watir - http://wtr.rubyforge.org/ • Ruby powered • Selenium - http://selenium.rubyforge.org/ • Java server (Selenium-rc) Slow compared to Webrat Supports Javascript and complex HTML
  • 25. Flog Flog essentially scores a complexity metric based on: • Assignments • Branches • Calls Excessive usage of these can be an indicator of too complex code. Thing at the top of the list are worth taking a closer look at. http://ruby.sadi.st/Flog.html
  • 27. ResultFactory#build: (54.7) main#none: (26.0) 21.8: branch 15.4: require 4.4: dirname 14.3: assignment 3.2: branch 12.7: new 2.4: include? 10.0: << 1.4: expand_path 7.1: [] 1.2: unshift 4.1: each 1.1: assignment 1.0: each 4.0: has_key? Config#to_url: (14.9) 2.2: discover_search_type 7.2: assignment 2.1: set_instance_variable 3.6: [] 2.0: raise 2.6: inject 2.0: include? 1.7: to_s 1.5: escape 1.9: parse 1.5: + Api#search_boss: (39.7) 1.5: marshal_dump 12.1: branch 1.3: branch 11.5: assignment 0.5: lit_fixnum 5.6: raise 3.2: format 3.0: format? 2.8: new 2.6: empty? 1.7: build 1.6: body 1.6: join 1.6: parse_error 1.5: count 1.5: build_request_url 1.4: include? 1.4: yield 1.3: parse 1.3: block_given? 1.3: get_response 1.3: > 1.3: code
  • 29. Rcov Examine which parts of your code are not covered by your tests. • Generates pretty HTML reports • Ensure test coverage before commits >rake verify_rcov > Coverage: 99.7% (threshold: 99.7%) http://eigenclass.org/hiki.rb?rcov
  • 31.
  • 32.
  • 34. Spec Profile (Rspec) Profiling enabled. .................P.............. Top 10 slowest examples: 0.0343130 Boss::Api failed search should extract error from xml on failed search 0.0083660 Boss::Api failed search should raise error on failed search 0.0053660 Boss::Api configuring search should allow configuring through block 0.0052650 Boss::Api searching terms should encode invalid characters 0.0045870 Boss::Api responding to spelling search should build the spelling objects 0.0044650 Boss::Api configuring search should allow configuring through hash 0.0044360 Boss::Api responding to web search should build the web objects 0.0044270 Boss::Api responding to image search should build the image objects 0.0044130 Boss::Api responding to news search should build the news objects 0.0042030 Boss::Api formats should not return any objects when format is 'json'
  • 35. Heckle Hurt your tests if becomes unless 1. Your tests should pass. calls get replaced 2. Break your code. numbers get changed, 3. Now they should fail. assignments get changed Mutates the code. and more... Be warned! Can lead to infinite loops and general craziness. http://ruby.sadi.st/Heckle.html
  • 37. ********************************************************************** *** Boss::ResultCollection#set_instance_variable loaded with 2 possible mutations ********************************************************************** 2 mutations remaining... 1 mutations remaining... The following mutations didn't cause test failures: Binary files original and mutation differ --- original +++ mutation def set_instance_variable(name, value) instance_variable_set(quot;@#{name}quot;, value) - instance_eval(quot;def #{name}n @#{name}n endquot;) + instance_eval(quot;def #{name}n @#{name}hzquot;) end ********************************************************************** *** Boss::ResultCollection#<< loaded with 1 possible mutations ********************************************************************** 1 mutations remaining... The following mutations didn't cause test failures: --- original +++ mutation def <<(element) - (@results << element) + # do nothing end
  • 38. Future • Johnson wraps JavaScript in a loving Ruby embrace. http://github.com/jbarnette/johnson/ Webrat + Johnson? • Cucumber merging with Rspec? • Framework for testing CSS?