Forum: Ruby on Rails Testing data from a file

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.
Simon M. (Guest)
on 2009-01-09 08:29
(Received via mailing list)
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
Phlip (Guest)
on 2009-01-10 21:32
(Received via mailing list)
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
http://julik.textdriven.com/svn/tools/rails_plugin... ),
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
Simon M. (Guest)
on 2009-01-11 02:44
(Received via mailing list)
On Sun, 11 Jan 2009 04:31:06 +0900, Phlip <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
This topic is locked and can not be replied to.