Testing picture / file uploads with webrat and cucumber
Webrat implements the step:
1 2 3 4 5 |
When /^I attach the "(.*)" file at "(.*)" to "(.*)"$/ do |type, path, field| attach_file(field, path, type) end |
So, for example:
1 2 3 4 5 |
Given X When I attach the "image/jpg" file at "features/support/picture.jpg" to "avatar_image" Then Y |
March 25, 2009

Nice. You should submit this as a patch to Cucumber, for the default webrat step definitions.
March 27, 2009 at 2:38 PMWhat would be nice though is if the attach_file command made the type optional and it inferred it by looking at the file...
@ben, I was all set to do both of those, but it turns out that they are both already done. attach_file's content type already is optional, and there is the following step already in the cukes rails gen in head:
March 27, 2009 at 8:11 PMWhen /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
attach_file(field, path)
end