Skip to content

Instantly share code, notes, and snippets.

@dougvk
Last active December 30, 2015 09:39
Show Gist options
  • Save dougvk/7810988 to your computer and use it in GitHub Desktop.
Save dougvk/7810988 to your computer and use it in GitHub Desktop.
class PageObjectDelegator
include Capybara::DSL
include Rails.application.routes.url_helpers
def initialize(*args)
# Create a `path` => `page object model` hash
@pages = {}
@pages[foo_bar_path] = FooBarPage.new("Foo Bar")
@pages[baz_path] = BazPage.new("Baz")
end
# Send the named route you wish to check that you're on,
# e.g. @page_delegator.on_page :foo_bar.
def on_page?(page)
@pages[send("#{page}_path")].on_page?
end
def method_missing(method, *args)
# If method not found, delegate to corresponding page object model
# based on the current page.
@pages[page.current_path].send(method, *args)
end
end
@dougvk
Copy link
Author

dougvk commented Dec 5, 2013

Now, whenever you need to call your page object, you can use your page delegator to forward the call to the corresponding page object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment