I have the following html <p><b>text</b>value</p> 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 <p>. I cannot work out how to check that the two are in the same <p>. 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Any thoughts anyone? Colin On 27 August 2010 22:08, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I have the following html > <p><b>text</b>value</p> > 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 <p>. I cannot work out how to > check that the two are in the same <p>. 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 >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote:> I have the following html > <p><b>text</b>value</p> > 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 <p>. I cannot work out how to > check that the two are in the same <p>. 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 <b> tags. That''s 1990s physical styling. That''s *bad*. You should be using a semantically named <span> instead. But you probably knew that already. Now to your question...I think I''d use assert_select ''p'', :html => ''<b>text</b>value''. Does that help?> > ColinBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 27 August 2010 22:08, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I have the following html > <p><b>text</b>value</p> > 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 <p>. I cannot work out how to > check that the two are in the same <p>. 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 30 August 2010 15:47, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> I have the following html >> <p><b>text</b>value</p> >> 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 <p>. I cannot work out how to >> check that the two are in the same <p>. 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 <b> tags. That''s 1990s physical > styling. That''s *bad*. You should be using a semantically named <span> > 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 => > ''<b>text</b>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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 30 August 2010 16:42, Chris Mear <chrismear-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 27 August 2010 22:08, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> I have the following html >> <p><b>text</b>value</p> >> 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 <p>. I cannot work out how to >> check that the two are in the same <p>. 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" > endI 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 30 August 2010 17:41, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 30 August 2010 16:42, Chris Mear <chrismear-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 27 August 2010 22:08, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> I have the following html >>> <p><b>text</b>value</p> >>> 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 <p>. I cannot work out how to >>> check that the two are in the same <p>. 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 > > 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.For the record, that worked fine. Thanks again Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- <b> tag in HTML 5 (was Re: Re: assert_select for <p><b>text</b>value</p>)
- Strange problem with "and" - "&&"
- why functional test does not get failure?
- after changed the tag i got the same eror
- Rails 3 Active Record query returns "undefined method `loaded?' for #<Array:0x126a4c>"