Cucumber + Paperclip
I just spent an inordinately long time trying to figure out how to get Cucumber tests to create records with Paperclip files attached. Those of you with an equally troglodytic IQ may thus find this snippet useful. The idea here, which is probably obvious, is that I have an upload-files folder in my Cucumber features folder in the root of the Rails application. I put the required sample files there. Be warned that this is actually saving the files to your public folder and they will not get removed when the test is done. When I figure out a better way of doing this I will update this article. Or better yet, if you know a better way of doing this, please a post a comment!
features/page_stepbs.rb:
Given /^I have 1 page$/ do
path = "#{RAILS_ROOT}/features/upload-files/"
image = File.new(path + "image.jpg")
song = File.new(path + "song.mp3")
Page.create!(:image=>image,:song=>song)
end
I am available for Ruby on Rails consulting work – get in touch to learn more.