Ruby Soundcloud Gem: Cannot Test Uploaded File-Collection of common programming errors
Haven’t seen much on testing for the soundcloud gem. Most everything has been splendid – however I found that uploading files to SoundCloud through my specs is a bit tricky.
Here’s the problem:
spec:
file = "#{Rails.root}/spec/factories/files/sample.mp3"
title = "From the test suite"
track = @client.post('/tracks', track: {title: title, asset_data: File.new(file)})
Whether or not I use
File.new
or
File.expand_path
the error is the same: NoMethodError: undefined method `map’ for #String:0x007fa1ce8425c0
The successful code in the controller is:
file = params["soundcloud_file"]
title = params["title"]
track = client.post('/tracks', track: {
title: title
asset_data: File.new(file.tempfile, 'rb')
})
Now I understand that params[“soundcloud_file”] is an ActionDispatch::Http::UploadedFile, so that’s what I’ve been attempting to work with for the past hour or so with no luck.
I’m open to any way to successfully test an upload.
-
The problem was with the ‘webmock’ gem. Even using the required version for VCR (
Originally posted 2013-11-09 20:50:42.