Pro Yearly is on sale from $80 to $50! »

What's a Capybara - Brian Hughes

B044a0f039af800f4df09bf3b2465f18?s=47 Las Vegas Ruby Group
September 11, 2013
46

What's a Capybara - Brian Hughes

B044a0f039af800f4df09bf3b2465f18?s=128

Las Vegas Ruby Group

September 11, 2013
Tweet

Transcript

  1. Brian Hughes @brianvhughes What’s a Capybara?

  2. Largest of all living rodents. Master of the Grasses! What’s

    a Capybara?
  3. What is Capybara?

  4. Ruby Acceptance Test framework for Rack-based web applications What is

    Capybara?
  5. Ruby Acceptance Test framework for Rack-based web applications What is

    Capybara?
  6. What’s an Acceptance Test?

  7. What’s an Acceptance Test? Verify the functionality of your web

    app, from a user’s POV
  8. Did we really need another kind of test?

  9. Did we really need another kind of test?

  10. Did we really need another kind of test? “Unit” tests

    Model specs Model Layer
  11. Did we really need another kind of test? “Unit” tests

    Model specs Model Layer “Functional” tests Controller specs Controller Layer
  12. Did we really need another kind of test? “Unit” tests

    Model specs Model Layer “Functional” tests Controller specs Controller Layer View tests/specs View Layer
  13. Did we really need another kind of test? “Unit” tests

    Model specs Model Layer “Functional” tests Controller specs Controller Layer Route tests/specs Route Layer View tests/specs View Layer
  14. Did we really need another kind of test? “Unit” tests

    Model specs Model Layer “Functional” tests Controller specs Controller Layer Route tests/specs Route Layer View tests/specs View Layer
  15. Testing behavior from the developer’s PoV

  16. Users don’t think like developers.

  17. Users receive value from our apps.

  18. User Value in Web Apps? Lives in the Web Browser

    Delivered via HTML, CSS, JavaScript Rendered as pages, links, forms, buttons Derived through interactions with these elements.
  19. How do we verify that value is delivered? Hint: CMD-R

    in Safari/Chrome is not the answer.
  20. Acceptance Tests with Capybara

  21. Acceptance Tests with Capybara Provides methods to automate browser interactions

    Can drive both headless and GUI browsers Integrates with RSpec, TestUnit and Cucumber Lets us test drive our web apps “outside-in”
  22. How do we write Acceptance tests? What’s the role of

    the user? What feature do they want to access? How does the user verify success? What are the browser steps that perform the feature? What’s the starting state of our app?
  23. How do we write Acceptance tests? What’s the role of

    the user? What feature do they want to access? How does the user verify success? What are the browser steps that perform the feature? What’s the starting state of our app?
  24. User Stories

  25. User Stories Describe a single feature/function of the application The

    user’s PoV. State a goal and describe the feature needed for success. “As a <user_role>”, “In order to accomplish <goal>”, “I need to perform <new_feature>”. Defines the parameters for writing and verifying an Acceptance Test
  26. User Story Example Voting for a Topic As an LVRUG

    Member In order to indicate that I want to see “Topic A” presented I want to vote for “Topic A”, so it rises higher in the Most Votes list
  27. User Story Example Suggesting a Topic As an LVRUG Member

    In order to learn cool stuff I want to suggest a topic for members to vote on
  28. User Story Example Assigning Presenter Bonus Points As an LVRUG

    Organizer In order to encourage more 1st time topic volunteers When a 1st time volunteer presents a topic, they should receive 10 extra bonus points.
  29. Use the Story definition to help describe the Acceptance Test

  30. But what about Capybara?

  31. But what about Capybara? Drives a Browser to interact with

    your app Can visit URL paths and follow/click links Interacts with form fields and clicks buttons Can search HTML text via CSS and XPath Provides matchers to verify the presence of HTML elements and content
  32. But what about Capybara? Provides a headless Rack App HTML

    browser Also supports Selenium web driver, for JavaScript interactions Can integrate with capybara-webkit gem, to have headless HTML + JavaScript browsing. Will use Launchy gem to save HTML as a rendered page for browser viewing
  33. RSpec + Capybara Example Voting for a Topic As an

    LVRUG Member In order to indicate that I want to see “Topic A” presented I want to give my “vote” to Topic A, so that it has more votes than Topic B
  34. RSpec + Capybara Example

  35. RSpec + Capybara Example

  36. RSpec + Capybara Example Suggesting a Topic As an LVRUG

    Member In order to learn cool stuff I want to suggest a topic for members to vote on
  37. RSpec + Capybara Example

  38. RSpec + Capybara Example

  39. RSpec + Capybara Example

  40. Capybara Resources https:/ /github.com/jnicklas/capybara https:/ /github.com/thoughtbot/capybara- webkit https:/ /github.com/copiousfreetime/launchy https:/

    /github.com/jonleighton/poltergeist http:/ /www.elabs.se/blog/51-simple-tricks-to- clean-up-your-capybara-tests