#12
Mar 30, 2007

Refactoring User Name Part 3

In the final part of this series you will see how to refactor your tests. Keeping tests clean is important because it will make testing easier to do in the future.
Download (9.8 MB, 4:03)
alternative download for iPod & Apple TV (6.4 MB, 4:03)
# user_test.rb
def test_full_name
  assert_equal 'John Doe', full_name('John', nil, 'Doe'), "nil middle initial"
  assert_equal 'John H. Doe', full_name('John', 'H', 'Doe'), "H middle initial"
  assert_equal 'John Doe', full_name('John', '', 'Doe'), "blank middle initial"
end

def full_name(first, middle, last)
  User.new(:first_name => first, :middle_initial => middle, :last_name => last).full_name
end

RSS Feed for Episode Comments 8 comments

1. Michael Jun 30, 2007 at 18:00

I like how you showed the process of refactoring in this series, but I wouldn't recommend multiple assertions in one controller.

See http://blog.jayfields.com/2007/06/testing-one-assertion-per-test.html


2. Tomek Apr 05, 2008 at 01:51

Yes, I agree. Multiple assertion is a bad practice since only the first assertion gets called if code changes alter behavior.


3. Faktura Jun 15, 2008 at 00:33

Very good cast!


4. Urzad Aug 15, 2008 at 02:04

Nice cast!


5. Bvlgari Necklaces May 06, 2009 at 23:52

Very good cast!


6. fake Tiffany Necklace May 07, 2009 at 01:08

Very good


7. chi hair tools Jun 09, 2009 at 20:44

  sale,100% Quality Guarantee!
 We guarantee we provide the cheapest Chi flat irons,
Chi Hair Straightener, Chi hair tools in the market and 100%
Quality Guarantee.
Straight hair is very useful, and cheap, quality, durability and so on.


8. links of london Jun 11, 2009 at 00:37

nice

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

sponsored by:
if you want to help:
required:
Get Quicktime Player