# HttpMock Post Parameters

**URL:** <https://www.ruby-forum.com/t/httpmock-post-parameters/171693>\
**Category:** Rails\
**Created:** [July 7, 2009, 6:39pm UTC](https://www.ruby-forum.com/t/httpmock-post-parameters/171693 "2009-07-07T18:39:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 7, 2009, 6:39pm UTC](https://www.ruby-forum.com/t/httpmock-post-parameters/171693/1 "2009-07-07T18:39:24Z")

</div>

Does anyone know how you can specify the body of an HttpMock post as  
well as the body of the response?

I’m trying to test a restful API where the parameters are posted in in  
the body of the post as XML and the response is XML in the response  
body.

As far as I can tell, you can only specify one body in a mock object?

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 21, 2009, 10:36pm UTC](https://www.ruby-forum.com/t/httpmock-post-parameters/171693/2 "2009-07-21T22:36:12Z")

</div>

I never got a reply, so either I’m crazy or other people have just  
lived with the issue. In any event, I wanted to post my work around.  
Rather than creating my mock request/response pairs using the  
ActiveResource::HttpMock.respond\_to method, I actually had to create  
both the request and the response individually and then add them to  
the ActiveResource::HttpMock.responses. Here is what I did:

# Created my mock request:

request = ActiveResource::Request.new(:post,  
path = “/my/path.xml”,  
body =  
my\_request\_body\_xml\_string,  
request\_headers =  
request\_headers\_hash)

# Created my mock response:

response = ActiveResource::Response.new(body =  
my\_response\_body\_xml\_string,  
status = 200,  
response\_header\_hash)

# Add the pair to the mock responses:

ActiveResource::HttpMock.responses \<\< [request, response]
