A presentation on code refactoring that I gave at Seattle.rb in October, 2012. There is also a behavioral driven development example from my work on the CapGun http://capgun.io/ service.
true end it "can't be partial" do @package.partial?.must_equal false end it "can't be complete" do @package.complete?.must_equal false end Tuesday, January 8, 13
away distractions before do @package = Package.new @package.extend(SpecEmpty) end it "can be empty" do @package.empty?.must_equal true end Tuesday, January 8, 13
code that can be unit tested changes your writing style • If a method can’t be unit tested it must be refactored • Factor out interaction with frameworks from code that is tested Tuesday, January 8, 13
order to list information about orders I want to be able to query the order API Background: Given I am a valid API user And I send and accept JSON Scenario: getting an estimate for a base screen capping job When I send a POST request to "/api/v1/orders/estimate" with the following body: |{ "url": "http://example.com/cucumber#test" }| Then the response should be "200" And the JSON response should not have "order/job" And the JSON response should have an estimate of 1 credits Tuesday, January 8, 13
capping a URL for 1 credit" do post '/estimate.json', '{"url":"http://www.seattlerb.org/"}' JSON.parse(last_response.body).should == { 'order' { 'id' '4fd20a1288f560177600000a' 'url' 'http://www.seattle.rb/' 'cost' 1 } } end end end Tuesday, January 8, 13
It class Order def cost end end describe Order do describe "defaults" do it "should cost 1 credit" do subject.cost.should == 1 end end end Tuesday, January 8, 13
Seattle.rb shirt by veganstraightedge http://www.flickr.com/photos/veganstraightedge/7843002706/in/set-72157631203475428 Amazon cover of “Refactoring” book http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672 Wallace the cat cradled like a baby - Mike Mondragon Xzibit head shot - The Internet Wallace - THE INTERNETS is watching - Mike Mondragon on icanhazcheezburger Green field @ wallpaperstock.net http://wallpaperstock.net/green-field_wallpapers_8739_1024x768_1.html Palouse wheat field - unknown Palouse wheat field - unknown Tilled field - unknown CapGun logo - Mike Mondragon Skitch screen cap of CapGun panel - Mike Mondragon Tilled field - unknown Kitten asleep in food dish http://catlovingcare.com/2042/blog/loosing-weight-tips-for-fat-cats/2009/12/ Skitch screen cap of http://tublr.capgun.io/ - Mike Mondragon CapGun.io result for Seattlerb.org - Mike Mondragon Wallace the cat profile - Mike Mondragon Tuesday, January 8, 13