• Home
  • Tutorials
  • Getting started with Ruby Concordion on Rails
  • Older tutorial for versions of Ruby Concordion a.k.a. rcor
  • Tutorial

    This tutorial is a bit out of date.

    Learn how to instrument html documents to make them active specifications with rcor.

    Details

    Here is the canonical Hello World example for rcor. Readers familiar with Concordion will note that the instrumentation is exactly the same for this example.

    We will create two files that correspond to the test: "basic_assert.html" and "basic_assert_test.rb".

    The Test: basic_assert.html

    <html xmlns:concordion="http://www.concordion.org/2007/concordion">
    <body>
    The greeting should be:
    <p concordion:assertEquals="get_greeting">Hello World!</p>
    </body>
    </html>

    Here we're using the RCor command "assertEquals" to compare the actual results of our system to the expected results. In this case, we expect "Hello World!" when we invoke the system through "get_greeting" in the fixture class.

    The Fixture: basic_assert_test.rb

    class BasicAssertTest < ConcordionTestCase
    def get_greeting
    "Hello World!" # Normally this would call the code you're trying to test
    end
    end

    Then we create a script to run our hello world test: "run_the_spec.rb".

    In practice the next file need not be created if your project has other tests (e.g. if you are using Rake and globs like *_test.rb to find your project tests).

    Runtime: run_the_spec.rb

    # This is the simplest script to run an RCor spec, normally would be a Rake script.
    require 'test/unit'
    require 'rcor'
    require 'basic_assert_test'

    Result: running "run_the_spec.rb" will hand control to RCor and produce "basic_assert_test_output.html'.

    This file will be based on the input document, but will find RCor commands in the HTML and decorate them with either Success or Failure, depending on the behavior of the code you're testing.

    It looks like this:

    Output snippet from: basic_assert_test_output.html

      The Greeting should be: <p concordion:assertequals="get_greeting" class="concordion_success">Hello World!</p>
    

    Want to know more?

    Have a look at a more ComplexExample, or see WhatRcorActuallyDoes, or VariationsOnAttributes.