Search code examples
rubyrubygemscucumbercucumber-jvm

Cucumber: Unable to see methods of a module included in the World?


I'm working with cucumber/ruby and I wanted to create a new module with some methods to use them in my step definitions.

I was reading how to do this here, https://github.com/cucumber/cucumber/wiki/A-Whole-New-World. But when I've tried the following I get an error:

  • create the new module under /root_location/lib/new_module.rb
  • create the module as:

.

module Newmodule
  def here
    puts "here"
  end
end
World(Newmodule)

However, when I then try to use the 'here' method from my steps definition, I just get:

undefined local variable or method `here' for # (NameError)

Any idea what I am doing wrong?


Solution

  • The module needs to be located in features, otherwise it won't be added into World. Cucumber does not look outside of features for anything unless you specifically tell it to.

    Put this code either in features/support or features/step_definitions