Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从内部和外部访问Ruby Cucumber模块变量?_Ruby_Variables_Scope_Cucumber_Gherkin - Fatal编程技术网

从内部和外部访问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

我有一个Ruby模块,我想用它作为Cucumber步骤定义的助手类。我希望模块包含一个可以从外部(步骤定义)和内部(模块内的方法)访问的类变量。以下是我的模块的简化版本:

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”给他们打电话。这段代码将用您在其中的方法扩展世界。

谢谢!这真的很有帮助。我想我只是错过了那一小部分。