我想将我的测试与内化隔离开来。我使用 rails 3.2.8 和 rspec 2.11.1
我把这段代码spec/support/translations.rb
module I18nHelpers
def with_translations(locale, translations)
I18n.backend.store_translations locale, translations
yield
ensure
I18n.reload!
end
结尾
RSpec.configure do |config|
config.include I18nHelpers
end
然后我测试应用程序助手:
describe ApplicationHelper do
context "messages" do
it "show body" do
with_translations :en, navigation: {messages: 'foo'} do
concat messages_navigation
assert_test 'span', 'foo'
end
end
end
end
但是这个测试伴随着消息
Failure/Error: assert_select 'span', text: /foo/
MiniTest::Assertion:
</foo/> expected but was
<"Messages">.
“消息”来自我真实的config/locales/en.yml
我从控制台测试#store_translations,它可以工作。但是当我在帮助模块中将行放在单词p I18n.t(translations.key.first)
之前时ensure
,它会向我显示旧的翻译。
谢谢你的帮助!