Your SlideShare is downloading. ×
0
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Testing Merb
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Testing Merb

2,989

Published on

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

No Downloads
Views
Total Views
2,989
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
71
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

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.

×