<— TutorialStepFour | Tutorial | TutorialStepSix (Coding) —>
Go to your rails folder
First clone your development database by running “rake db:test:clone”
Then you can run the initial tests that were generated with the controller by simply typing “rake” (the tests are the default rake action.
If rake is installed on your computer, it then performs some tests to ensure your rails has been correctly deployed.
As you develop controllers and models, functional and unit tests are automatically generated and added to the test\functional and test\unit directories, and fixtures to the test\fixtures directory.
<— TutorialStepFour | Tutorial | TutorialStepSix (Coding) —>
note: As of rails 0.9.5, the tests work for MySQL, PostgreSQL and SQLite (versions 2 and 3). Earlier rails versions may have problems running the tests if you are not using MySQL (so upgrade!).
This didn’t work for me
Did you have a test database created? Check your “config/database.yml”.
Try creating the test database with the following: rake db:create RAILSENV=’test’_
Didn’t work for me either, even though stage six works. rake aborted, you have a nil object where you probably didn’t expect it. Odds are you want an instance of Array instead
This might not have worked if you missed TutorialStepOne, which is where the database script is presented. It seems that Tutorial went right to TutorialStepTwo instead, but I fixed that. The script needs to be used for the test database for testing to work.
I had a similar problem and solved it by creating a table in my test database playgroundtest called playgrounds with an integer column, id_
Again, the tests failied until I have created all three databases, and created at least one table.
If you do rake db:create, only the first database from config/database.yml is created. Instead, do rake db:create:all and everything works fine.
PostgreSQL you have to create database rails_test and create database rails_development as well. Then when you’re connected to your rails_development database \c railsdevelopment_ you also have to create the same table structure as you did in TutorialStepOnePostgresql.
_Wonderful: “Here’s how to test”. What should I see? I get a failure message but again, a cryptic Rails error messages. Apparently I should be looking in what look like system files ( /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb ) for information about what test was executed and what failed. Are there any gems that spit out reasonable error messages? For example:
Test failed:
I tried ot do X and it failed with Error message Y
At the moment I have:
Test failures
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute’
plus a whole bunch more. Execute what? Is my system file pooched or is my app pooched? Is it my model? my db? my html?
I’m having some similar problems. I can run tests by running the individual file, but then i type rake in the base dir and everything explodes. I think it may be due to rake’s recreating the test database’s structure from the production database’s structure. I think there may be more than structure there that is needed to have the app work.
You need to add your database password to the ‘test’ section of database.yml, I think. Works for me, anyway. However, the original database.yml that we blew away advises that rake will destroy all data in your test database, so this should probably be different from your devel and production databases.
I modified the file 002_create_people" and use “add_column” instead of “create_table” and works good..
Also “rake:db:test” and “rake”..
See "linkname
<— TutorialStepFour | Tutorial | TutorialStepSix (Coding) —>