一直在尝试找出如何编写一个测试,以测试当内容是带有 html 的翻译键时视图是否呈现正确的内容。为了更详细地解释一下,我有这个 rspec 测试:
require 'spec_helper'
describe "application/error_404.html.erb" do
I18n.available_locales.each do |locale|
it "should have 'not found text' in #{locale}" do
I18n.locale = locale
render
rendered.should have_content I18n.t(:not_found_html)
end
end
end
测试它是否:not_found_html
为我可用的每个语言环境呈现。但测试失败,因为它寻找一个没有 html 的字符串:
Failure/Error: rendered.should have_content I18n.t(:not_found_html)
expected there to be content "Could not find the page or item you tried to view.
Please try again and if the problem persists please <a href=\"%{contact_link} \">let us
know</a> so we can fix this."
in
"\n\t\n\t\t\tNot found\n\t\t\n\t\n\t\t\t\n\t\t\t\tCould not find the page or item you tried
to view. Please try again and if the problem persists please let us know so we can fix
this.\n\t\t\t\t\n\t\t\n\t"
我对 Rails 的了解不够多,不知道如何完成这项工作。我想我需要一些方法来渲染 I18n 字符串?对此的任何帮助将不胜感激。