简体   繁体   中英

When To Use A Particular Rails Environment for Testing?

I am teaching myself Ruby On Rails with Michael Hartl's Book. When it uncovered the use of seeds.rb file, I tested within Development Environment , it Failed . When set to Test Environment , It Succeeded . Why? When will I need to change the environment again for successful tests?

When you say I tested within Development Environment, it Failed. , you are not running automated tests. You ran the rake db:seed script against the development database. The same task can be run against the test environment with rake db:seed RAILS_ENV=test . Again, this is not an automated test.

There are many reasons why rake db:seed run against the development environment failed in your case. The specific reason could be identified based on the error message.

development environment is one where you work on a day to day basis, adding/changing functionality by making code changes. By default, most scripts assume that you are working with development environment.

test environment is the environment against which the automated tests are run. In the case of rails tutorial, the automated tests are written in the files under test folder. When automated tests are run on a rails application - with rake test or some other way - the test environment is used to run these tests against. The test database gets cleaned up before running the tests to ensure the tests are run starting with a blank state.

Hope this clarifies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM