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
On 14 Nov 2007, at 20:56, Bas van Westing wrote:
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
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 C. [email protected]
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
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 C. [email protected]