如何找到Dragonfly with Cucumber / Capybara生成的图像?

在如何使用Cucumber / Capybara在页面上找到图像的解决方案的评论中,有人问:

我似乎无法想象如何使用Dragonfly生成的URL。 它们看起来像这样:/media/BAh_some_long_string_AwIw/12_11_52_810_5x5.jpg?s=7e360000,其中5×5.jpg是我的文件名。 我尝试过类似:// img [@src =“/ media / / #{image}?s = *”]但它不起作用。 有什么提示吗? – Ramon Tayag 2月25日凌晨 4点18分

我有一个类似的问题,只是更糟糕 – 在我的情况下,生成的图像路径甚至不包含(jpg | png | gif)文件名,它们只有这些非常长的ID:

 

(使用蜻蜓和mongo / gridfs)

这些路径渲染得很好,但我无法弄清楚如何在Cucumber / Capybara步骤中找到它们:P

有任何想法吗? 我查看了Dragonfly的function ,但是他们只测试了图像本身的渲染,而没有检测到它在html页面中的存在。

在与Dragonfly的作者交谈之后回答我自己的问题(他正在努力使这更容易):

 #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 

关键是在模型中添加[attachment] _name字段,Dragonfly自动填充,然后将其作为后缀传递给url()。 除了生成的蜻蜓标识符之外,路由还需要允许:file_name参数。