Assert_select <br /> embedded in text

Can someone help with an assert_select problem please?

I have:

some text
some more text

I see how to use assert_select to check that the text in the paragraph is "some textsome more text" and I can check that the paragraph contains a break. I cannot see how to check that the break is at the right point in the text.

Any help will be much appreciated

Colin

Colin L. wrote:
[…]
} I cannot see how to check that the break is at the

right point in the text.

What does the “right point” consist of? In other words, how (English,
not Ruby) would you define the break being at the right point?

Any help will be much appreciated

Colin

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

2009/6/13 Marnen Laibow-Koser [email protected]:

Colin L. wrote:
[…]
} I cannot see how to check that the break is at the

right point in the text.

What does the “right point” consist of? Â In other words, how (English,
not Ruby) would you define the break being at the right point?

Repeating my original post for clarity:

I have:

some text
some more text

The right point for the break is after ‘some text’ and before ‘some more
text’
As I said I can see how to use assert_select to check that the
complete text is there, and how to check that the break is there, but
I do not see how to check that the break is after ‘some text’ and
before ‘some more text’. I am no doubt missing something obvious.
Of course in my real application the text is not as in this simplified
example.

Colin

2009/6/13 Colin L. [email protected]:

Repeating my original post for clarity:

I have:

some text
some more text

The right point for the break is after ‘some text’ and before ‘some more text’
As I said I can see how to use assert_select to check that the
complete text is there, and how to check that the break is there, but
I do not see how to check that the break is after ‘some text’ and
before ‘some more text’. I am no doubt missing something obvious.
Of course in my real application the text is not as in this simplified example.

Perhaps I should clarify further. In my functional test I currently
have something like
assert_select “p”, “some textsome more text” # checks the text is
correct
assert_select “p>br”, 1 # checks p contains br
What I am lacking is a check that the
is in the correct place
in the text.

Colin

2009/6/13 Marnen Laibow-Koser [email protected]:

Colin L. wrote:
[…]

The right point for the break is after ‘some text’ and before ‘some more text’

How about assert_select “p”, /some text.<br[^>]>some more text/m ?

No that doesn’t work. The br tag does not appear in the text for the
p tag. This can be seen from the fact that
assert_select “p”, “some textsome more text”
passes.
I tried it just to check and it said
/some text.<br[^>]>some more text/m expected but was
some textsome more text

BTW, you shouldn’t be using
in the self-closing form unless you’re
generating XHTML (it is not actually valid HTML), and you shouldn’t be
generating XHTML unless you’re serving it with the XHTML MIME type – at
which point IE won’t understand the document! Â So in general, HTML 4 is
the way to go (the html_output plugin will help). Â See the recent thread
where Rimantas convinced me of this (admittedly after some argument from
me).

OK

Colin

Colin L. wrote:
[…]

The right point for the break is after ‘some text’ and before ‘some more text’

How about assert_select “p”, /some text.<br[^>]>some more text/m ?

BTW, you shouldn’t be using
in the self-closing form unless you’re
generating XHTML (it is not actually valid HTML), and you shouldn’t be
generating XHTML unless you’re serving it with the XHTML MIME type – at
which point IE won’t understand the document! So in general, HTML 4 is
the way to go (the html_output plugin will help). See the recent thread
where Rimantas convinced me of this (admittedly after some argument from
me).

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

2009/6/13 Colin L. [email protected]:

p tag. Â This can be seen from the fact that
assert_select “p”, “some textsome more text”
passes.
I tried it just to check and it said
/some text.<br[^>]>some more text/m expected but was
some textsome more text

For anyone coming to this thread without the history I am trying to
use assert_select to verify the html

some text
some more text

I found a solution to this by adding span tags round my text
fragments, so that the html is now

some text
some more text

Then I can test it with assert_select "p>span:first-of-type", "some text" assert_select "p>span:first-of-type+br", 1 assert_select "p>span:nth-of-type(2)", "some more text" This works but feel there must be a better solution than adding extra tags to the html just so that it can be tested.

Colin

2009/6/14 Marnen Laibow-Koser [email protected]:

response.body , or perhaps go for an XPath-based solution (with RSpec,
that would be rspec_hpricot_matchers, but I don’t know if that works
without RSpec).

OK, it looks as if I will just have to accept that it cannot be done
with assert_select.
Many thanks for the help
Colin

Colin L. wrote:
[…]> I found a solution to this by adding span tags round my text

fragments, so that the html is now

some text
some more text

[…]

This works but feel there must be a better solution than adding extra
tags to the html just so that it can be tested.

Indeed. Try using the regexp I gave you as a simple string match on
response.body , or perhaps go for an XPath-based solution (with RSpec,
that would be rspec_hpricot_matchers, but I don’t know if that works
without RSpec).

Colin

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]