Rails Test Prescriptions Chapter 2
What's a test?
What's a test? It “should do something” do #Logic end
What's a test?   it { should validate_uniqueness_of(:username) }
What goes in a test?
What goes in a test? Set up your data
What goes in a test? Factories
What goes in a test? # In spec/factories/users.rb FactoryGirl.define do factory :user do sequence(:email)  { |n| "use...
What goes in a test? Perform the action
What goes in a test? Perform the assertion
What goes in a test? Tear Down
What goes in a test? Tear Down (Rarely needed)
Por ejemplo describe "user behavior" do let(:me) { User.new(name: "Noel", Password: “foobar”) } let(:y...
What can you test in Rails? Models
What can you test in Rails? Controllers
What can you test in Rails? Views
What can you test in Rails? Views (but view tests are brittle)
How is Rspec different from Test::Unit “ Unit tests” usually test models spec/models/user_spec.rb
How is Rspec different from Test::Unit “ Functional tests” usually  test controllers spec/controllers/users_controller_spe...
How is Rspec different from Test::Unit “ Integration tests” usually  test multiple controllers
What Happens when Rails Tests Run?
What Happens when Rails Tests Run? Reset fixture data.
What Happens when Rails Tests Run? Run any defined “let”  “ setup” or “before”  blocks
What Happens when Rails Tests Run? Run the actual test method.
What Happens when Rails Tests Run? Run all teardown blocks
Running your tests $ bundle exec guard start
Running your tests $ begs
Upcoming SlideShare
Loading in …5
×

Rtt preso

999 views
962 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
999
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

×