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

Red Bar

The inner Wiki page needs to detect and register that error. Its node's color should no longer be green. And the outer Wiki needs to register success, because test_WikiTestPage's job is to test that our Wiki detects and registers errors correctly.

Our new goal stack is:

  • If an IFRAME can't serve its page, put an error report into the bottom of the Wiki.

  • Error reports change the clicked node's color to red.

  • Set the background of the node's title (test_hammy_squirrel) to its color variable.

  • Add an rjs.assert command.

  • The TestWiki page should assert that the tested Wiki's node turned red.

  • Hence, the TestWiki page should turn green!

If we can test that, we can test anything in the target IFRAME!

Now how can the test case detect that a target page has failed? The current failure comes from Rails—it serves a well-formed page containing a helpful error message. So our test's setup node needs a script that asserts that the target page's title contains no fault diagnostics. We put the new assertion into our setup nodes, so that each test script can then evaluate under the assumption it has the right page.

First, add to the sample Wiki (the inner Wiki) an assertion that a page loaded correctly:

      - setup:
        - !omap
          - script: \"rjs.assert '!/Exception caught/.test(document.title)'\"

Our Wiki currently pulls its script value from only one node—the target test_ node. The Wiki's .select() method must upgrade to also read the setup node's script value, and to join the two scripts together, if any:

 def ...

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