I tried for a while to mute multiuser requests using webmock and did not find a satisfactory solution.
Ideally, I would like to stub the request as follows:
stub_request(:post, 'http://test.api.com').with(:body => { :file1 => File.new('filepath1'), file2 => File.new('filepath2') })
However, this does not seem to work, and RSpec complains that the request was not muted. Printed request printed:
stub_request(:post, "http://test.api.com"). with(:body => "--785340\r\nContent-Disposition: form-data; name=\"file1\"; filename=\"filepath1\"\r\nContent-Type: text/plain\r\n\r\nhello\r\n--785340\r\nContent-Disposition: form-data; name=\"file2\"; filename=\"filepath2\"\r\nContent-Type: text/plain\r\n\r\nhello2\r\n--785340\r\n", :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'664', 'Content-Type'=>'multipart/form-data; boundary=785340', 'User-Agent'=>'Ruby'}). to_return(:status => 200, :body => "", :headers => {})
Of course, I cannot follow this sentence because borders are generated dynamically. Any idea how I could properly drown out these requests?
Thanks! Bruno
source share