Bas van Westing
2007-Nov-14 20:56 UTC
Resetting fixtures for each iteration within a single test
Hi, I want to reset the fixture data manually during a single test. I know this action is performed between tests, but I need to trigger it within a single test. I need this because I have a directory full of test data (xml files) which need to be sent to the application and validated for their response. These files are all sent to a single controller action, which dispatches the request to the appropriate Restful controller/ action. This controller mainly exists for backward compatibility reasons which do not map to Restful controllers. I already have tests on the Restful controller actions, but I want to run this dispatching test as well. So what I do now is create a single test which iterates over all these files and after each run reset! the session for the next run. class DispatcherControllerTest < Test::Unit::TestCase def test_all_xml_files all_files.each do |file| post :submit, file ...assertions... reset! end end end The problem is that the submitted files change the state of the application. I don''t want the tests to be dependent of each other so I want to reset the fixture data after each iteration, but I can''t find the method to do this. Does anybody know how to reset the fixtures manually during a single test? Thanks in advance, Bas van Westing --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Nov-14 21:33 UTC
Re: Resetting fixtures for each iteration within a single test
On 14 Nov 2007, at 20:56, Bas van Westing wrote:> > Hi, > > I want to reset the fixture data manually during a single test. I know > this action is performed between tests, but I need to trigger it > within a single test. > > The problem is that the submitted files change the state of the > application. I don''t want the tests to be dependent of each other so I > want to reset the fixture data after each iteration, but I can''t find > the method to do this. > > Does anybody know how to reset the fixtures manually during a single > test?You need to rollback the current database transaction and start a new one. An alternative method would be to dynamically generate a testcase for each data file you have. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bas van Westing
2007-Nov-15 15:47 UTC
Re: Resetting fixtures for each iteration within a single test
Hi Fred, Thanks for your response. Can you also give me the statement which rolls back the current database transaction? Regards, Bas On Nov 14, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 14 Nov 2007, at 20:56, Bas van Westing wrote: > > > > > Hi, > > > I want to reset the fixture data manually during a single test. I know > > this action is performed between tests, but I need to trigger it > > within a single test. > > > The problem is that the submitted files change the state of the > > application. I don''t want the tests to be dependent of each other so I > > want to reset the fixture data after each iteration, but I can''t find > > the method to do this. > > > Does anybody know how to reset the fixtures manually during a single > > test? > > You need to rollback the current database transaction and start a new > one. > An alternative method would be to dynamically generate a testcase for > each data file you have. > > Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Nov-15 16:04 UTC
Re: Resetting fixtures for each iteration within a single test
On 15 Nov 2007, at 15:45, Bas van Westing wrote:> Hi Fred, > > Thanks for your response. Can you also give the statement for rolling > back the current database transaction? >ActiveRecord::Base.connection.rollback_db_transaction ActiveRecord::Base.connection.begin_db_transaction Fred> Regards, Bas > > On Nov 14, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 14 Nov 2007, at 20:56, Bas van Westing wrote: >> >> >> >>> Hi, >> >>> I want to reset the fixture data manually during a single test. I >>> know >>> this action is performed between tests, but I need to trigger it >>> within a single test. >> >>> The problem is that the submitted files change the state of the >>> application. I don''t want the tests to be dependent of each other >>> so I >>> want to reset the fixture data after each iteration, but I can''t >>> find >>> the method to do this. >> >>> Does anybody know how to reset the fixtures manually during a single >>> test? >> >> You need to rollback the current database transaction and start a new >> one. >> An alternative method would be to dynamically generate a testcase for >> each data file you have. >> >> Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bas van Westing
2007-Nov-15 18:01 UTC
Re: Resetting fixtures for each iteration within a single test
Fred, Thanks for your help. I ended up generating the test cases dynamically as you suggested. This gives nicer test outputs in case of failing test cases. Ruby is so beautiful... class DispatcherControllerTest < Test::Unit::TestCase Dir.glob( "#{File.dirname(__FILE__)}/../internal/*input.xml" ).each do |input_filename| output_filename = input_filename.gsub( ''input.xml'', ''output.xml'') next unless File.exists?( output_filename ) method_name = "test_internal_#{File.basename(input_filename, ''.xml'')}" define_method( method_name ) do ...Actual method contents here, comparing the response with the expected output file..... end end end On Nov 15, 5:04 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 15 Nov 2007, at 15:45,BasvanWestingwrote: > > > Hi Fred, > > > Thanks for your response. Can you also give the statement for rolling > > back the current database transaction? > > ActiveRecord::Base.connection.rollback_db_transaction > ActiveRecord::Base.connection.begin_db_transaction > > Fred > > > Regards,Bas > > > On Nov 14, 10:33 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 14 Nov 2007, at 20:56,BasvanWestingwrote: > > >>> Hi, > > >>> I want to reset the fixture data manually during a single test. I > >>> know > >>> this action is performed between tests, but I need to trigger it > >>> within a single test. > > >>> The problem is that the submitted files change the state of the > >>> application. I don''t want the tests to be dependent of each other > >>> so I > >>> want to reset the fixture data after each iteration, but I can''t > >>> find > >>> the method to do this. > > >>> Does anybody know how to reset the fixtures manually during a single > >>> test? > > >> You need to rollback the current database transaction and start a new > >> one. > >> An alternative method would be to dynamically generate a testcase for > >> each data file you have. > > >> Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---