[英]How can I add I18n capabilities to my step definitions in cucumber?
env.rb =>
def setup_language_resources
I18n.load_path = ['features/configuration_resources/english.yml']
case ENV['Language']
when 'english'
I18n.locale = :en
when 'spanish'
I18n.locale = :es
when 'italian'
I18n.locale = :it
else
abort("Incorrect language set, cannot continue the test run: supported are 'english', 'italian' or 'spanish'")
end
end
setup_language_resources
步驟=>
expect(@browser.text.include?(I18N.t('successful-adoption'))).to be true
如何在步驟定義中引用我的I18n.t函數,如何將其傳遞到“世界”中以使其可用?
yml =>
---
en:
successful-adoption: "Thank you for adopting a puppy!"
錯誤是: uninitialized constant I18N (NameError)
只需在hooks @before方法內添加一個實例var。
Before do |scenario|
@locale = I18n
@log = setup_logger("#{scenario.name}")
@log.debug("Starting scenario: #{scenario.name}")
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.