Testing Merb
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Testing Merb

on

  • 5,055 views

 

Statistics

Views

Total Views
5,055
Views on SlideShare
5,044
Embed Views
11

Actions

Likes
3
Downloads
70
Comments
0

2 Embeds 11

http://www.slideshare.net 9
https://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Testing Merb Presentation Transcript

  • 1. Testing Merb The Right Way
  • 2. Why Test?
  • 3. TDD
  • 4. TDD and Regressions
  • 5. TDD and Regressions I am not saying TDD is bad, but this talk doesn’t focus on mock- driven TDD.
  • 6. Resiliant Against Refactoring
  • 7. class Awesome def hello puts quot;~ Hello ~quot; end end describe Awesome do it quot;prints helloquot; do awesome = Awesome.new awesome.should_receive(:puts) awesome.hello end end
  • 8. class Awesome def hello awesome_print quot;~ Hello ~quot; end def awesome_print(str) print quot;#{str}nquot; end end describe Awesome do it quot;prints helloquot; do awesome = Awesome.new awesome.should_receive(:puts) awesome.hello end end
  • 9. class Awesome def hello awesome_print quot;~ Hello ~quot; end def awesome_print(str) print quot;#{str}nquot; end end describe Awesome do it quot;prints helloquot; do AIL awesome = Awesome.new F awesome.should_receive(:puts) awesome.hello end end
  • 10. class Awesome def hello awesome_print quot;~ Hello ~quot; end def awesome_print(str) print quot;#{str}nquot; end end describe Awesome do it quot;prints helloquot; do capture { Awesome.new.hello }. should =~ /Hello/ end end
  • 11. How to Test Three Rules
  • 12. Broken Interface means failing tests
  • 13. Working Interface means passing tests
  • 14. Write tests about what you care about
  • 15. http://example.com/foo Filters Controller Views Helpers What Happens in Your App
  • 16. http://example.com/foo Your App What You Care About
  • 17. http://example.com/foo 4 Filters Controller H Views Partials Helpers Refactoring
  • 18. Iteration 1
  • 19. class Foo < Application def awesome awesome_string end def awesome_string quot;Awesomequot; end end Merb::Router.prepare do match(quot;/foo/awesomequot;). to(:controller => Foo, :action => :awesome). name(:awesome) end
  • 20. dispatch_to(Foo, :awesome) do |cont| cont.should_receive(:awesome_string) end
  • 21. dispatch_to(Foo, :awesome) do |cont| cont.should_receive(:awesome_string) end
  • 22. Iteration 2
  • 23. class Bar < Application def coolness render end end Merb::Router.prepare do match(quot;/foo/awesomequot;). to(:controller => Bar, :action => :coolness). name(:awesome) end
  • 24. dispatch_to(Foo, :awesome) do |cont| cont.should_receive(:awesome_string) end
  • 25. dispatch_to(Foo, :awesome) do |cont| AIL cont.should_receive(:awesome_string) end F
  • 26. request(quot;/foo/awesomequot;).body. should =~ /Awesome/
  • 27. request(url(:awesome)).body. should =~ /Awesome/
  • 28. Broken Interface means failing tests
  • 29. Working Interface means passing tests
  • 30. Write tests about what you care about
  • 31. “It’s Too Hard”
  • 32. Let’s Make it Easy
  • 33. request(url(:speakers)) request(resource(@speaker)) request(quot;/foo/speakersquot;)
  • 34. request(url(:speakers)) one method request(resource(@speaker)) request(quot;/foo/speakersquot;)
  • 35. Sessions are automatically sticky in a spec
  • 36. it quot;should let you inquot; do request(quot;/loginquot;, :method => :post, :params => {:username => quot;userquot;, :password => quot;passquot;}) request(quot;/homequot;).should be_successful end
  • 37. it quot;should let you inquot; do request(quot;/loginquot;, :method => :post, :params => {:username => quot;userquot;, :password => quot;passquot;}) request(quot;/homequot;).should be_successful login end
  • 38. it quot;should let you inquot; do request(quot;/loginquot;, :method => :post, :params => {:username => quot;userquot;, :password => quot;passquot;}) request(quot;/homequot;).should be_successful end you’re logged in
  • 39. describe quot;/loginquot;, :given => quot;successful loginquot; do it quot;should let you inquot; do request(quot;/homequot;).should be_successful end end simpler
  • 40. describe quot;/loginquot;, :given => quot;successful loginquot; do it quot;should let you inquot; do request(quot;/homequot;).should be_successful end end simpler
  • 41. Request Rack status body headers
  • 42. request() helper Rack status body headers
  • 43. request(quot;/fooquot;).body.should == quot;helloquot; request(quot;/fooquot;).should have_xpath(quot;//h1quot;) request(quot;/fooquot;).should( have_selector(quot;h1:contains(text)quot;))
  • 44. request(quot;/fooquot;).body.should == quot;helloquot; request(quot;/fooquot;).should have_xpath(quot;//h1quot;) request(quot;/fooquot;).should( have_selector(quot;h1:contains(text)quot;)) 1.0 final
  • 45. request(quot;/fooquot;).should be_client_error request(quot;/fooquot;).should( have_content_type(:json))
  • 46. Thank you.