Search code examples
rubyrspecrspec-rails

rspec: How to expect that page has the desired html


I have below html which I took from the launched page source.

    <dt title="No. days">No. days:</dt>
    <dd>7</dd>

In my test I have to expect the same html, I tried below

expect(page.html).to include("<dt title=\"No. days\">No. days:</dt><dd>7</dd>")

But got the error. What format exactly I need to write in the include to expect the same html

Thank you in advance


Solution

  • String is not safe HTML.

    expect(page).to have_selector('dt[title="No. days"]', text: "No. days:")
    expect(page).to have_selector('dd', text: "7")