lib/calabash/page.rb in calabash-1.9.9.pre3 vs lib/calabash/page.rb in calabash-2.0.0.pre1

- old
+ new

@@ -3,15 +3,48 @@ # For auto-completion include Calabash def self.inherited(subclass) # Define the page into global scope - name = subclass.to_s.split('::').last + full_name = subclass.name - unless Object.const_defined?(name.to_sym) - # We need a unique type for this constant - clz = Class.new(StubPage) - Object.const_set(name.to_sym, clz) + if full_name == 'IOS' || full_name == 'Android' + raise "Invalid page name '#{full_name}'" + end + + os_scope = full_name.split('::').first + + if os_scope == 'IOS' || os_scope == 'Android' + page_name = full_name.split('::', 2).last + + unless Calabash.is_defined?(page_name) + scopes = page_name.split('::') + + previous_scope = '' + + scopes[0..-2].each do |scope| + old_scope = Calabash.recursive_const_get("Object::#{os_scope}#{previous_scope}") + new_scope = Calabash.recursive_const_get("Object#{previous_scope}") + + old_const = old_scope.const_get(scope.to_sym) + + if new_scope.const_defined?(scope.to_sym) + new_scope.send(:remove_const, scope.to_sym) + end + + new_scope.const_set(scope.to_sym, old_const.class.allocate) + + previous_scope << "::#{scope}" + end + + simple_page_name = page_name.split('::').last.to_sym + new_scope = Calabash.recursive_const_get("Object#{previous_scope}") + + unless new_scope.const_defined?(simple_page_name, false) + clz = Class.new(StubPage) + new_scope.const_set(simple_page_name, clz) + end + end end end private_class_method :new