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!

  @wip
  Scenario: View the portfolio
    Given the following projects exists:
      | name       | url                           | screen_grab     |
      | Project 1  | www.project-1.com  | screen_grab.gif |
      | Project 2  | www.project-2.com  | screen_grab.gif |
      | Project 3  | www.project-3.com  | screen_grab.gif |
      | Project 4  | www.project-4.com  | screen_grab.gif |
      | Project 5  | www.project-5.com  | screen_grab.gif |
      | Project 6  | www.project-6.com  | screen_grab.gif |
      | Project 7  | www.project-7.com  | screen_grab.gif |
      | Project 8  | www.project-8.com  | screen_grab.gif |
      | Project 9  | www.project-9.com  | screen_grab.gif |
      | Project 10 | www.project-10.com | screen_grab.gif |
      | Project 11 | www.project-12.com | 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 (http://cassiomarques.wordpress.com/2009/04/16/a-cucumber-step-to-generate-any-number-of-objects-for-any-model/)
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
    klass.destroy_all
    n.to_i.times do |i|
      Factory(model_sym)
    end
  end
end

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

Factory.define :project do |project|
  project.name        { Factory.next(:name) }
  project.url         { "www.google.com" }
  project.active      { 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') }
end

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: http://robots.thoughtbot.com/post/28480 … 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: http://www.pipetodevnull.com/past/2010/ … 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:66
      ./features/step_definitions/project_steps.rb:65:in `times'
      ./features/step_definitions/project_steps.rb:65
      ./features/step_definitions/project_steps.rb:63:in `/^there are (\d+) (.+)$/'
      features/public/portfolio.feature:8:in `Given there are 15 projects'