2

How I could test I18n html keys with the rspec steak gem?

feature 'about page - not signed in user' do

   background do
     visit '/about'
   end

  scenario 'visit about page' do
   page.should have_content(I18n.t("pages.about.headline_html"))
   page.should have_content(I18n.t("pages.about.body_html"))
  end

end

I always get following:

..FF

Failures:

 1) about page - not signed in user visit about page
 Failure/Error: page.should have_content(I18n.t("pages.about.headline_html"))
   expected there to be content "<h1>About</h1>" in "About"

Anybody an idea?

I already tried:

page.should have_content(I18n.t("pages.about.headline_html").html_safe)

EDIT: If I include

include ActionView::Helpers::SanitizeHelper

into my feature and I do like that:

headline = strip_tags(I18n.t("pages.about.headline_html"))
body = strip_tags(I18n.t("pages.about.body_html"))
page.should have_content(headline)
page.should have_content(body)

everything works.

What do you think about this solution? Seems to be a bit hacky I think..

4

1 回答 1

2

我认为这应该适合你: page.html.should include(I18n.t("pages.about.headline_html"))

类似的问题在这里:Capybara: should have html content

于 2013-12-05T13:56:56.547 回答