Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Acceptance Testing with RSpec, Capybara & friends

Acceptance Testing with RSpec, Capybara & friends

Slides from my 2010 talk at Madrid Ruby Users Group (madrid-rb)

Sergio Gil

April 09, 2012
Tweet

More Decks by Sergio Gil

Other Decks in Programming

Transcript

  1. El stack de testing de aceptación definitivo de moda el

    primer trimestre de 2010 RSpec · Steak · Capybara · RackTest · Culerity · ... madrid-rb @madridrb Sergio Gil @porras
  2. TDD

  3. Porque empieza por el interfaz y tu interfaz es tu

    producto* *http://gettingreal.37signals.com/ch09_Interface_First.php
  4. Porque te ayuda a pensar realmente en la feature e

    implementar exclusivamente lo que hace falta
  5. Porque te ayuda a pensar realmente en la feature e

    implementar exclusivamente lo que hace falta (= aporta valor)
  6. Porque todo lo dicho sobre TDD y Agile es especialmente

    cierto con el testing de aceptación
  7. Porque el texto plano no aporta nada si quienes escribimos

    y leemos somos desarrolladores (sólo una capa más a cambio de nada)
  8. Porque el único producto del desarrollo del software susceptible de

    validación es el software (Manifiesto Ágil, minuto 1)
  9. Porque el mantenimiento, reutilización y refactorización de features y steps

    acaba siendo muy complejo y trabajoso (que era lo que queríamos evitar)
  10. feature "Main page" do background do create_user :login => "wadus"

    end scenario "should show existing books" do create_book :title => "The Pragmatic Programmer" login_as "wadus" visit "/" page.should have_css(".book", :text => "The Pragmatic Programmer") end end
  11. feature "Main page" do background do create_user :login => "wadus"

    end scenario "should show existing books" do create_book :title => "The Pragmatic Programmer" login_as "wadus" visit "/" page.should have_css(".book", :text => "The Pragmatic Programmer") end end
  12. feature "Main page" do background do create_user :login => "wadus"

    end scenario "should show existing books" do create_book :title => "The Pragmatic Programmer" login_as "wadus" visit "/" page.should have_css(".book", :text => "The Pragmatic Programmer") end end
  13. feature "Main page" do background do create_user :login => "wadus"

    end scenario "should show existing books" do create_book :title => "The Pragmatic Programmer" login_as "wadus" visit "/" page.should have_css(".book", :text => "The Pragmatic Programmer") end end
  14. feature "Main page" do background do create_user :login => "wadus"

    end scenario "should show existing books" do create_book :title => "The Pragmatic Programmer" login_as "wadus" visit "/" page.should have_css(".book", :text => "The Pragmatic Programmer") end end
  15. feature "Main page" do background do create_user :login => "wadus"

    end scenario "should show existing books" do create_book :title => "The Pragmatic Programmer" login_as "wadus" visit "/" page.should have_css(".book", :text => "The Pragmatic Programmer") end end
  16. feature "Main page" do background do create_user :login => "wadus"

    end scenario "should show existing books" do create_book :title => "The Pragmatic Programmer" login_as "wadus" visit "/" page.should have_css(".book", :text => "The Pragmatic Programmer") end end
  17. Ideal para testing de aceptación Alto nivel No se habla

    de modelos o métodos Ni tampoco de acciones o peticiones
  18. Ideal para testing de aceptación Alto nivel No se habla

    de modelos o métodos Ni tampoco de acciones o peticiones Sino de páginas, enlaces y formularios
  19. API de Capybara fill_in "Title", :with => "Wadus" choose "Option"

    check "Option" uncheck "Option" select "1980", :from => "Birth Year"
  20. API de Capybara fill_in "Title", :with => "Wadus" choose "Option"

    check "Option" uncheck "Option" select "1980", :from => "Birth Year" click_button "Save"
  21. API de Capybara fill_in "Title", :with => "Wadus" choose "Option"

    check "Option" uncheck "Option" select "1980", :from => "Birth Year" click_button "Save" click "Save"
  22. API de Capybara page.should have_content("Wadus") page.should have_no_content("Wadus") page.should have_css(".article", :text

    => "Wadus") page.should have_css(".article", :count => 3) page.should have_xpath("//*[@class='article']")
  23. API de Capybara page.should have_css(".article", :text => "Wadus") do |article|

    article.should have_css(".author", :text => "@porras") article.should have_css(".links") do |links| links.should have_css("a", :href => "http://wadus.info") links.should have_css("a", :href => "http://bit.ly/wadus") end end
  24. if Time.now < begins_at + 40.minutes && !me.thirsty? me.make :demo

    else me.show(the_code) && go_to(:bar) end
  25. if Time.now < begins_at + 40.minutes && !me.thirsty? me.make :demo

    else me.show(the_code) && go_to(:bar) end def the_code visit "http://github.com/porras/madrid-rb-feb-2010" end
  26. Delorean it "should show latest created user" do time_travel_to(3.minutes.ago) {

    create_user :name => "John" } time_travel_to(5.minutes.ago) { create_user :name => "Chris" } get '/' response.should have_text("John") response.should_not have_text("Chris") end
  27. ¿?

  28. http://cukes.info/ http://github.com/aslakhellesoy/cucumber http://github.com/cavalle/steak http://rspec.info/ http://wiki.github.com/dchelimsky/rspec/ http://github.com/dchelimsky/rspec http://github.com/jnicklas/capybara http://github.com/brynary/rack-test http://seleniumhq.org/ http://code.google.com/p/selenium/

    http://celerity.rubyforge.org/ http://htmlunit.sourceforge.net/ http://github.com/langalex/culerity http://github.com/bmabey/database_cleaner http://github.com/timcharper/spork http://github.com/bblimke/webmock http://github.com/bebanjo/delorean http://github.com/porras/rakegrowl