Help: How to write tests for a sms service interface


#1

I’m working on a website that integrates sms services. When someone
sends an sms to my service number, the sms provider posts an xml doc to
an url specified by me.

I have implemented the processing method like this:

def process_notification xml = XmlSimple.xml_in(@request.raw_post, 'ForceArray' => false) @params.merge! xml sms_request = SmsboxRequest.new(:phonenumber => @params["sender"], :operator => @params["operator"], :service => @params["service"], :message => @params["message"]) sms_request.save end

I have tested this method with a test application provided by my sms
provider and all works like a charm.
Now I want to write a functional test for this controller, but I don’t
know how to build a post request that works. How am I supposed to call
post so that my xml document is in the raw_post of my TestRequest ?
I tried this:

post :process_notification, xml
post :process_notification, {:params => xml}
post :process_notification, {:id => xml}

where xml contains a valid xml document but none of them work. Any help
is more than welcome !


#2

Hi,

Which sms provider are you using ?


#3

Are you testing the implementation or just your code’s interaction
with the interface? If you’re testing the interaction, then mock the
interface.

http://rubyforge.org/projects/mocha