Skip to content

Instantly share code, notes, and snippets.

@leviwilson
Last active December 17, 2015 20:49
Show Gist options
  • Save leviwilson/5670143 to your computer and use it in GitHub Desktop.
Save leviwilson/5670143 to your computer and use it in GitHub Desktop.
Using gametel / mohawk within the same test suite
require 'page_navigation'
module Gametel
module Navigation
include PageNavigation
def on(cls, &block)
p "Gametel::PageNavigation - #{cls}"
end
end
end
# include Mohawk 2nd, to make it the default one in the suite
module Mohawk
module Navigation
include PageNavigation
def on(cls, &block)
p "Mohawk::PageNavigation - #{cls}"
end
end
end
class Foo; end
class Bar; end
# define routes for both
Mohawk::Navigation.routes = { :default => [[Foo, :to_s], [Bar, :to_s]] }
Gametel::Navigation.routes = { :default => [[Bar, :to_s], [Foo, :to_s]] }
# use Mohawk as the default navigation
extend Mohawk::Navigation
class GametelNavigation
extend Gametel::Navigation
class << self
alias :orig_navigate_to :navigate_to
# use Gametel::Navigation, but restore Mohawk::Navigation when done
def navigate_to(*args)
orig_cls = PageNavigation.cls
PageNavigation.instance_variable_set(:@cls, Gametel::Navigation)
result = orig_navigate_to(*args)
PageNavigation.instance_variable_set(:@cls, orig_cls)
result
end
end
end
navigate_to Bar # Mohawk
GametelNavigation.navigate_to Foo # Gametel
navigate_to Bar # restored to Mohawk again
# Example output:
#
# "Mohawk::PageNavigation - Foo"
# "Mohawk::PageNavigation - Bar"
# "Gametel::PageNavigation - Bar"
# "Gametel::PageNavigation - Foo"
# "Mohawk::PageNavigation - Foo"
# "Mohawk::PageNavigation - Bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment