Rails载波测试-测试后如何删除文件? [英] Rails carrierwave testing - how to remove file after test?

查看:68
本文介绍了Rails载波测试-测试后如何删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rspec和capybara测试载波上传功能。我有类似的东西:

I am testing the carrierwave upload functionality using rspec and capybara. I have something like:

describe "attachment" do
    let(:local_path)  { "my/file/path" }
    before do
      attach_file('Attachment file', local_path)
      click_button "Save changes"       
    end

    specify {user.attachment.should_not be_nil}
    it { should have_link('attachment', href: user.attachment_url) }
end

这很好用。问题在于测试后,上传的图像仍保留在我的public / uploads目录中。测试完成后如何将其删除?我尝试过这样的事情:

And this works great. The problem is that after testing the uploaded image remains in my public/uploads directory. How can I remove it after the test is done? I tried something like this:

after do
   user.remove_attachment!
end

但它不起作用。

推荐答案

您不是唯一一个在载波中删除文件有问题的人。

You're not the only one having issues to delete the files in carrierwave.

我最终做了:

user.remove_attachment = true
user.save

我得到了这个提示阅读此信息

这篇关于Rails载波测试-测试后如何删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆