Created
October 20, 2009 11:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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