SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
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?

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais 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
 

Mais 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
 

Último

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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...Neo4j
 
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 DevelopmentsTrustArc
 
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 2024Rafal Los
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 organizationRadu Cotescu
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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 Scriptwesley chun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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...Martijn de Jong
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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...
 
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
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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...
 

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?