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=" + $('meta[name=csrf-token]').attr("content");

   '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", 'rb')


  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     end   end

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