I have a Ruby Module that I want to use as a helper class for Cucumber step definitions. I want the Module to contain a class variable that can be accessed from outside (the step definitions) as well as inside (a method within the module). Here is a simplified version of my module:
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
Here, the fillCalendarFields
method needs to be able to access the calendar_ids
class variable.
This is something I want to accomplish with my step definitions:
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
The first step definition calls the fillCalendarFields
method from the module. The second step definition accesses the calendar_ids
variable for its own use. Any advice on how to properly do this? Thanks in advance.
World(CalendarHelper)
Should do the trick. Though you'll no longer need to call them via "CalendarHelper". What this code will do is extend World with the methods you have in there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.