views:

142

answers:

3

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

A: 

Idk about this, but have you tried dropping and recreating the database on the fly?

Nik
didn't work =( i did the same as above... except with 4 rake lines... with db:test:drop, and db:test:create
DerNalia
running Prepare in the terminal works... so I guess there is something wrong with the code in features/support/env.rb
DerNalia
Alright, maybe recoding (resolving the issue) in features/support/env.rb might be a solution.
Nik
A: 

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.

Ryan Bigg
how? the Cucumber::Rails::World.use_transactional_fixtures = trueis in the env.rb...so the transactions shold be working... but they aren't. there is data left over after I run cucumber features/featurename.feature
DerNalia
A: 

I have a similar problem with the db not resetting object ids to start with 1 after running Cucumber scenario examples. I use factory_girl to seed the test db with 10 or so objects (with a numbered sequence, so id => 1 might have name => name1, etc. ), then I run my first Cucumber scenario example with no problem (db has objects/sequence with id 1 to 10). When the second scenario example runs, the db factories, but this time the object/sequence ids are 11 to 20.

Cucumber::Rails::World.use_transactional_fixtures = true is in the env.rb I run my tests within RubyMine 2.0.2 Hmmm....

Peter Bloom