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 !
Jeremy Weiskotten
November 21, 2007, November 21, 2007 18:23, permalink
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.
macournoyer
November 22, 2007, November 22, 2007 18:41, permalink
You should give a look at RSpec (http://rspec.rubyforge.org/) or Shoulda (http://thoughtbot.com/projects/shoulda)
we4tech
November 23, 2007, November 23, 2007 05:10, permalink
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 :)
macournoyer
November 23, 2007, November 23, 2007 15:15, permalink
might be easier for you to use Shoulda in that cause, it's plugable into your current Test::Unit::TestCase
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.