# RSpec and Testing for the presence of css class

**URL:** <https://www.ruby-forum.com/t/rspec-and-testing-for-the-presence-of-css-class/152039>\
**Category:** Rails\
**Created:** [October 29, 2008, 12:36pm UTC](https://www.ruby-forum.com/t/rspec-and-testing-for-the-presence-of-css-class/152039 "2008-10-29T12:36:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Armand\_du\_Plessis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Armand\_du\_Plessis](https://www.ruby-forum.com/u/Armand_du_Plessis)\
**Post date:** [October 29, 2008, 12:36pm UTC](https://www.ruby-forum.com/t/rspec-and-testing-for-the-presence-of-css-class/152039/1 "2008-10-29T12:36:05Z")

</div>

Hi there,

Hoping someone can help with this or point out alternative options for  
testing for the presence of a css class on a specific element.

We’re using rspec and I would like to check for the presence of a  
specific css class (‘current’) on an element (link).

response.should have\_tag(‘a#some\_link’)

I was hoping that the have\_tag matcher might have some option to  
specify a class to match but can’t gleam anything from the docs.

Any suggestions would be really welcome?

Armand

---

<div class="post-metadata">

**Author:** ![Armand\_du\_Plessis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Armand\_du\_Plessis](https://www.ruby-forum.com/u/Armand_du_Plessis)\
**Post date:** [October 29, 2008, 12:52pm UTC](https://www.ruby-forum.com/t/rspec-and-testing-for-the-presence-of-css-class/152039/2 "2008-10-29T12:52:32Z")

</div>

We’ve switched away from using current on the element in favour of  
descendent selectors which makes the testing easier as well.

> **[Sliding Doors of CSS, Part II](https://alistapart.com/article/slidingdoors2/)**
>
> In Sliding Doors of CSS Part I, Douglas Bowman introduced a new technique for creating visually stunning interface elements with simple, text-based, semantic markup. In Part II, he pushes the techn…

Cheers,

Armand

---

<div class="post-metadata">

**Author:** ![Armand\_du\_Plessis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Armand\_du\_Plessis](https://www.ruby-forum.com/u/Armand_du_Plessis)\
**Post date:** [October 30, 2008, 8:31am UTC](https://www.ruby-forum.com/t/rspec-and-testing-for-the-presence-of-css-class/152039/3 "2008-10-30T08:31:24Z")

</div>

Thanks Christian. In hindsight that makes perfect sense 🙂

On Oct 29, 8:11 pm, Christian L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Armand\_du\_Plessis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Armand\_du\_Plessis](https://www.ruby-forum.com/u/Armand_du_Plessis)\
**Post date:** [October 29, 2008, 7:12pm UTC](https://www.ruby-forum.com/t/rspec-and-testing-for-the-presence-of-css-class/152039/4 "2008-10-29T19:12:54Z")

</div>

Try:  
have\_tag(‘a.current’)

Christian
