Skip to content

Instantly share code, notes, and snippets.

@rodreegez
Created October 20, 2009 11:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodreegez/214185 to your computer and use it in GitHub Desktop.
Save rodreegez/214185 to your computer and use it in GitHub Desktop.
I was having trouble testing images uploads with the Cucumber && Webrat && Selenium setup. This was basically because I was not calling the file path correctly. To prevent this in future, I wrote a helper to extend the Cucumber World object and explicitly
module ImageHelpers
def image_path(size)
case size
when "thumbnail"
File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "fixtures", "adam_mint.jpg"))
# NOTE: I created a sub dir of "support" called "fixtures" in which to place test files.
else
raise "don't know where to find a #{size} image"
end
end
end
World(ImageHelpers)
Scenario: A Member uploads a photo
Given I am signed in as the Member "tambourine"
And I am on my profile edit page
When I follow "Upload a photo"
And I attach a "thumbnail" image to "image_source_file"
And I press "Upload photo"
Then I should see "This is a caption"
# added the following step to explicitly handel images
When /^I attach a "([^\"]*)" image to "([^\"]*)"$/ do |size, field|
attach_file(field, image_path(size))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment