The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Shoulda Refactorred

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Amos King

Posts: 78
Nickname: adkron
Registered: Jan, 2007

Amos King is a Web Developer for the US Postal Service and for Ramped Media.
Shoulda Refactorred Posted: Oct 24, 2008 11:12 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Amos King.
Original Post: Shoulda Refactorred
Feed Title: DirtyInformation
Feed URL: http://feeds.feedburner.com/Dirtyinformation
Feed Description: Information about Ruby/Rails/JRuby/WebDevelpoment/whatever.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Amos King
Latest Posts From DirtyInformation

Advertisement

Shoulda has been great for testing, and is really easy to condense. So let's refactor a shoulda test.

class PostTest < Test::Unit::TestCase
  should_ensure_length_in_range :zip, (6..10)
  should_ensure_length_in_range :title, (3..20)
  should_ensure_lenght_in_range :phone, (7..10)
end

Now refactored:

class PostTest < Test::Unit::TestCase
  {:zip => (6..10), :title => (3..20), :phone => (7..10)}.each_pair do |field, range|
    should_ensure_length_in_range field, range
  end
end

And there we have it. Condensed code, and if you have enough of these fields it can really save some key strokes.

Read: Shoulda Refactorred

Topic: Rails Rumble 2008: Developing Run.Track.Run. Previous Topic   Next Topic Topic: Twitter Etiquette

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use