riot
riot is a cute little testing framework. It is a great example of the variety of frameworks that are available in the Ruby language in general and testing frameworks in particular.
The riot testing framework is designed for fast unit test writing and execution. Its main object is context, which is where you write tests about a specific subject, feature, or other logical separation. Contexts can also be nested within each other to gather similar subjects or features and to create a hierarchical structure of tests.
An interesting feature of contexts in riot, which differs them from other testing frameworks, is that they have a setup method that is executed only once per context, and not per test method. As a result, you get faster execution of your tests. Moreover, because setup methods on most testing frameworks are used to create an object that is used later on, riot simplifies that and spares the need to save the object to a variable. All you have to do is return the object and the riot framework will save it for you in a variable named topic, which will be accessible to all methods within the context.
Last but not least, the process of writing test methods in the riot framework has been simplified as well. The test method is called asserts, and it receives a textual description and a code block where the actual testing code is written. The testing code should return true to indicate that the test is successful and false if it is not.
For example, the next code contains tests for the DayNightHelper class using the riot framework. Notice how simple and short the code turns out:
require "DayNightHelper.dll" require "rubygems" require "riot" # Define a context context "Tests DayNightHelper class for perfection" do # Define the setup method which returns an instance of DayNightHelper setup { CustomTools::DayNightHelper.new } # Define the test methods asserts("It is day on 15:00") do topic.is_day(Time.local(2012,12,21,15,0)) end asserts("It is NOT night on 15:00") do !topic.is_night(Time.local(2012,12,21,15,0)) end end
To run it, from the command line use the IronRuby interpreter, ir.exe, to execute the test file. Assuming that the sample code written above is saved in a file named “riot_test.rb”, the following sample contains the execution command and its output:
>ir riot_test.rb Tests DayNightHelper class for perfection + asserts It is day on 15:00 + asserts It is NOT night on 15:00 2 passes, 0 failures, 0 errors in 0.053003 seconds
The riot framework is small but powerful. To learn more about it, visit its official site.