From: Chris Cropleu Date: 2010-04-14T21:42:39+09:00 Subject: Re: Newbie: Control flow of tests using 'define_method' Aldric Giacomoni wrote: > Chris Cropleu wrote: >> class TestSuite < Test::Unit::TestCase >> >> #Build a hash of Source Database columns and target Database columns >> >> companyRRAccessToBeacon = Hash.new >> companyRRAccessToBeacon['company_id'] = 'ID' >> cmpanyRRAccessToBeacon['ultimate_parent_id'] = 'GlobalUltimateID' >> companyRRAccessToBeacon['fullname'] = 'Name' >> companyRRAccessToBeacon['turnover_curr'] = 'TurnoverCurrencyTypeID' >> companyRRAccessToBeacon['turnover'] = 'TurnoverAmount' >> companyRRAccessToBeacon['u_size_code'] = 'CorporateSizeTypeID' >> companyRRAccessToBeacon['corp_status_id'] = >> 'CorporateOwnershipTypeID' >> companyRRAccessToBeacon['created_user'] = 'RowCreatedBy' >> companyRRAccessToBeacon['created_datetime'] = 'RowCreatedDate' >> companyRRAccessToBeacon['last_modification_by'] = 'RowModifiedBy' >> companyRRAccessToBeacon['last_modification_date'] = >> 'RowModifiedDate' >> companyRRAccessToBeacon['off_limits_id'] = 'OffLimitsID' > Wowzer. How about this? > companyRRAccessToBeacon = {'company_id' => 'ID', 'ultimate_parent_id' => > 'GlobalUltimateID' } > And so on and so forth ? A little cleaner, a little easier to read, > fewer repetitions. >> >> #Connect to the RRAccess and Beacon databases >> rraccesshandle = connectrraccessdb >> beaconhandle = connectbeacondb >> >> > [...] >> >> #Loop through each record returned in the Data Driven Test set. >> companyrowData.each do | companydata | >> puts "In #{companydata} loop" >> #If no Company records are returned then run the test. >> companydata["company_id"] != "" >> recordtofetch = companydata["company_id"] > > Where is your if statement? Maybe you mean this? > recordtofetch = companydata['company_id'] unless > companydata['company_id'].empty? > >> > [...] >> >> >> The output of this is as follows: >> > [...] >> Inside assert_equal loop for test_company_CorporateOwnershipTypeID >> FInside assert_equal loop for test_company_CorporateSizeTypeID >> FInside assert_equal loop for test_company_GlobalUltimateID >> .Inside assert_equal loop for test_company_ID >> .Inside assert_equal loop for test_company_Name >> .Inside assert_equal loop for test_company_OffLimitsID >> FInside assert_equal loop for test_company_RowCreatedBy >> .Inside assert_equal loop for test_company_RowCreatedDate >> .Inside assert_equal loop for test_company_RowModifiedBy >> .Inside assert_equal loop for test_company_RowModifiedDate >> .Inside assert_equal loop for test_company_TurnoverAmount >> .Inside assert_equal loop for test_company_TurnoverCurrencyTypeID >> F >> Finished in 0.029 seconds. >> >> 1) Failure: >> test_company_CorporateOwnershipTypeID(TestSuite) >> [C:/Users/ecucropc/Documents/Visual Studio >> 2008/Projects/DataSynchronisation/DataSynchronisation/CommonTest.rb:57]: >> <"QUO "> expected but was >> <1>. > > Well, in your first test, you get a '1' back and you apparently expect a > "QUO ". > Anything else the errors can tell you that they can't tell us? > Look into this and get back to us a little later.. The tests work, > they're telling you that they fail :) Thanks for your feedback. You are quite right, the assertion is giving me the failures I was expecting, however my rather large code snippet probably did not highlight my particular problem in the loop control I was trying to describe. I have since spoken with some wiser heads (namely the developers on the team) and they suggested a good method for me to move forward on this. I have now captured the column differences (if there are any) in a hash and the put that hash into an assert_nil test. Much cleaner and I only need to run one test as opposed to the potential hundreds in my original solution. Regards, Chris -- Posted via http://www.ruby-forum.com/.