[英]How can I add I18n capabilities to my step definitions in cucumber?
env.rb => 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
steps => 步骤=>
expect(@browser.text.include?(I18N.t('successful-adoption'))).to be true
How can i reference my I18n.t function inside the step definition, how should i pass it into the "world" to have it available there? 如何在步骤定义中引用我的I18n.t函数,如何将其传递到“世界”中以使其可用?
yml => yml =>
---
en:
successful-adoption: "Thank you for adopting a puppy!"
Error is: uninitialized constant I18N (NameError)
错误是: uninitialized constant I18N (NameError)
simply just add an instance var inside the hooks @before method. 只需在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.