# Assert\_tag not working

**URL:** <https://www.ruby-forum.com/t/assert-tag-not-working/121642>\
**Category:** Rails\
**Created:** [November 29, 2007, 4:43pm UTC](https://www.ruby-forum.com/t/assert-tag-not-working/121642 "2007-11-29T16:43:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [November 29, 2007, 4:43pm UTC](https://www.ruby-forum.com/t/assert-tag-not-working/121642/1 "2007-11-29T16:43:34Z")

</div>

Hi all,  
in a test I’m doing I’m looking for a div of class errorExplanation to  
know if an update passed validation, but even if the rendered html has  
it, as you can see below, the assert\_tag fails. What am I doing wrong?

expected tag, but no tag found matching  
{:attributes=\>{:class=\>“errorExplanation”}, :tag=\>“div”} in:  
"HWait(‘0’);HWait(‘00’);\nif($(‘flashesint’) !=  
undefined){Effect.Fade(‘flashesint’,{duration:  
0.7});Effect.BlindUp(‘flashesint’, {duration:  
0.7});}\nsetTimeout(function() {\n;\n},  
800);\nElement.update(“mac\_address\_number\_1”, "\n\074div  
class=\“errorExplanation\”  
id=\“errorExplanation\”\076\074h2\0761 error prohibited this mac  
address from being saved\074/h2\076\074p\076There were problems with  
the following fields:\074/p\076\074ul\076\074li\076Mac address is  
not a valid MAC Address\074/li\076\074/ul\076\074/div\076  
\n\074form…

Thank you,  
Emanuele.

---

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [November 30, 2007, 9:56am UTC](https://www.ruby-forum.com/t/assert-tag-not-working/121642/2 "2007-11-30T09:56:02Z")

</div>

Really noone has a clue?

---

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [November 30, 2007, 1:11pm UTC](https://www.ruby-forum.com/t/assert-tag-not-working/121642/3 "2007-11-30T13:11:22Z")

</div>

On 29 Nov 2007, at 15:43, Emanuele R. wrote:

> Hi all,  
> in a test I’m doing I’m looking for a div of class errorExplanation to  
> know if an update passed validation, but even if the rendered html has  
> it, as you can see below, the assert\_tag fails. What am I doing wrong?

assert\_tag is quite literally looking for a div tag of that class,  
which your output does not contain. It does contain javascript for  
inserting such a tag, but assert\_tag doesn’t understand that.  
You probably want to use assert\_select\_rjs (I also find the arts  
plugin useful for this sort of stuff)

Fred

---

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [November 30, 2007, 1:27pm UTC](https://www.ruby-forum.com/t/assert-tag-not-working/121642/4 "2007-11-30T13:27:40Z")

</div>

Frederick C. wrote:

> On 29 Nov 2007, at 15:43, Emanuele R. wrote:
> 
> > Hi all,  
> > in a test I’m doing I’m looking for a div of class errorExplanation to  
> > know if an update passed validation, but even if the rendered html has  
> > it, as you can see below, the assert\_tag fails. What am I doing wrong?
> 
> assert\_tag is quite literally looking for a div tag of that class,  
> which your output does not contain. It does contain javascript for  
> inserting such a tag, but assert\_tag doesn’t understand that.  
> You probably want to use assert\_select\_rjs (I also find the arts  
> plugin useful for this sort of stuff)
> 
> Fred

Thank you very much for your answer, I’ ll look into assert\_select\_rjs  
and arts, till now I patched it with a custom assertion that works for  
me:

```
 def assert_validation_success
   assert got_validation_error.nil?, "Not valid!"
 end

 def got_validation_error
   @response.body.inspect.match(/.*errorExplanation.*/)
 end

```

Emanuele.

---

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [July 2, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/assert-tag-not-working/121642/5 "2008-07-02T22:39:37Z")

</div>

I had a problem similar to this and just could not get assert\_tag to  
work,  
but I did not want to use a regex as the order of different attributes  
makes complex testing difficult to maintain.

so after some testing I found that if I replaced the strict  
declaration in the application layout with the transitional one

replace this

with

then it worked just fine.

On Nov 30 2007, 1:27 pm, Emanuele R. \<rails-mailing-l…@andreas-
