Testing Merb
Upcoming SlideShare
Loading in...5
×
 

Testing Merb

on

  • 5,023 views

 

Statistics

Views

Total Views
5,023
Views on SlideShare
5,013
Embed Views
10

Actions

Likes
3
Downloads
70
Comments
0

2 Embeds 10

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

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 Testing Merb Presentation Transcript

  • Testing Merb The Right Way
  • Why Test?
  • TDD
  • TDD and Regressions
  • TDD and Regressions I am not saying TDD is bad, but this talk doesn’t focus on mock- driven TDD.
  • Resiliant Against Refactoring
  • 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
  • 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
  • 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
  • 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
  • How to Test Three Rules
  • Broken Interface means failing tests
  • Working Interface means passing tests
  • Write tests about what you care about
  • http://example.com/foo Filters Controller Views Helpers What Happens in Your App
  • http://example.com/foo Your App What You Care About
  • http://example.com/foo 4 Filters Controller H Views Partials Helpers Refactoring
  • Iteration 1
  • 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
  • dispatch_to(Foo, :awesome) do |cont| cont.should_receive(:awesome_string) end
  • dispatch_to(Foo, :awesome) do |cont| cont.should_receive(:awesome_string) end
  • Iteration 2
  • class Bar < Application def coolness render end end Merb::Router.prepare do match(quot;/foo/awesomequot;). to(:controller => Bar, :action => :coolness). name(:awesome) end
  • dispatch_to(Foo, :awesome) do |cont| cont.should_receive(:awesome_string) end
  • dispatch_to(Foo, :awesome) do |cont| AIL cont.should_receive(:awesome_string) end F
  • request(quot;/foo/awesomequot;).body. should =~ /Awesome/
  • request(url(:awesome)).body. should =~ /Awesome/
  • Broken Interface means failing tests
  • Working Interface means passing tests
  • Write tests about what you care about
  • “It’s Too Hard”
  • Let’s Make it Easy
  • request(url(:speakers)) request(resource(@speaker)) request(quot;/foo/speakersquot;)
  • request(url(:speakers)) one method request(resource(@speaker)) request(quot;/foo/speakersquot;)
  • Sessions are automatically sticky in a spec
  • 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
  • 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
  • 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
  • describe quot;/loginquot;, :given => quot;successful loginquot; do it quot;should let you inquot; do request(quot;/homequot;).should be_successful end end simpler
  • describe quot;/loginquot;, :given => quot;successful loginquot; do it quot;should let you inquot; do request(quot;/homequot;).should be_successful end end simpler
  • Request Rack status body headers
  • request() helper Rack status body headers
  • 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;))
  • 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
  • request(quot;/fooquot;).should be_client_error request(quot;/fooquot;).should( have_content_type(:json))
  • Thank you.