Rtt preso

1,071 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Rtt preso

  1. 1. Rails Test Prescriptions Chapter 2
  2. 2. What's a test?
  3. 3. What's a test? It “should do something” do #Logic end
  4. 4. What's a test? it { should validate_uniqueness_of(:username) }
  5. 5. What goes in a test?
  6. 6. What goes in a test? Set up your data
  7. 7. What goes in a test? Factories
  8. 8. What goes in a test? # In spec/factories/users.rb FactoryGirl.define do factory :user do sequence(:email) { |n| "user#{n}@generalthings.com" } sequence(:username) { |n| "user#{n}name" } first_name Faker::Name.first_name last_name Faker::Name.last_name phone_number Faker::PhoneNumber.phone_number title Faker::Name.prefix password "password" bio Faker::Lorem.sentences end end
  9. 9. What goes in a test? Perform the action
  10. 10. What goes in a test? Perform the assertion
  11. 11. What goes in a test? Tear Down
  12. 12. What goes in a test? Tear Down (Rarely needed)
  13. 13. Por ejemplo describe "user behavior" do let(:me) { User.new(name: "Noel", Password: “foobar”) } let(:you) { Factory(:user) } it "should let users be friends" do me.add_friend(you) you.should have(1).friend end end
  14. 14. What can you test in Rails? Models
  15. 15. What can you test in Rails? Controllers
  16. 16. What can you test in Rails? Views
  17. 17. What can you test in Rails? Views (but view tests are brittle)
  18. 18. How is Rspec different from Test::Unit “ Unit tests” usually test models spec/models/user_spec.rb
  19. 19. How is Rspec different from Test::Unit “ Functional tests” usually test controllers spec/controllers/users_controller_spec.rb
  20. 20. How is Rspec different from Test::Unit “ Integration tests” usually test multiple controllers
  21. 21. What Happens when Rails Tests Run?
  22. 22. What Happens when Rails Tests Run? Reset fixture data.
  23. 23. What Happens when Rails Tests Run? Run any defined “let” “ setup” or “before” blocks
  24. 24. What Happens when Rails Tests Run? Run the actual test method.
  25. 25. What Happens when Rails Tests Run? Run all teardown blocks
  26. 26. Running your tests $ bundle exec guard start
  27. 27. Running your tests $ begs

×