从内部和外部访问Ruby Cucumber模块变量?
我有一个Ruby模块,我想用它作为Cucumber步骤定义的助手类。我希望模块包含一个可以从外部(步骤定义)和内部(模块内的方法)访问的类变量。以下是我的模块的简化版本:从内部和外部访问Ruby Cucumber模块变量?,ruby,variables,scope,cucumber,gherkin,Ruby,Variables,Scope,Cucumber,Gherkin,我有一个Ruby模块,我想用它作为Cucumber步骤定义的助手类。我希望模块包含一个可以从外部(步骤定义)和内部(模块内的方法)访问的类变量。以下是我的模块的简化版本: module CalendarHelper def self.calendar_ids ids = ['1', '2', '3', '4'] end def self.fillCalendarFields (browser) calendar_ids.each { |i
module CalendarHelper
def self.calendar_ids
ids = ['1', '2', '3', '4']
end
def self.fillCalendarFields (browser)
calendar_ids.each { |id|
browser.text_field(:id => id).set '2001-01-01'
}
end
end
这里,fillCalendarFields
方法需要能够访问calendar\u id
类变量
这是我希望通过步骤定义实现的:
And /^the calendar fields are filled$/ do
CalendarHelper.fillCalendarFields(@browser)
end
Then /^the calendar fields are cleared$/ do
CalendarHelper.calendar_ids.each { |id|
@browser.text_field(:id => id).set ""
}
end
第一步定义从模块调用fillCalendarFields
方法。第二步定义访问calendar\u id
变量以供自己使用。如何正确地做到这一点,有什么建议吗?提前谢谢
World(CalendarHelper)
我们应该做到这一点。尽管您不再需要通过“CalendarHelper”给他们打电话。这段代码将用您在其中的方法扩展世界。谢谢!这真的很有帮助。我想我只是错过了那一小部分。