Topic: Cucumber and Paperclip

I have searched high and low for an answer to this question but cannot seem to find the answer to what I am looking for (which leads me to think that I could be approaching it the wrong way). I have the following step that is failing due to validation... The project model has a screen_grab attribute (paperclip) but no matter what I put in the column I always get a validation error (Validation failed: Screen grab file name must be set., Screen grab content type is not one of image/jpeg, image/jpg, image/gif, image/png, Screen grab file size file size must be between 0 and 512000 bytes. (ActiveRecord::RecordInvalid)).

Feature: Viewing the Portfolio
  As one who works for a living
  I want to record to the projects that I work on
  So that the world can see how good I really am!

  Scenario: View the portfolio
    Given the following projects exists:
      | name       | url                           | screen_grab     |
      | Project 1  |  | screen_grab.gif |
      | Project 2  |  | screen_grab.gif |
      | Project 3  |  | screen_grab.gif |
      | Project 4  |  | screen_grab.gif |
      | Project 5  |  | screen_grab.gif |
      | Project 6  |  | screen_grab.gif |
      | Project 7  |  | screen_grab.gif |
      | Project 8  |  | screen_grab.gif |
      | Project 9  |  | screen_grab.gif |
      | Project 10 | | screen_grab.gif |
      | Project 11 | | screen_grab.gif |
      And I am on the home page
    Then I should see "Project 1"
      And I should see "Project 2"
      And I should see "Project 3"
      And I should see "Project 4"
      And I should see "Project 5"
      And I should see "Project 6"

Apart from the above issue, is the test getting a little out of control (to me it seems overly verbose)? Would I be better off saying something like (see below) because then I could have a predefined Factory(:project) that has an attachment...

# feature
Given there are 16 existing projects

# step (
Given /^there are (\d+) existing (.+)$/ do |n, model_str|
  model_str = model_str.gsub(/\s/, '_').singularize
  model_sym = model_str.to_sym
  klass = eval(model_str.camelize)
  klass.transaction do
    n.to_i.times do |i|

# factories.rb
Factory.sequence(:name) { |n| "Project #{n}" }

Factory.define :project do |project|        { }
  project.url         { "" }      { true }
  # this isn't working correctly but you get the idea...
  project.screen_grab { File.join(File.dirname(__FILE__), "paperclip", 'project', 'screen_grabs', 'screen_grab.gif') }

I understand that it probably comes down to a matter of taste but what is your preferred way of testing this?

On a side note, I would like to include the helpers steps provided by Factory Girl as detailed here: … ree-steps. I have included them in env.rb as described but they don't seem to be available... I realise this isn't a lot of information to go off but is there a way to debug what is being loaded through require?

Re: Cucumber and Paperclip

I have found an answer that should work: … e_uploads/

Unfortunately I just need to work on it a bit as I am getting an error:

can't dup Symbol (TypeError)
      ./lib/paperclip/interpolations.rb:29:in `dup'
      ./lib/paperclip/interpolations.rb:29:in `interpolate'
      ./lib/paperclip/attachment.rb:305:in `interpolate'
      ./lib/paperclip/attachment.rb:122:in `path'
      ./lib/paperclip/storage.rb:40:in `flush_writes'
      ./lib/paperclip/storage.rb:38:in `each'
      ./lib/paperclip/storage.rb:38:in `flush_writes'
      ./lib/paperclip/attachment.rb:144:in `save'
      ./lib/paperclip.rb:351:in `send'
      ./lib/paperclip.rb:351:in `save_attached_files'
      ./lib/paperclip.rb:344:in `each_attachment'
      ./lib/paperclip.rb:343:in `each'
      ./lib/paperclip.rb:343:in `each_attachment'
      ./lib/paperclip.rb:350:in `save_attached_files'
      ./features/step_definitions/project_steps.rb:65:in `times'
      ./features/step_definitions/project_steps.rb:63:in `/^there are (\d+) (.+)$/'
      features/public/portfolio.feature:8:in `Given there are 15 projects'