开发者

Rails testing with Watir. How do I load my test db with the fixtures from /test/fixtures

I'm trying to test my Rails App with test fixtures using Watir. The watir tests work but I can't seem to load my test db with the fixtures from /test/fixtures.

I tried using rake tasks with RAILS_ENV=test but only m开发者_JS百科anaged to load the fixtures from /db/fixtures/


Found a way to do this using rake tasks.

namespace :watir do
  desc "Initiate the db for watir tests" 
  task :db_reset do
    if (ENV['RAILS_ENV'] == "test")
      Rake::Task["db:test:prepare"].invoke
      Rake::Task["db:test:load"].invoke
      Rake::Task["db:seed"].invoke
      Rake::Task["db:fixtures:load"].invoke("FIXTURES=x,y,z,....") #x,y,z are the name of the fixtures in test/fixtures/*
    else
      puts "Must be executed with test flag ('RAILS_ENV=test')"
    end
  end
end

To run it I do rake watir:db_reset

Now I can run the watir tests on the test fixtures

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜