Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3999766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:41:56+00:00 2026-05-20T07:41:56+00:00

I have 2 cucumber scenarios that simulate paperclip image upload. I want to remove

  • 0

I have 2 cucumber scenarios that simulate paperclip image upload. I want to remove those folders again once scenarios are complete.

I have the following attachment folder structure:
:url => “/system/:attachment/:listing_id/:id/:style_:filename“

Paperclip automatically deletes the :id/:style_:filename folder but not the parent folder.

I have a the following in my listings controller (1 listing has many images) which works great to remove the image folder with the listing id when the listing is deleted. I need to simulate the same in Cucumber after the step is run.

def destroy 
    @listing = Listing.find(params[:id])  

    # if destroy was a success, remove the listing image folder
    if @listing.destroy 


    end 

    require 'fileutils'
    dir = Rails.root + '/system/photos/' + @listing.id.to_s()
    FileUtils.rm_rf(dir)


    respond_to do |format| 
        format.html { redirect_to(listings_url) } 
        format.xml { head :ok } 
    end 
end 

I could a) tell cucumber to delete the :listing_id folder name after running through the scenario or b) tell cucumber to delete the listing as the final step?

I’ve tried adding this to my cucumber env.rb file:

AfterStep('@paperclip') do
      # This will only run before steps within scenarios tagged
      # with @cucumis AND @sativus.
        # delete folders that were created with paperclip during the test
        require 'fileutils'
        #@listing.id = 55
        #dir = Rails.root + '/system/photos/' + @listing.id.to_s()
        dir = Rails.root + '/system/photos/55' # NOT WORKING
        FileUtils.rm_rf(dir)
    end

But that causes problems because 1) I don’t know how to get the @listing.id from that scenario, and 2) even when I hardcode it (as above) it doesn’t remove it.

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:41:57+00:00Added an answer on May 20, 2026 at 7:41 am

    Already a bit older, but as I just ran over the same issue myself here is what I did:

    dir = Rails.root + 'images/'
    dir.rmtree if dir.directory?
    
    # or the short form, if you know the directory will be there
    (Rails.root + 'images/').rmtree
    

    So I guess the problem was your ‘/’ at the beginning of the folder. At least for me it didn’t work with that slash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to test some features that needs delayed jobs to work, on cucumber.
I'm using Grails 2.1.1 with Cucumber and Geb. I have an Auth.feature that contains
I have around 30 scenarios that all bar one require this step to be
Say that I have an application where user can upload his avatar, and then
I have a cucumber test (using Capybara) that needs to follow a link in
In my Rails application, I have a set of cucumber acceptance tests that test
I have a suite of scenarios that should be runned against a site. Now
I have a cucumber scenario outline for testing a webservice that is similar to:
I'm trying to write a Cucumber scenario that requires me to have a logged
I have a cucumber step that involves the following: When /^I select from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.