RSpecで一時的に言語設定を変える
i18nの機能に以下のメソッドが定義されてることを知った。
# Executes block with given I18n.locale set.
def_with\_locale_(_tmp\_locale_ = nil)
if_tmp\_locale
current\_locale_ = self.locale
self.locale =_tmp\_locale_
end
yield
ensure
self.locale =_current\_locale_ if_tmp\_locale_
end
なのでこんなふうにかけた。
it '意図した英語の値が返る' do
I18n.with_locale(:en) do
expect(object.start_string).to eq("Early 10/2018")
end
end
よっしゃ。