Search code examples
rubyseleniumcapybara

Undefined method 'delegate' for capybara::dsl::module


I have a capybara monkey patch to deal with jquery-ui, which works pretty well running on Ubuntu... although when moving to windows I get the following error (all dependency gems were installed successfully):

Undefined method 'delegate' for capybara::dsl::module

The line of code that this occurs is:

module Capybara::DSL
  delegate :datepick, :datetimepick, :timepick, to: :page
end

any ideas of what this could be? a bit lost of why this error is shown just by switching OS...


Solution

  • In standard ruby delegation is handled by the module Forwardable. You need to require and then extend Forwardable to access these methods like so:

    require 'forwardable'
    module Capybara::DSL
      extend Forwardable
      #notice syntax is accessor, *methods
      def_delegators :page, :datepick, :datetimepick, :timepick
    end
    

    The type of delegation you are trying to use right now is part of active support Module Class. If you would like to use this syntax then do so like this:

    require 'active_support/core_ext/module'
    module Capybara::DSL
      #active_support syntax allows a to: element in the hash to act as the accessor
      delegate :datepick, :datetimepick, :timepick, to: :page
    end