SlideShare una empresa de 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?

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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...
 

Similar 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
 

Similar 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
 

Más 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
 

Más 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

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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
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
 
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
 
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
 
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
 
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
 
🐬 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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

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...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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...
 
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
 
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
 
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
 
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...
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
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
 
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
 
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
 
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...
 
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...
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

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')