Q:

Cucumber\Ruby\PageObject - Can't call PageObject::PageFactory#visit_page from within my module

I'm automating cucumber acceptance tests using PageObject and I'm currently refactoring navigation methods into modules. I'm leaving the project soon and the developers who are to maintain the code aren't happy about having pages of helper method, and would prefer them in their own namespaces.
To investigate this process, I created a module called Navigation and added a pageobject call to it:
module Navigator

  include PageObject::PageFactory

  def self.send_auth_to_login(user_type)

    visit_page(LoginPage) do |login_page|
      login_page.login_as Users::user_factory(user_type)
    end

  end

end

I called it this way:
Navigator.send_auth_to_login 'admin'

This is the error:
undefined method `visit_page' for Navigator:Module (NoMethodError)

I tried it with an explicit receiver:
PageObject::PageFactory.login_page.login_as Users::user_factory(user_type)

But it doesn't work. I even tried making it a class with class methods 
Can anyone with more PageObject knowledge see what I'm doing wrong here? It works outside the module, not inside it.
Thanks.

A:

I believe you need to extend rather than include the PageFactory - ie you need:
extend PageObject::PageFactory

Ruby Quicktips explains the difference well:

You can either use include or extend to mix in a module’s functionality into a class. The difference is this:

include makes the module’s methods available to the instance of a class, while
extend makes these methods available to the class itself.

In your case, you want the methods available to the module itself, therefore you need to use extend.

