#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 -11 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. Urzad Aug 15, 2008 at 02:04

Nice cast!


4. Iuniya Jan 31, 2010 at 06:45

Good matherial.


5. Nikolaha Mar 21, 2010 at 02:32

[url=http://aptekacatalog.ru/]Nikolaha[/url]
Good matherial.


6. YUka Apr 20, 2010 at 08:36

i think it is good article 5+!!1


7. free directory list Aug 11, 2010 at 22:03

If God would exists it will be you... very thanks for this screencast.


8. free directory list Aug 11, 2010 at 22:03

If God would exists it will be you... very thanks for this screencast.


9. free directory list Aug 11, 2010 at 22:03

If God would exists it will be you... very thanks for this screencast.


10. mbt shoes sale Aug 14, 2010 at 18:44

It is a nice article,i appreciate it,i will keep it on my dashboad.


11. mbt sport Aug 14, 2010 at 18:45

I just want to say the spirit is positive,but the content is simply.


12. snow boots Aug 31, 2010 at 02:08

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


13. Dolce & Gabbana Belts Sep 01, 2010 at 22:54

I think this is a great post. One thing that I find the most helpful is number five. Sometimes when I write, I just let the flow of the words and information come out so much that I loose the purpose. It’s only after editing when I realize what I’ve done. There’s defiantly a lot of great tips here I’m going to try to be more aware of.

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
Give Back to Open Source