# Testing image\_tag :src (asset id issue)

**URL:** <https://www.ruby-forum.com/t/testing-image-tag-src-asset-id-issue/190830>\
**Category:** Rails\
**Created:** [June 28, 2010, 10:39pm UTC](https://www.ruby-forum.com/t/testing-image-tag-src-asset-id-issue/190830 "2010-06-28T22:39:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DKDKDK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DKDKDK](https://www.ruby-forum.com/u/DKDKDK)\
**Post date:** [June 28, 2010, 10:39pm UTC](https://www.ruby-forum.com/t/testing-image-tag-src-asset-id-issue/190830/1 "2010-06-28T22:39:16Z")

</div>

This seems like it should be real easy to do but I have not found any  
documentation:

I have an image tag in a page:

\<%= image\_tag “arrow\_green.gif”, :alt =\> “image did not load” %\>

And a functional test I would like to write:

assert\_tag :tag =\> “img”, :attributes =\> { :src =\> “arrow\_green.gif” }

Of course, rails return the asset id at the end, so the test fails:

expected tag, but no tag found matching {:tag=\>“img”,  
:attributes=\>{:src=\>“arrow\_green.giv”}} in…

So is there a way to write a test for this? I know I can use an :alt  
property and test that, but I really would rather test the :src. Any way  
to  
get the asset id within the test so I could write:

assert\_tag :tag =\> “img”, :attributes =\> { :src =\> “arrow\_green.gif” +  
asset\_id }

---

<div class="post-metadata">

**Author:** ![DKDKDK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DKDKDK](https://www.ruby-forum.com/u/DKDKDK)\
**Post date:** [June 28, 2010, 10:43pm UTC](https://www.ruby-forum.com/t/testing-image-tag-src-asset-id-issue/190830/2 "2010-06-28T22:43:22Z")

</div>

On Jun 28, 2010, at 1:37 PM, DK wrote:

> Of course, rails return the asset id at the end, so the test fails:
> 
> expected tag, but no tag found matching {:tag=\>“img”, :attributes=\>{:src=\>“arrow\_green.giv”}} in…
> 
> So is there a way to write a test for this? I know I can use an :alt property and test that, but I really would rather test the :src. Any way to get the asset id within the test so I could write:
> 
> assert\_tag :tag =\> “img”, :attributes =\> { :src =\> “arrow\_green.gif” + asset\_id }

Mess around with…

ActionView::Helpers::AssetTagHelper.cache\_asset\_timestamps = false

---

<div class="post-metadata">

**Author:** ![DKDKDK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/46a35a/32.png) [@DKDKDK](https://www.ruby-forum.com/u/DKDKDK)\
**Post date:** [June 28, 2010, 10:58pm UTC](https://www.ruby-forum.com/t/testing-image-tag-src-asset-id-issue/190830/3 "2010-06-28T22:58:44Z")

</div>

DK wrote:

> This seems like it should be real easy to do but I have not found any  
> documentation:
> 
> I have an image tag in a page:
> 
> \<%= image\_tag “arrow\_green.gif”, :alt =\> “image did not load” %\>

Slightly off your question, but…that’s a terrible abuse of the alt  
attribute. It should have text that can take the place of the image in  
non-graphical browsers. “Image die not load” is inappropriate alt  
content and is dealt with by the browser in any case.
