1
我用葡萄在我的rails应用程序中创建api。葡萄rspec上传
现在我想测试我所有的API。在我的api中,我可以上传声音,获取声音/:id并删除声音/:id。
我开始写帖子的声音,但我的测试所有的时间回测试“未定义的方法[]为无:NilClass”。
我上传curl命令(这工作):
curl -X POST -i -F [email protected]/test.mp3 "http://localhost:3000/api/sounds/new?access_token=1234567"
我认为这个问题是在卷曲,当你使用“-F数据=”,你需要“=”如果后添加@我删除@,我有未定义的方法[]为nil:NilClass错误。
现在我的问题是我怎么能在我的测试中添加测试上传文件的@?
我的测试:
it "uploads a file" do
sound_filename = "spec/fixtures/test.mp3"
post "/api/sounds/new", data= Rack::Test::UploadedFile.new(sound_filename, 'audio/mp3', true)
expect(response.status).to eq(201)
expect(response.headers['Content-Type']).to eq("audio/mp3")
expect(response.headers['Content-Disposition']).to eq("attachment; filename*=UTF-8''test.mp3")
end
此测试这个错误:未定义的方法[]为无:NilClass错误。任何人都知道我可以修复它吗?
感谢您的帮助。