# Assert\_select for \<p\>\<b\>text\</b\>value\</p\>

**URL:** <https://www.ruby-forum.com/t/assert-select-for-p-b-text-b-value-p/194013>\
**Category:** Rails\
**Created:** [August 27, 2010, 11:15pm UTC](https://www.ruby-forum.com/t/assert-select-for-p-b-text-b-value-p/194013 "2010-08-27T23:15:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [August 27, 2010, 11:15pm UTC](https://www.ruby-forum.com/t/assert-select-for-p-b-text-b-value-p/194013/1 "2010-08-27T23:15:34Z")

</div>

I have the following html

**text** value

I can use assert\_select "p\>b", "text" to check the text portion, and assert\_select "p", "value" to check that the value appears in a 

. I cannot work out how to check that the two are in the same

. I have used assert\_select for much more complex tasks but my mind seems to have gone blank and google has not provided an example of this type.

Any help would be much appreciated.

Colin

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [August 30, 2010, 4:40pm UTC](https://www.ruby-forum.com/t/assert-select-for-p-b-text-b-value-p/194013/2 "2010-08-30T16:40:09Z")

</div>

Any thoughts anyone?

Colin

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [August 30, 2010, 4:47pm UTC](https://www.ruby-forum.com/t/assert-select-for-p-b-text-b-value-p/194013/3 "2010-08-30T16:47:21Z")

</div>

Colin L. wrote:

> I have the following html
> 
> **text** value
> 
> I can use assert\_select "p\>b", "text" to check the text portion, and assert\_select "p", "value" to check that the value appears in a 
> 
> . I cannot work out how to check that the two are in the same
> 
> . I have used assert\_select for much more complex tasks but my mind seems to have gone blank and google has not provided an example of this type.
> 
> Any help would be much appreciated.

First off: you shouldn’t ever be using **tags. That’s 1990s physical  
styling. That’s _bad_. You should be using a semantically named   
instead. But you probably knew that already.**

 

Now to your question…I think I’d use assert\_select ‘p’, :html =\>  
‘ **text** value’. Does that help?

> Colin

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [August 30, 2010, 5:45pm UTC](https://www.ruby-forum.com/t/assert-select-for-p-b-text-b-value-p/194013/4 "2010-08-30T17:45:09Z")

</div>

On 27 August 2010 22:08, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have the following html
> 
> **text** value
> 
> I can use assert\_select "p\>b", "text" to check the text portion, and assert\_select "p", "value" to check that the value appears in a 
> 
> . I cannot work out how to check that the two are in the same
> 
> . I have used assert\_select for much more complex tasks but my mind seems to have gone blank and google has not provided an example of this type.

Pass a block to assert\_select, perhaps?

assert\_select “p”, /value/ do  
assert\_select “b”, “text”  
end

Chris

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [August 30, 2010, 6:42pm UTC](https://www.ruby-forum.com/t/assert-select-for-p-b-text-b-value-p/194013/5 "2010-08-30T18:42:32Z")

</div>

On 30 August 2010 15:47, Marnen Laibow-Koser [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > google has not provided an example of this type.
> > 
> > Any help would be much appreciated.
> 
> First off: you shouldn’t ever be using **tags. That’s 1990s physical  
> styling. That’s _bad_. You should be using a semantically named   
> instead. But you probably knew that already.**

 

Yes I know, it was generated by a rails scaffold some years ago if I  
remember correctly. It is a rarely used admin page so I have not got  
round to re-factoring it yet. It is all a matter of priorities of  
course. Also of course this is one case where re-factoring may cause  
existing tests to fail.

> Now to your question…I think I’d use assert\_select ‘p’, :html =\>  
> ‘ **text** value’. Does that help?

Yes of course, I don’t think I have ever had to use :html, it always  
seems like a bit of a cop-out but it should fix my problem.

Many thanks

Colin

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [August 30, 2010, 7:21pm UTC](https://www.ruby-forum.com/t/assert-select-for-p-b-text-b-value-p/194013/6 "2010-08-30T19:21:12Z")

</div>

On 30 August 2010 16:42, Chris M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > google has not provided an example of this type.
> 
> Pass a block to assert\_select, perhaps?
> 
> assert\_select “p”, /value/ do  
> assert\_select “b”, “text”  
> end

I had considered that and decided it would give me problems if there  
were another p with the right value, but without the b text? However,  
having looked at the docs again it should in fact pass all p elements  
with that value to the block, so the inner assert should be satisfied  
if any p with the right value has a matching b. So I think you are  
right, it should work. I will give it a go.

Many thanks

Colin

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [August 31, 2010, 11:03am UTC](https://www.ruby-forum.com/t/assert-select-for-p-b-text-b-value-p/194013/7 "2010-08-31T11:03:12Z")

</div>

On 30 August 2010 17:41, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > much more complex tasks but my mind seems to have gone blank and  
> > > having looked at the docs again it should in fact pass all p elements  
> > > with that value to the block, so the inner assert should be satisfied  
> > > if any p with the right value has a matching b. So I think you are  
> > > right, it should work. I will give it a go.

For the record, that worked fine.

Thanks again

Colin
