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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs