用i18n html键进行rspec牛排验收测试

时间:2013-01-04 19:35:25

标签: ruby-on-rails

如何用rspec牛排宝石测试I18n html键?

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

我总是得到以下:

..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"

有人有想法吗?

我已经尝试过:

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

编辑:如果我包括

include ActionView::Helpers::SanitizeHelper

进入我的功能,我喜欢这样:

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)
一切正常。

您对此解决方案有何看法?我认为似乎有点笨拙..

1 个答案:

答案 0 :(得分:1)

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

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