Integration Testing with RAGI
We're using RAGI to connect rails to Asterisk for one of our current projects. After an hour spent on the phone testing a simple AGI script, I realized that this wouldn't scale. This led to the creation of the ragi_test plugin. Some examples inside.
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:
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
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.
Posted by Mike Mangino on Monday, December 18, 2006