Quazi Rashid Quazi Rashid - 1 year ago 120
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}"]

Call this method from module:

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

Error message:

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

Please check Screen

Answer Source

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):


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download