# Testing data from a file

**URL:** <https://www.ruby-forum.com/t/testing-data-from-a-file/157291>\
**Category:** Rails\
**Created:** [January 9, 2009, 7:29am UTC](https://www.ruby-forum.com/t/testing-data-from-a-file/157291 "2009-01-09T07:29:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijomo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@sijomo](https://www.ruby-forum.com/u/sijomo)\
**Post date:** [January 9, 2009, 7:29am UTC](https://www.ruby-forum.com/t/testing-data-from-a-file/157291/1 "2009-01-09T07:29:39Z")

</div>

Hi,

I have some functional tests that require XML input that gets set into  
the  
RAW\_POST\_DATA. I would like to get the XML for each tests from files (to  
save having lots of XML in my test.rb. Is there anything in the testing  
framework to handle this, or should I just load the file manually?

Cheers  
Simon

---

<div class="post-metadata">

**Author:** ![sijomo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@sijomo](https://www.ruby-forum.com/u/sijomo)\
**Post date:** [January 10, 2009, 8:32pm UTC](https://www.ruby-forum.com/t/testing-data-from-a-file/157291/2 "2009-01-10T20:32:11Z")

</div>

Simon M. wrote:

> I have some functional tests that require XML input that gets set into the  
> RAW\_POST\_DATA. I would like to get the XML for each tests from files (to  
> save having lots of XML in my test.rb. Is there anything in the testing  
> framework to handle this, or should I just load the file manually?

If you mean the data comes as a file upload, look up the upload\_mock  
plugin (  
posserbly  
[textdriven.com&nbsp;-&nbsp;textdriven Resources and Information.](http://julik.textdriven.com/svn/tools/rails_plugins/upload_mock/) ),  
and add an XML mimetype to it. We use it to test paperclip (which is the  
best  
way to store uploaded files we have seen so far):

def test\_upload\_one\_document  
image = MockUpload.new(“image.pdf”)  
owner = owners(:a\_document\_owner)

```
 doc = assert_latest owner.documents do
   post :edit_owner, :owner_id => owner.id, :document => image
 end

 assert{ doc.image_file_name =~ /image.pdf/ }

```

end

If you don’t mean that, then just write a folder in test/fixtures and  
put XML  
files in it, then write a test helper method to load them into your  
params.

–  
Phlip

---

<div class="post-metadata">

**Author:** ![sijomo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@sijomo](https://www.ruby-forum.com/u/sijomo)\
**Post date:** [January 11, 2009, 1:44am UTC](https://www.ruby-forum.com/t/testing-data-from-a-file/157291/3 "2009-01-11T01:44:25Z")

</div>

On Sun, 11 Jan 2009 04:31:06 +0900, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If you don’t mean that, then just write a folder in test/fixtures and  
> put XML  
> files in it, then write a test helper method to load them into your  
> params.

Yeah, that’s what I meant. That’s basically what I ended up doing, but I  
was wondering if there was any test helpers already, or if there was a  
‘best practise’ way of doing it.

Cheers  
Simon
