Integration Testing with RAGI

Posted by Mike Mangino on Dec 18, 2006

RAGI is a simple interface that allows you to drive IVR applications from within RAILS. It makes it very simple to allow your users to obtain information via the telephone. To develop a RAGI application, you create a handler class that specifies the procedures for handling a call. Now, you can easily test these applications using the ragi_test plugin available via rubyforge.

To create a test, all you need to do is create your test as a subclass of ElevatedRails::RagiTestCase. Here’s an example:

<pre> class VerificationHandlerTest < ElevatedRails::RagiTestCase fixtures :phone_numbers def test_success @handler.place_call("6145551212") #this is the callerid assert_action :play_sound assert_plays_sound("thank_you_for_calling") assert_action :get_data assert_plays_sound("please_enter_your_activation_code") @handler.enter_digits "12345" assert_action :play_sound assert_plays_sound "activation_success" assert_action :hangup end end </pre>

That’s all it takes to test a basic phone conversation. The code is still pretty rough. You can’t test timeouts and most AGI methods aren’t implemented, but it is enough for basic tests. Expect more AGI methods to be added and more solid code to appear over the coming weeks.