2011-03-16 40 views
1

在评论为How do I find an image on a page with Cucumber/Capybara解决方案,有人问:如何找到蜻蜓与黄瓜/水豚产生的图像?

我似乎无法弄清楚如何得到这个 与 蜻蜓生成的URL工作。他们看起来像这样: /media/BAh_some_long_string_AwIw/12_11_52_810_5x5.jpg?s=7e360000,其中5x5.jpg是我的文件名。我有 尝试过这样的: // img [@src =“/ media//#{image}?s = *”] 但它不起作用。有任何提示? - Ramon Tayag 2月25日在4:18

我有类似的问题,只有更坏 - 在我的情况下,生成的图像路径甚至不包括(JPG | PNG | GIF)文件名,他们只有这些很长的IDS:

<img src="/media/BAhbB1sHOgZmSSIdNGQ4MTEyOGU3ZjViZmQwZTQ4MDAwMDAyBjoGRVRbCDoGcDoKdGh1bWJJIg0yMDB4MjAwIwY7BlQ" /> 

(使用蒙戈/ GridFS的蜻蜓)

这些路径得到正常的渲染,但我无法弄清楚如何找到它们在黄瓜/水豚步:P

任何我DEAS?我看着Dragonfly's features,但他们只测试图像本身的渲染,而没有检测到它在html页面中的存在。

回答

7

回答我的问题,之后talking to Dragonfly's author(他的工作使这个容易):

#route 
match '/media/:dragonfly/:file_name', :to => Dragonfly[:images] 

#model 
class Store 
    include MongoMapper::Document 
    key :photo_uid, String 
    key :photo_name, String 
    image_accessor :photo 
end 

#view 
<%= image_tag @store.photo.thumb('274x207#').url(:suffix => "/#{@store.photo_name}") if @store.photo %> 

#cucumber 
Then I should see the image "my_photo.png" 

Then /^I should see the image "(.+)"$/ do |image| 
    page.should have_xpath("//img[contains(@src, \"#{image}\")]") 
end 

的关键是添加[附件] _name场模型,该模型蜻蜓自动填充,然后传递作为url()的后缀。除了生成的蜻蜓标识符之外,路由还需要允许:file_name参数。