4bb774de244da2d6e7f39a189b905077

in my test case method, i was putting all type of concerns together, which was deadly producing unmanageable test method.
so later i split my test method in two phases, first one is preparation phase and second one is verification phase.

i was wondering whether there is more art of making this thing more understandable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def test_destroy_category_with_dependent
    category = Category.find(3)

    # prepare for verification
    prepare_for_verifying_related_property_mappings(category)
    prepare_for_verifying_category_mappings(category)
    prepare_for_verifying_child_category(category)

    # perform action
    category.destroy

    # ensure the action
    assert_raise(ActiveRecord::RecordNotFound) {
      Category.find(category.id)
    }

    # perform verification
    verify_related_property_mappings(category)
    verify_related_category_mappings(category)
    verify_related_child_category(category)
end

Refactorings

No refactoring yet !

5170ca260dbd2cdfd5a887a4dba7636f

Jeremy Weiskotten

November 21, 2007, November 21, 2007 18:23, permalink

No rating. Login to rate!

You could move the preparation into the setup method or fixtures. However, I tend to prefer localizing it to the test as you did here.

Bfec5f7d1a4aaafc5a2451be8c42d26a

macournoyer

November 22, 2007, November 22, 2007 18:41, permalink

1 rating. Login to rate!

You should give a look at RSpec (http://rspec.rubyforge.org/) or Shoulda (http://thoughtbot.com/projects/shoulda)

4bb774de244da2d6e7f39a189b905077

we4tech

November 23, 2007, November 23, 2007 05:10, permalink

No rating. Login to rate!

hi @macournoyer,
thanks again for your suggestion.
actually i got to know about RSpec during this rails europe conference, here in our team we always follow TDD, as we were mostly from java background we have some fascination with junit type stuff.

we would love to move on RSpec, which is already scheduled to be executed from our next project milestone.
best wishes :)

Bfec5f7d1a4aaafc5a2451be8c42d26a

macournoyer

November 23, 2007, November 23, 2007 15:15, permalink

No rating. Login to rate!

might be easier for you to use Shoulda in that cause, it's plugable into your current Test::Unit::TestCase

4bb774de244da2d6e7f39a189b905077

we4tech

November 23, 2007, November 23, 2007 16:51, permalink

No rating. Login to rate!

thank you @macournoyer, i also think shoulda might be a good choice.

Your refactoring





Format Copy from initial code

or Cancel