SlideShare uma empresa Scribd logo
1 de 9
CURSO DE TESTING OSL
        12 – 16 DE ABRIL 2010




                           Shoulda


Alberto Perdomo

Web:       http://albertoperdomo.net
Email:     alberto.perdomo@aentos.es
Twitter:   @albertoperdomo             http://www.aentos.com
TEST::UNIT

→ los tests no tienen mucha expresividad



→ las posibilidades son limitadas



→ acabamos probando las mismas cosas una y otra vez
SHOULDA

→ librería que “amplía” Test::Unit


→ helpers para contexto y expresividad


→ macros


→ helpers
SHOULDA: CONTEXTO Y
               EXPRESIVIDAD
                     class UserTest < Test::Unit::TestCase
                       context "A User instance" do
                         setup do
                           @user = User.find(:first)
                         end

                         should "return its full name" do
                           assert_equal 'John Doe', @user.full_name
                         end

                         context "with a profile" do
                           setup do
                             @user.profile = Profile.find(:first)
                           end

                           should "return true when sent #has_profile?" do
                             assert @user.has_profile?
                           end
                         end
                       end
                     end


Produce los siguientes tests unitarios:

 "test: A User instance should return its full name."
 "test: A User instance with a profle should return true when sent #has_profle?."
SHOULDA: MACROS PARA
   ACTIVERECORD
  class PostTest < Test::Unit::TestCase
    fixtures :all

    should_belong_to :user
    should_have_many :tags, :through => :taggings

    should_validate_uniqueness_of :title
    should_validate_presence_of :body, :message => /wtf/
    should_validate_presence_of :title
    should_validate_numericality_of :user_id
  end

  class UserTest < Test::Unit::TestCase
    should_have_many :posts

    should_not_allow_values_for :email, "blah", "b lah"
    should_allow_values_for :email, "a@b.com", "asdf@asdf.com"
    should_ensure_length_in_range :email, 1..100
    should_ensure_value_in_range :age, 1..100
    should_not_allow_mass_assignment_of :password
  end
MACROS PARA ACTIVERECORD

 test "a transfer without a from_account should not be valid" do
   transfer = Transfer.new(:from_account => nil, :to_account => @account_b, :amount => 100)
   assert !transfer.valid?
 end




                         should_validate_presence_of :from_account
SHOULDA: MACROS PARA
   CONTROLADORES

  class PostsControllerTest < ActionController::TestCase
    context "on GET to :show for first record" do
      setup do
        get :show, :id => 1
      end

      should_assign_to :user
      should_respond_with :success
      should_render_template :show
      should_not_set_the_flash

      should "do something else really cool" do
        assert_equal 1, assigns(:user).id
      end
    end
  end
SHOULDA: ASSERTIONS



   assert_same_elements([:a, :b, :c], [:c, :a, :b])
   assert_contains(['a', '1'], /d/)
   assert_contains(['a', '1'], 'a')
¿PREGUNTAS?

Mais conteúdo relacionado

Mais procurados

Mule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutesMule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutesGennaro Spagnoli
 
Able to find out apps password in r12
Able to find out apps password in r12Able to find out apps password in r12
Able to find out apps password in r12Vasu Nec
 
Mule esb - How to convert from Json to Object in 5 minutes
Mule esb - How to convert from Json to Object in 5 minutesMule esb - How to convert from Json to Object in 5 minutes
Mule esb - How to convert from Json to Object in 5 minutesGennaro Spagnoli
 
Lecture6 display data by okello erick
Lecture6 display data by okello erickLecture6 display data by okello erick
Lecture6 display data by okello erickokelloerick
 
PowerShell Script to add multiple users to a group in AD
PowerShell Script to add multiple users to a group in ADPowerShell Script to add multiple users to a group in AD
PowerShell Script to add multiple users to a group in ADJoseph Daramola
 
Book integrated assignment
Book integrated assignmentBook integrated assignment
Book integrated assignmentAkash gupta
 
Php mysql connectivity
Php mysql connectivityPhp mysql connectivity
Php mysql connectivityabhikwb
 
Mapping and listing in mule
Mapping and listing in muleMapping and listing in mule
Mapping and listing in muleKhan625
 

Mais procurados (18)

Web2py
Web2pyWeb2py
Web2py
 
Mule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutesMule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutes
 
Able to find out apps password in r12
Able to find out apps password in r12Able to find out apps password in r12
Able to find out apps password in r12
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
 
Mule esb - How to convert from Json to Object in 5 minutes
Mule esb - How to convert from Json to Object in 5 minutesMule esb - How to convert from Json to Object in 5 minutes
Mule esb - How to convert from Json to Object in 5 minutes
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
JavaScript patterns
JavaScript patternsJavaScript patterns
JavaScript patterns
 
Migrating legacy data
Migrating legacy dataMigrating legacy data
Migrating legacy data
 
ActiveRecord
ActiveRecordActiveRecord
ActiveRecord
 
Muleesbobjecttojson
Muleesbobjecttojson Muleesbobjecttojson
Muleesbobjecttojson
 
Mule esb object_to_json
Mule esb object_to_jsonMule esb object_to_json
Mule esb object_to_json
 
Lecture6 display data by okello erick
Lecture6 display data by okello erickLecture6 display data by okello erick
Lecture6 display data by okello erick
 
Web 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHPWeb 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHP
 
PowerShell Script to add multiple users to a group in AD
PowerShell Script to add multiple users to a group in ADPowerShell Script to add multiple users to a group in AD
PowerShell Script to add multiple users to a group in AD
 
Book integrated assignment
Book integrated assignmentBook integrated assignment
Book integrated assignment
 
Php mysql connectivity
Php mysql connectivityPhp mysql connectivity
Php mysql connectivity
 
Examplecode
ExamplecodeExamplecode
Examplecode
 
Mapping and listing in mule
Mapping and listing in muleMapping and listing in mule
Mapping and listing in mule
 

Destaque

Curso TDD Ruby on Rails #04: Factorías de objetos
Curso TDD Ruby on Rails #04: Factorías de objetosCurso TDD Ruby on Rails #04: Factorías de objetos
Curso TDD Ruby on Rails #04: Factorías de objetosAlberto Perdomo
 
Logo edarco
Logo edarcoLogo edarco
Logo edarcoelchavin
 
Boost your productivity!: Productivity tips for rails developers - Lightning ...
Boost your productivity!: Productivity tips for rails developers - Lightning ...Boost your productivity!: Productivity tips for rails developers - Lightning ...
Boost your productivity!: Productivity tips for rails developers - Lightning ...Alberto Perdomo
 
Celine dion all by myself
Celine dion   all by myselfCeline dion   all by myself
Celine dion all by myselfelchavin
 
Reshet Nrn Audio1
Reshet Nrn Audio1Reshet Nrn Audio1
Reshet Nrn Audio1Kelias
 
Leveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4jLeveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4jAlberto Perdomo
 
Tutorial goear
Tutorial goearTutorial goear
Tutorial goearelchavin
 
Complaint free teachers
Complaint free teachersComplaint free teachers
Complaint free teachersEva Migdal
 
Svym Update Presentation
Svym Update PresentationSvym Update Presentation
Svym Update Presentationguestc97027
 
Primeros pasos con la base de datos de grafos Neo4j
Primeros pasos con la base de datos de grafos Neo4jPrimeros pasos con la base de datos de grafos Neo4j
Primeros pasos con la base de datos de grafos Neo4jAlberto Perdomo
 
Rails for Mobile Devices @ Conferencia Rails 2011
Rails for Mobile Devices @ Conferencia Rails 2011Rails for Mobile Devices @ Conferencia Rails 2011
Rails for Mobile Devices @ Conferencia Rails 2011Alberto Perdomo
 
Curso TDD Ruby on Rails #03: Tests unitarios
Curso TDD Ruby on Rails #03: Tests unitariosCurso TDD Ruby on Rails #03: Tests unitarios
Curso TDD Ruby on Rails #03: Tests unitariosAlberto Perdomo
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Alberto Perdomo
 
JOP Programs 2008-09
JOP Programs 2008-09JOP Programs 2008-09
JOP Programs 2008-09Kelias
 
Squire: A polyglot application combining Neo4j, MongoDB, Ruby and Scala @ FOS...
Squire: A polyglot application combining Neo4j, MongoDB, Ruby and Scala @ FOS...Squire: A polyglot application combining Neo4j, MongoDB, Ruby and Scala @ FOS...
Squire: A polyglot application combining Neo4j, MongoDB, Ruby and Scala @ FOS...Alberto Perdomo
 

Destaque (16)

Curso TDD Ruby on Rails #04: Factorías de objetos
Curso TDD Ruby on Rails #04: Factorías de objetosCurso TDD Ruby on Rails #04: Factorías de objetos
Curso TDD Ruby on Rails #04: Factorías de objetos
 
Logo edarco
Logo edarcoLogo edarco
Logo edarco
 
Boost your productivity!: Productivity tips for rails developers - Lightning ...
Boost your productivity!: Productivity tips for rails developers - Lightning ...Boost your productivity!: Productivity tips for rails developers - Lightning ...
Boost your productivity!: Productivity tips for rails developers - Lightning ...
 
Celine dion all by myself
Celine dion   all by myselfCeline dion   all by myself
Celine dion all by myself
 
Reshet Nrn Audio1
Reshet Nrn Audio1Reshet Nrn Audio1
Reshet Nrn Audio1
 
Leveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4jLeveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4j
 
Tutorial goear
Tutorial goearTutorial goear
Tutorial goear
 
Complaint free teachers
Complaint free teachersComplaint free teachers
Complaint free teachers
 
Svym Update Presentation
Svym Update PresentationSvym Update Presentation
Svym Update Presentation
 
Primeros pasos con la base de datos de grafos Neo4j
Primeros pasos con la base de datos de grafos Neo4jPrimeros pasos con la base de datos de grafos Neo4j
Primeros pasos con la base de datos de grafos Neo4j
 
Pie Plano
Pie PlanoPie Plano
Pie Plano
 
Rails for Mobile Devices @ Conferencia Rails 2011
Rails for Mobile Devices @ Conferencia Rails 2011Rails for Mobile Devices @ Conferencia Rails 2011
Rails for Mobile Devices @ Conferencia Rails 2011
 
Curso TDD Ruby on Rails #03: Tests unitarios
Curso TDD Ruby on Rails #03: Tests unitariosCurso TDD Ruby on Rails #03: Tests unitarios
Curso TDD Ruby on Rails #03: Tests unitarios
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
JOP Programs 2008-09
JOP Programs 2008-09JOP Programs 2008-09
JOP Programs 2008-09
 
Squire: A polyglot application combining Neo4j, MongoDB, Ruby and Scala @ FOS...
Squire: A polyglot application combining Neo4j, MongoDB, Ruby and Scala @ FOS...Squire: A polyglot application combining Neo4j, MongoDB, Ruby and Scala @ FOS...
Squire: A polyglot application combining Neo4j, MongoDB, Ruby and Scala @ FOS...
 

Semelhante a Curso TDD Ruby on Rails #05: Shoulda

Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)Andre Foeken
 
Double Trouble
Double TroubleDouble Trouble
Double Troublegsterndale
 
Rails2 Pr
Rails2 PrRails2 Pr
Rails2 Prxibbar
 
Coffeescript a z
Coffeescript a zCoffeescript a z
Coffeescript a zStarbuildr
 
Антипаттерны модульного тестирования
Антипаттерны модульного тестированияАнтипаттерны модульного тестирования
Антипаттерны модульного тестированияMitinPavel
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperJon Kruger
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosEdgar Suarez
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Brian Hogan
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Metaprogramming 101
Metaprogramming 101Metaprogramming 101
Metaprogramming 101Nando Vieira
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everythingnoelrap
 
A Whirlwind Tour of Test::Class
A Whirlwind Tour of Test::ClassA Whirlwind Tour of Test::Class
A Whirlwind Tour of Test::ClassCurtis Poe
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012xSawyer
 

Semelhante a Curso TDD Ruby on Rails #05: Shoulda (20)

Spock
SpockSpock
Spock
 
Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)Rails workshop for Java people (September 2015)
Rails workshop for Java people (September 2015)
 
php part 2
php part 2php part 2
php part 2
 
Why Our Code Smells
Why Our Code SmellsWhy Our Code Smells
Why Our Code Smells
 
Double Trouble
Double TroubleDouble Trouble
Double Trouble
 
Ruby basic3
Ruby basic3Ruby basic3
Ruby basic3
 
Rails2 Pr
Rails2 PrRails2 Pr
Rails2 Pr
 
Python advance
Python advancePython advance
Python advance
 
Coffeescript a z
Coffeescript a zCoffeescript a z
Coffeescript a z
 
Антипаттерны модульного тестирования
Антипаттерны модульного тестированияАнтипаттерны модульного тестирования
Антипаттерны модульного тестирования
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Metaprogramming 101
Metaprogramming 101Metaprogramming 101
Metaprogramming 101
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
A Whirlwind Tour of Test::Class
A Whirlwind Tour of Test::ClassA Whirlwind Tour of Test::Class
A Whirlwind Tour of Test::Class
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
 

Mais de Alberto Perdomo

Curso TDD Ruby on Rails #08: Buenas prácticas
Curso TDD Ruby on Rails #08: Buenas prácticasCurso TDD Ruby on Rails #08: Buenas prácticas
Curso TDD Ruby on Rails #08: Buenas prácticasAlberto Perdomo
 
Curso TDD Ruby on Rails #02: Test Driven Development
Curso TDD  Ruby on Rails #02: Test Driven DevelopmentCurso TDD  Ruby on Rails #02: Test Driven Development
Curso TDD Ruby on Rails #02: Test Driven DevelopmentAlberto Perdomo
 
Curso TDD Ruby on Rails #06: Mocks y stubs
Curso TDD Ruby on Rails #06: Mocks y stubsCurso TDD Ruby on Rails #06: Mocks y stubs
Curso TDD Ruby on Rails #06: Mocks y stubsAlberto Perdomo
 
Curso TDD Ruby on Rails #02: Test Driven Development
Curso TDD Ruby on Rails #02: Test Driven DevelopmentCurso TDD Ruby on Rails #02: Test Driven Development
Curso TDD Ruby on Rails #02: Test Driven DevelopmentAlberto Perdomo
 
Curso TDD Ruby on Rails #01: Introducción al testing
Curso TDD Ruby on Rails #01: Introducción al testingCurso TDD Ruby on Rails #01: Introducción al testing
Curso TDD Ruby on Rails #01: Introducción al testingAlberto Perdomo
 
Plugins de autenticación en Rails - Lightning talk Las Palmas On Rails 09/02/...
Plugins de autenticación en Rails - Lightning talk Las Palmas On Rails 09/02/...Plugins de autenticación en Rails - Lightning talk Las Palmas On Rails 09/02/...
Plugins de autenticación en Rails - Lightning talk Las Palmas On Rails 09/02/...Alberto Perdomo
 

Mais de Alberto Perdomo (6)

Curso TDD Ruby on Rails #08: Buenas prácticas
Curso TDD Ruby on Rails #08: Buenas prácticasCurso TDD Ruby on Rails #08: Buenas prácticas
Curso TDD Ruby on Rails #08: Buenas prácticas
 
Curso TDD Ruby on Rails #02: Test Driven Development
Curso TDD  Ruby on Rails #02: Test Driven DevelopmentCurso TDD  Ruby on Rails #02: Test Driven Development
Curso TDD Ruby on Rails #02: Test Driven Development
 
Curso TDD Ruby on Rails #06: Mocks y stubs
Curso TDD Ruby on Rails #06: Mocks y stubsCurso TDD Ruby on Rails #06: Mocks y stubs
Curso TDD Ruby on Rails #06: Mocks y stubs
 
Curso TDD Ruby on Rails #02: Test Driven Development
Curso TDD Ruby on Rails #02: Test Driven DevelopmentCurso TDD Ruby on Rails #02: Test Driven Development
Curso TDD Ruby on Rails #02: Test Driven Development
 
Curso TDD Ruby on Rails #01: Introducción al testing
Curso TDD Ruby on Rails #01: Introducción al testingCurso TDD Ruby on Rails #01: Introducción al testing
Curso TDD Ruby on Rails #01: Introducción al testing
 
Plugins de autenticación en Rails - Lightning talk Las Palmas On Rails 09/02/...
Plugins de autenticación en Rails - Lightning talk Las Palmas On Rails 09/02/...Plugins de autenticación en Rails - Lightning talk Las Palmas On Rails 09/02/...
Plugins de autenticación en Rails - Lightning talk Las Palmas On Rails 09/02/...
 

Último

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Último (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
+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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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...
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Curso TDD Ruby on Rails #05: Shoulda

  • 1. CURSO DE TESTING OSL 12 – 16 DE ABRIL 2010 Shoulda Alberto Perdomo Web: http://albertoperdomo.net Email: alberto.perdomo@aentos.es Twitter: @albertoperdomo http://www.aentos.com
  • 2. TEST::UNIT → los tests no tienen mucha expresividad → las posibilidades son limitadas → acabamos probando las mismas cosas una y otra vez
  • 3. SHOULDA → librería que “amplía” Test::Unit → helpers para contexto y expresividad → macros → helpers
  • 4. SHOULDA: CONTEXTO Y EXPRESIVIDAD class UserTest < Test::Unit::TestCase context "A User instance" do setup do @user = User.find(:first) end should "return its full name" do assert_equal 'John Doe', @user.full_name end context "with a profile" do setup do @user.profile = Profile.find(:first) end should "return true when sent #has_profile?" do assert @user.has_profile? end end end end Produce los siguientes tests unitarios: "test: A User instance should return its full name." "test: A User instance with a profle should return true when sent #has_profle?."
  • 5. SHOULDA: MACROS PARA ACTIVERECORD class PostTest < Test::Unit::TestCase fixtures :all should_belong_to :user should_have_many :tags, :through => :taggings should_validate_uniqueness_of :title should_validate_presence_of :body, :message => /wtf/ should_validate_presence_of :title should_validate_numericality_of :user_id end class UserTest < Test::Unit::TestCase should_have_many :posts should_not_allow_values_for :email, "blah", "b lah" should_allow_values_for :email, "a@b.com", "asdf@asdf.com" should_ensure_length_in_range :email, 1..100 should_ensure_value_in_range :age, 1..100 should_not_allow_mass_assignment_of :password end
  • 6. MACROS PARA ACTIVERECORD test "a transfer without a from_account should not be valid" do transfer = Transfer.new(:from_account => nil, :to_account => @account_b, :amount => 100) assert !transfer.valid? end should_validate_presence_of :from_account
  • 7. SHOULDA: MACROS PARA CONTROLADORES class PostsControllerTest < ActionController::TestCase context "on GET to :show for first record" do setup do get :show, :id => 1 end should_assign_to :user should_respond_with :success should_render_template :show should_not_set_the_flash should "do something else really cool" do assert_equal 1, assigns(:user).id end end end
  • 8. SHOULDA: ASSERTIONS assert_same_elements([:a, :b, :c], [:c, :a, :b]) assert_contains(['a', '1'], /d/) assert_contains(['a', '1'], 'a')