ae_page_objects 0.1.1 → 0.1.2.dt1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ require 'active_support/dependencies'
10
10
  require 'ae_page_objects/version'
11
11
 
12
12
  module AePageObjects
13
+ autoload :Universe, 'ae_page_objects/core/universe'
13
14
  autoload :ConstantResolver, 'ae_page_objects/core/constant_resolver'
14
15
  autoload :DependenciesHook, 'ae_page_objects/core/dependencies_hook'
15
16
  autoload :Installable, 'ae_page_objects/core/installable'
@@ -32,6 +33,7 @@ module AePageObjects
32
33
  autoload :Visitable, 'ae_page_objects/concerns/visitable'
33
34
  end
34
35
 
36
+ autoload :Window, 'ae_page_objects/window'
35
37
  autoload :Node, 'ae_page_objects/node'
36
38
  autoload :Document, 'ae_page_objects/document'
37
39
  autoload :Element, 'ae_page_objects/element'
@@ -7,7 +7,7 @@ module AePageObjects
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  def stale?
10
- @stale
10
+ !!@stale
11
11
  end
12
12
 
13
13
  def node
@@ -3,9 +3,8 @@ module AePageObjects
3
3
  include AePageObjects::Singleton
4
4
 
5
5
  class << self
6
- private :new
7
-
8
6
  attr_accessor :called_from
7
+ protected :called_from=
9
8
 
10
9
  delegate :initialize!, :to => :instance
11
10
  delegate :config, :to => :instance
@@ -18,34 +17,64 @@ module AePageObjects
18
17
  File.dirname(call_stack.detect { |p| p !~ %r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack] })
19
18
  end
20
19
 
21
- application_class.parent.send(:include, ConstantResolver)
22
- application_class.parent.page_objects_application = application_class
20
+ application_class.universe.send(:include, Universe)
21
+ application_class.universe.page_objects_application_class = application_class
22
+ end
23
+
24
+ def universe
25
+ parent
26
+ end
27
+
28
+ def from(from_mod)
29
+ until from_mod == Object
30
+ if from_mod < AePageObjects::Universe
31
+ return from_mod.page_objects_application_class.instance
32
+ end
33
+
34
+ from_mod = from_mod.parent
35
+ end
36
+
37
+ nil
23
38
  end
24
39
  end
25
40
 
26
- delegate :root_path, :to => :config
41
+ delegate :universe, :to => 'self.class'
27
42
 
43
+ delegate :paths, :to => :config
28
44
  delegate :router, :to => :config
45
+
29
46
  delegate :path_recognizes_url?, :to => :router
30
- delegate :generate_path, :to => :router
47
+ delegate :generate_path, :to => :router
31
48
 
32
49
  def config
33
50
  @config ||= Configuration.new(self)
34
51
  end
35
52
 
36
53
  def initialize!
37
- ActiveSupport::Dependencies.autoload_paths.unshift(root_path)
54
+ ActiveSupport::Dependencies.autoload_paths.unshift(*paths)
38
55
  eager_load!
39
56
  end
40
57
 
58
+ def resolve_constant(from_mod, const_name)
59
+ resolver = ConstantResolver.new(self, from_mod, const_name)
60
+
61
+ resolved = nil
62
+ paths.each do |path|
63
+ break if resolved = resolver.load_constant_from_path(path)
64
+ end
65
+ resolved
66
+ end
67
+
41
68
  private
42
69
 
43
70
  def eager_load!
44
- matcher = /\A#{Regexp.escape(root_path)}\/(.*)\.rb\Z/
71
+ paths.each do |path|
72
+ matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/
45
73
 
46
- Dir.glob("#{root_path}/**/*.rb").sort.each do |file|
47
- dependency_name = file.sub(matcher, '\1')
48
- require_dependency dependency_name
74
+ Dir.glob("#{path}/**/*.rb").sort.each do |file|
75
+ dependency_name = file.sub(matcher, '\1')
76
+ require_dependency dependency_name
77
+ end
49
78
  end
50
79
  end
51
80
  end
@@ -1,10 +1,10 @@
1
1
  module AePageObjects
2
2
  class Configuration
3
- attr_accessor :router, :root_path
3
+ attr_accessor :router, :paths
4
4
 
5
5
  def initialize(application)
6
6
  @application = application
7
- @root_path = application.class.called_from
7
+ @paths = [application.class.called_from]
8
8
  end
9
9
 
10
10
  def router
@@ -1,42 +1,38 @@
1
1
  module AePageObjects
2
- module ConstantResolver
3
- extend ActiveSupport::Concern
2
+ class ConstantResolver
3
+ def initialize(application, from_mod, const_name)
4
+ @application = application
5
+ @from_mod = from_mod
6
+ @const_name = const_name
4
7
 
5
- included do
6
- class << self
7
- attr_accessor :page_objects_application
8
- end
8
+ @path_for_constant = path_for_constant
9
9
  end
10
10
 
11
- module ClassMethods
11
+ def load_constant_from_path(path)
12
+ file_path = File.join(path, "#{@path_for_constant}.rb").sub(/(\.rb)?$/, ".rb")
13
+
14
+ if File.file?(file_path) && ! ActiveSupport::Dependencies.loaded.include?(File.expand_path(file_path))
15
+ ActiveSupport::Dependencies.require_or_load file_path
12
16
 
13
- def const_name_for(from_mod, const_name)
14
- name_within_universe = ""
15
- if self != from_mod
16
- name_within_universe = from_mod.name.split("#{self.name}::")[1]
17
+ unless ActiveSupport::Dependencies.local_const_defined?(@from_mod, @const_name)
18
+ qualified_name = ActiveSupport::Dependencies.qualified_name_for(@from_mod, @const_name)
19
+ raise LoadError, "Expected #{@file_path} to define #{qualified_name}"
17
20
  end
18
21
 
19
- name_within_universe += "::#{const_name}"
22
+ @from_mod.const_get(@const_name)
20
23
  end
21
-
22
- def load_missing_page_objects_constant(from_mod, const_name)
23
- path_for_constant = self.const_name_for(from_mod, const_name).underscore
24
-
25
- file_path = File.join(page_objects_application.instance.root_path, "#{path_for_constant}.rb").sub(/(\.rb)?$/, ".rb")
26
-
27
- if File.file?(file_path) && ! ActiveSupport::Dependencies.loaded.include?(File.expand_path(file_path))
28
- ActiveSupport::Dependencies.require_or_load file_path
24
+ end
29
25
 
30
- unless ActiveSupport::Dependencies.local_const_defined?(from_mod, const_name)
31
- qualified_name = ActiveSupport::Dependencies.qualified_name_for(from_mod, const_name)
32
- raise LoadError, "Expected #{file_path} to define #{qualified_name}"
33
- end
26
+ private
34
27
 
35
- from_mod.const_get(const_name)
36
- else
37
- nil
38
- end
28
+ def path_for_constant
29
+ name_within_universe = ""
30
+ if @application.universe != @from_mod
31
+ name_within_universe = @from_mod.name.split("#{@application.universe.name}::")[1]
39
32
  end
33
+
34
+ name_within_universe += "::#{@const_name}"
35
+ name_within_universe.underscore
40
36
  end
41
37
  end
42
38
  end
@@ -1,21 +1,7 @@
1
1
  module AePageObjects
2
2
  module DependenciesHook
3
-
4
- def self.containing_page_object_universe(from_mod)
5
- until from_mod == Object
6
- if from_mod < AePageObjects::ConstantResolver
7
- return from_mod
8
- end
9
-
10
- from_mod = from_mod.parent
11
- end
12
-
13
- nil
14
- end
15
-
16
3
  def load_missing_constant(from_mod, const_name)
17
- page_objects = DependenciesHook.containing_page_object_universe(from_mod)
18
- page_objects && page_objects.load_missing_page_objects_constant(from_mod, const_name) || super
4
+ Application.from(from_mod).try(:resolve_constant, from_mod, const_name) || super
19
5
  end
20
6
  end
21
7
  end
@@ -2,6 +2,12 @@ module AePageObjects
2
2
  module Singleton
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ included do
6
+ class << self
7
+ private :new
8
+ end
9
+ end
10
+
5
11
  module ClassMethods
6
12
  def instance
7
13
  @instance ||= new
@@ -0,0 +1,11 @@
1
+ module AePageObjects
2
+ module Universe
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ class << self
7
+ attr_accessor :page_objects_application_class
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,18 +1,24 @@
1
1
  module AePageObjects
2
2
  class Document < Node
3
3
  include Concerns::Visitable
4
+
5
+ attr_reader :window
6
+
7
+ def initialize
8
+ super(Capybara.current_session)
9
+
10
+ @window = Window.current
11
+ @window.current_document = self
12
+ end
4
13
 
5
14
  def document
6
15
  self
7
16
  end
8
17
 
9
18
  class << self
10
- private
19
+ private
11
20
  def application
12
- @application ||= begin
13
- universe = AePageObjects::DependenciesHook.containing_page_object_universe(self)
14
- "#{universe.name}::Application".constantize.instance
15
- end
21
+ @application ||= AePageObjects::Application.from(self)
16
22
  end
17
23
  end
18
24
  end
@@ -7,7 +7,7 @@ module AePageObjects
7
7
  include Dsl::Collection
8
8
  include Dsl::FormFor
9
9
 
10
- def initialize(capybara_node = Capybara.current_session)
10
+ def initialize(capybara_node)
11
11
  @node = capybara_node
12
12
  end
13
13
 
@@ -1,3 +1,3 @@
1
1
  module AePageObjects
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2.dt1'.freeze
3
3
  end
@@ -0,0 +1,51 @@
1
+ module AePageObjects
2
+ class Window
3
+ class << self
4
+ def all
5
+ @all ||= {}
6
+ end
7
+
8
+ def current
9
+ current_handle = Capybara.current_session.driver.browser.window_handle
10
+
11
+ window = all.keys.find do |window|
12
+ window.handle == current_handle
13
+ end
14
+
15
+ unless window
16
+ window = new(current_handle)
17
+ all[window] = window
18
+ end
19
+
20
+ window
21
+ end
22
+ end
23
+
24
+ attr_reader :current_document, :handle
25
+
26
+ def initialize(handle)
27
+ @handle = handle
28
+ @current_document = nil
29
+
30
+ self.class.all[self] = self
31
+ end
32
+
33
+ def current_document=(document)
34
+ @current_document.send(:stale!) if @current_document
35
+ @current_document = document
36
+ end
37
+
38
+ def switch_to
39
+ Capybara.current_session.driver.browser.switch_to(handle)
40
+ current_document
41
+ end
42
+
43
+ def close
44
+ self.current_document = nil
45
+
46
+ Capybara.current_session.driver.close
47
+
48
+ self.class.all.delete(self)
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_page_objects
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ hash: 631108069
5
+ prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
+ - 2
10
+ - dt
9
11
  - 1
10
- version: 0.1.1
12
+ version: 0.1.2.dt1
11
13
  platform: ruby
12
14
  authors:
13
15
  - Donnie Tognazzini
@@ -15,7 +17,7 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2013-06-03 00:00:00 Z
20
+ date: 2013-06-12 00:00:00 Z
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
23
  type: :runtime
@@ -48,10 +50,26 @@ dependencies:
48
50
  version: "1.1"
49
51
  requirement: *id002
50
52
  prerelease: false
53
+ - !ruby/object:Gem::Dependency
54
+ type: :runtime
55
+ name: nokogiri
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 17
62
+ segments:
63
+ - 1
64
+ - 5
65
+ - 9
66
+ version: 1.5.9
67
+ requirement: *id003
68
+ prerelease: false
51
69
  - !ruby/object:Gem::Dependency
52
70
  type: :development
53
71
  name: appraisal
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
55
73
  none: false
56
74
  requirements:
57
75
  - - ~>
@@ -62,12 +80,12 @@ dependencies:
62
80
  - 5
63
81
  - 1
64
82
  version: 0.5.1
65
- requirement: *id003
83
+ requirement: *id004
66
84
  prerelease: false
67
85
  - !ruby/object:Gem::Dependency
68
86
  type: :development
69
87
  name: mocha
70
- version_requirements: &id004 !ruby/object:Gem::Requirement
88
+ version_requirements: &id005 !ruby/object:Gem::Requirement
71
89
  none: false
72
90
  requirements:
73
91
  - - "="
@@ -78,12 +96,12 @@ dependencies:
78
96
  - 13
79
97
  - 3
80
98
  version: 0.13.3
81
- requirement: *id004
99
+ requirement: *id005
82
100
  prerelease: false
83
101
  - !ruby/object:Gem::Dependency
84
102
  type: :development
85
103
  name: selenium-webdriver
86
- version_requirements: &id005 !ruby/object:Gem::Requirement
104
+ version_requirements: &id006 !ruby/object:Gem::Requirement
87
105
  none: false
88
106
  requirements:
89
107
  - - ">="
@@ -92,7 +110,7 @@ dependencies:
92
110
  segments:
93
111
  - 0
94
112
  version: "0"
95
- requirement: *id005
113
+ requirement: *id006
96
114
  prerelease: false
97
115
  description: Capybara Page Objects pattern
98
116
  email:
@@ -119,6 +137,7 @@ files:
119
137
  - lib/ae_page_objects/core/internal_helpers.rb
120
138
  - lib/ae_page_objects/core/rake_router.rb
121
139
  - lib/ae_page_objects/core/singleton.rb
140
+ - lib/ae_page_objects/core/universe.rb
122
141
  - lib/ae_page_objects/document.rb
123
142
  - lib/ae_page_objects/element.rb
124
143
  - lib/ae_page_objects/element_proxy.rb
@@ -128,6 +147,7 @@ files:
128
147
  - lib/ae_page_objects/elements/select.rb
129
148
  - lib/ae_page_objects/node.rb
130
149
  - lib/ae_page_objects/version.rb
150
+ - lib/ae_page_objects/window.rb
131
151
  homepage: http://github.com/appfolio/ae_page_objects
132
152
  licenses:
133
153
  - MIT