Forum: Ruby on Rails Help: How to write tests for a sms service interface

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gernot K. (Guest)
on 2006-05-25 14:08
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:

<code>
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
</code>

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 !
Rm R. (Guest)
on 2007-02-19 07:36
Hi,

Which sms provider are you using ?
Alex S. (Guest)
on 2007-02-20 00:23
(Received via mailing list)
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
This topic is locked and can not be replied to.