Search code examples
ruby-on-rails-3testingrspec2guard

Is there a way to automatically have a "rake db:migrate RAILS_ENV=test" after "rake db:migrate" in development environment?


Is there a way to automatically do a rake db:migrate RAILS_ENV=test after each rake db:migrate when in development environment?

I have guard and guard-rspec running, and I am really annoyed about the failing tests, even if it works manually in the browser.

It costs me at least 15 minutes every time I had a pause from development, to figure out that I simply forgot to call rake db:migrate:test after the change of the database.

Since I am already using guard I thought about adding guard-rake to the project also, but I dont know which file I should watch. When watching development.sqlite3, rake db:migrate RAILS_ENV=test would be fired every time I do something with my records through the browser, so this is not really what I want.

Can someone help me with my problem?


Solution

  • Possibly just make a command alias in your .bashrc file.

    ~/.bashrc

    alias rake_db_migrate='rake db:migrate db:test:prepare'
    

    Terminal

    $ rake_db_migrate