So I am in my test environment
now, in the terminial, rake db:test:prepare clears the db... but not when i run it from the code
And I have this in features/support/env.rb:
Before do
task :build_all do
[ :debug, :release ].each do |t|
$build_type = t
Rake::Task["db:test:prepare"].reenable
Rake::Task["db:test:prepare"].invoke
end
end
end
But my data remains in the project_test db when my tests are done running
This is in my database.yml
test:
adapter: mysql
encoding: utf8
database: projectname_test
username: root
password:
Ive also tried
db:test:purge
and
db:test:reset
and I know that it is using my test db, because I check mySQLWorkbench, and it inserts data into the tables... but doesn't delete the data when its done (I have to delete it manually). When the tables are empty, the test cases pass
You should use
begin
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = :truncation
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Before do
DatabaseCleaner.start
end
After do |scenario|
DatabaseCleaner.clean
end
Scenarios in Cucumber, like tests in RSpec, are run in transactions blocks and are rolled back once the scenario is done. Any data that's in the database that shouldn't be there is probably left over from something else. Try purging your database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With