Rails carrierwave testing - how to remove file after test?

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

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

but it did not work.

Answers


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

I ended up doing:

user.remove_attachment = true
user.save

I got this tip reading this.


Need Your Help

Cmake test : was a library compiled/linked against libc++ or libstd++?

c++ cmake libstdc++ libc++

I am using cmake to manage my project that uses a third party library.

The method setActualDefaultRingtoneUri(Context, int, Uri) in the type RingtoneManager is not applicable for the arguments OnItemClickListener

android listview onitemclicklistener ringtone

I am making android application and I want when I click on list view item to find ID of clicked item, get resources and set that file as ringtone.However I get this error : The method

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.