Unfortunately for me “rake test” were not a feasible feature, since I’ve learned that none of the transactional fixtures work very well with Sybase. Based on the previous my tests were not very accurate since records were lingering around and overlapping each other producing folse results. In order to make sure 99% accuracy I descarde fixtures method and implemented my tests with following
class LegalEntityTest < Test::Unit::TestCase
def setup
Fixtures.create_fixtures("test/fixtures","leb_legal_entities","LegalEntity")
end
def teardown
LegalEntity.delete_all
@request.reset_session
end
...
end
More on create_fixtures method can be found here
As you can see this way I ensure that on each unit test fixture is added and then the whole table is cleaned out.
NOTE: there is a down side to it. My test time increased from 49s to 69 which is obvious since insertion as well as deletion is performed on every test. So if you need more accuracy and don’t care about test execution time this is for you.
Also useful adding @request.reset_session method to teardown method to insure that all of your sessions are reset.
Important create files folder in your test/fixtures folder
for csv content I’ve used:
assert_nothing_raised{
post :add_multiple_emails,
:emails_csv => 'test/fixtures/files/emails_file.csv'
}
RSpec uses test_helper called file_file_uload. It will look for files in the spec/fixtures directory
post :import_contacts,:csv_file => fixture_file_upload('files/email_contacts.csv')