Topic: Need help with Rspec xhr request

I have the following function in JS for a drag and drop file uploader:

function uploadFile(file){

             var xhr = new XMLHttpRequest();
             var upload = xhr.upload;
             var uri      =   "/imagebooks/upload_supporting_image/?authenticity_token=" +

   'POST', uri, true);
             xhr.setRequestHeader('X-Filename', file.fileName);



This works properly.  I'm trying to create a spec to test the function
with rspec- anyone know how I can mimic this?  I've tried:

before(:each) do
    @image ="#{Rails.root}/public/images/test/test.jpg",


  describe 'Upload Supporting Image method' do
    it 'should read a binary string and write a file with it' do
      request.env['X-Filename'] = 'test.jpg'
      xhr :post, :upload_supporting_image, @image

But it doesn't work as expected.  Any help is greatly appreciated!

Last edited by sholton311 (2011-03-02 11:04:14)

Re: Need help with Rspec xhr request

xhr :post, :upload_supporting_image, @image, :format => 'js'

If this dosent work out ,share your controller code once.