Quazi Rashid Quazi Rashid - 3 months ago 13
Ruby Question

Call EXCEL method from Module

Creating module:

module CF
def work_sheet(excel_doc_name, workbook_name)
dir_to_excel = Dir.pwd + '/lib/config/data/'
read_workbook = RubyXL::Parser.parse("#{dir_to_excel}#{excel_doc_name}")
worksheet = read_workbook["#{workbook_name}"]
end
end


Call this method from module:

Given(/^Excel read$/) do
include CF
work_sheet("Login.xlsx", "Login_info")
end


Error message:

NoMethodError: undefined method `work_sheet' for #<Object:0x442f158>


Please check Screen

Answer

To include the methods of a module in a step definition, you need to add the module to the World.

In your env.rb (or a file required by it) add the following line (after you have required the module file):

World(CF)

You should also remove the include CF line from the step definition.

Comments