O'Reilly logo

Test Driven Ajax (on Rails) by Phlip

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enough Planning! Now Rush to Coding...

You could add the following project to any Rails web site. I created a new one with rails yarWiki, then I opened the file config/database.yml and set all the databases to sqlite3. That just shuts ActiveRecord up. This project won't use the database. (If you don't have any Rails projects yet, read another tutorial to get started, and come back here when you know how to work with a Rails site.)

Install two plug-ins, FormTestHelper and ARTS. Plug them in like this:

script/plugin install -x http://form-test-helper.googlecode.com/svn/form_test_helper/
script/plugin install -x http://thar.be/svn/projects/plugins/arts/

They provide select_form and assert_rjs, respectively, to test FORMS and Remote JavaScript (JavaScriptGenerator). Using the vocabulary developed earlier, we could say these assertions attack legacy HTML and JavaScript situations.

Now start the server by opening another command-line shell and entering this:

script/server -p 3000

Our experiments will assume that server is always running and available on port 3000. Now generate the skeleton for our project:

script/generate controller wiki

That creates a controller and its test suite, producing this familiar output:

./app/controllers/wiki_controller.rb
./app/helpers/wiki_helper.rb
./app/views/wiki
./test/functional/wiki_controller_test.rb

Now we start with a test. The Rails test framework might indeed be exemplary, but this Short Cut is about what happens when we move beyond its built-in features. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required