# Help: How to write tests for a sms service interface

**URL:** <https://www.ruby-forum.com/t/help-how-to-write-tests-for-a-sms-service-interface/61588>\
**Category:** Rails\
**Created:** [May 25, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/help-how-to-write-tests-for-a-sms-service-interface/61588 "2006-05-25T12:08:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkogler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ba9def/32.png) [@gkogler](https://www.ruby-forum.com/u/gkogler)\
**Post date:** [May 25, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/help-how-to-write-tests-for-a-sms-service-interface/61588/1 "2006-05-25T12:08:24Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![gkogler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ba9def/32.png) [@gkogler](https://www.ruby-forum.com/u/gkogler)\
**Post date:** [February 19, 2007, 6:36am UTC](https://www.ruby-forum.com/t/help-how-to-write-tests-for-a-sms-service-interface/61588/2 "2007-02-19T06:36:16Z")

</div>

Hi,

Which sms provider are you using ?

---

<div class="post-metadata">

**Author:** ![gkogler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ba9def/32.png) [@gkogler](https://www.ruby-forum.com/u/gkogler)\
**Post date:** [February 19, 2007, 11:23pm UTC](https://www.ruby-forum.com/t/help-how-to-write-tests-for-a-sms-service-interface/61588/3 "2007-02-19T23:23:06Z")

</div>

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](http://rubyforge.org/projects/mocha)
