rspec と capybara を使用して、carrierwave アップロード機能をテストしています。私は次のようなものを持っています:
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 ディレクトリに残ることです。テストが完了したら、どのように削除できますか? 私はこのようなことを試しました:
after do
user.remove_attachment!
end
しかし、うまくいきませんでした。