ae_page_objects 0.0.1.beta.6.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,13 +32,11 @@ module AePageObjects
32
32
 
33
33
  def can_load_from_current_url?
34
34
  return true if paths.empty?
35
-
36
- Capybara.current_session.wait_until do
37
- url = current_url_without_params
38
-
39
- paths.any? do |path|
40
- application.path_recognizes_url?(path, url)
41
- end
35
+
36
+ url = current_url_without_params
37
+
38
+ paths.any? do |path|
39
+ application.path_recognizes_url?(path, url)
42
40
  end
43
41
  end
44
42
 
@@ -1,61 +1,42 @@
1
- require "active_support/dependencies"
2
-
3
1
  module AePageObjects
4
2
  class Application
5
3
  include Configurable
6
4
 
7
5
  class << self
8
- attr_accessor :called_from
9
6
  private :new
10
7
 
11
- def inherited(base)
8
+ delegate :initialize!, :to => :instance
9
+
10
+ def inherited(application_class)
12
11
  super
13
-
14
- base.called_from = begin
15
- call_stack = caller.map { |p| p.sub(/:\d+.*/, '') }
16
- File.dirname(call_stack.detect { |p| p !~ %r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack] })
17
- end
18
-
19
- base.parent.send(:include, ConstantResolver)
20
- end
21
-
22
- def initialize!
23
- instance.initialize!
12
+ application_class.parent.send(:include, ConstantResolver)
24
13
  end
25
14
  end
26
-
15
+
16
+ delegate :router, :to => :config
17
+ delegate :path_recognizes_url?, :to => :router
18
+ delegate :generate_path, :to => :router
19
+
27
20
  def initialize
28
- set_autoload_paths
21
+ ActiveSupport::Dependencies.autoload_paths.unshift(*all_autoload_paths)
22
+
23
+ # Freeze so future modifications will fail rather than do nothing mysteriously
24
+ config.eager_load_paths.freeze
29
25
  end
30
26
 
31
27
  def config
32
- @config ||= Configuration.new(self, find_root_with_flag("config.ru", Dir.pwd))
28
+ @config ||= Configuration.new(self)
33
29
  end
34
30
 
35
31
  def initialize!
36
32
  eager_load!
37
33
  end
38
-
39
- delegate :path_recognizes_url?, :to => :router
40
- delegate :generate_path, :to => :router
41
-
34
+
42
35
  def all_autoload_paths
43
- @all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths).uniq
44
- end
45
-
46
- private
47
-
48
- def router
49
- @router ||= config.router
36
+ @all_autoload_paths ||= config.eager_load_paths.uniq
50
37
  end
51
-
52
- def set_autoload_paths
53
- ActiveSupport::Dependencies.autoload_paths.unshift(*all_autoload_paths)
54
38
 
55
- # Freeze so future modifications will fail rather than do nothing mysteriously
56
- config.autoload_paths.freeze
57
- config.eager_load_paths.freeze
58
- end
39
+ private
59
40
 
60
41
  def eager_load!
61
42
  config.eager_load_paths.each do |load_path|
@@ -67,19 +48,5 @@ module AePageObjects
67
48
  end
68
49
  end
69
50
  end
70
-
71
- def find_root_with_flag(flag, default=nil)
72
- root_path = self.class.called_from
73
-
74
- while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
75
- parent = File.dirname(root_path)
76
- root_path = parent != root_path && parent
77
- end
78
-
79
- root = File.exist?("#{root_path}/#{flag}") ? root_path : default
80
- raise "Could not find root path for #{self}" unless root
81
-
82
- Pathname.new(root).realpath
83
- end
84
51
  end
85
52
  end
@@ -11,6 +11,7 @@ module AePageObjects
11
11
  return true if route.name.to_s == path.to_s
12
12
  end
13
13
  end
14
+ false
14
15
  end
15
16
  end
16
17
 
@@ -1,28 +1,13 @@
1
- require 'rails/paths'
2
-
3
1
  module AePageObjects
4
2
  class Configuration
5
3
  attr_writer :router
6
4
 
7
- def initialize(application, root)
5
+ def initialize(application)
8
6
  @application = application
9
- @root = root
10
7
  end
11
8
 
12
- def paths
13
- @paths ||= begin
14
- paths = Rails::Paths::Root.new(@root)
15
- paths.add "test/page_objects", :eager_load => true
16
- paths
17
- end
18
- end
19
-
20
9
  def eager_load_paths
21
- @eager_load_paths ||= paths.eager_load
22
- end
23
-
24
- def autoload_paths
25
- @autoload_paths ||= paths.autoload_paths
10
+ @eager_load_paths ||= ["test/page_objects"]
26
11
  end
27
12
 
28
13
  def router
@@ -11,74 +11,82 @@ module AePageObjects
11
11
  # collection. collection() defines a method on the class that returns an instance of a collection
12
12
  # class which contains instances of the collection's item class.
13
13
  #
14
- # Supported signatures are described below.
15
- #
16
- # ------------------------------------------------
17
- # Signature: (:is, no :contains, no block)
18
- #
19
- # collection :addresses, :is => AddressList
20
- #
21
- # Collection class: AddressList
22
- # Item class: AddressList.item_class
23
- #
24
- # ------------------------------------------------
25
- # Signature: (no :is, :contains, no block)
26
- #
27
- # collection :addresses, :contains => Address
28
- #
29
- # Collection class: one-off subclass of ::AePageObjects::Collection
30
- # Item class: Address
31
- #
14
+ # Supported signatures are described below.
15
+ #
32
16
  # ------------------------------------------------
33
- # Signature: (:is, :contains, no block)
34
- #
35
- # collection :addresses, :is => AddressList, :contains => ExtendedAddress
36
- #
37
- # Collection class: one-off subclass ofAddressList
38
- # Item class: ExtendedAddress
39
- #
17
+ # Signature: (no :is, no :contains, no block)
18
+ #
19
+ # collection :addresses
20
+ #
21
+ # Collection class: ::AePageObjects::Collection
22
+ # Item class: ::AePageObjects::Element
23
+ #
40
24
  # ------------------------------------------------
41
25
  # Signature: (no :is, no :contains, block)
42
- #
26
+ #
43
27
  # collection :addresses do
44
28
  # element :city
45
29
  # element :state
46
30
  # end
47
- #
31
+ #
48
32
  # Collection class: one-off subclass of ::AePageObjects::Collection
49
33
  # Item class: one-off subclass of ::AePageObjects::Element
50
34
  # Methods defined on item class:
51
35
  # city() # -> instance of ::AePageObjects::Element
52
36
  # state() # -> instance of ::AePageObjects::Element
53
- #
37
+ #
54
38
  # ------------------------------------------------
55
- # Signature: (:is, no :contains, block)
56
- #
57
- # collection :addresses, :is => AddressList do
39
+ # Signature: (no :is, :contains, no block)
40
+ #
41
+ # collection :addresses, :contains => Address
42
+ #
43
+ # Collection class: one-off subclass of ::AePageObjects::Collection
44
+ # Item class: Address
45
+ #
46
+ # ------------------------------------------------
47
+ # Signature: (no :is, :contains, block)
48
+ #
49
+ # collection :addresses, :contains => Address do
58
50
  # element :longitude
59
51
  # element :latitude
60
52
  # end
61
- #
62
- # Collection class: one-off subclass of AddressList
63
- # Item class: one-off subclass of AddressList.item_class
53
+ #
54
+ # Collection class: one-off subclass of ::AePageObjects::Collection element
55
+ # Item class: one-off subclass of Address
64
56
  # Methods defined on item class:
65
57
  # longitude() # -> instance of ::AePageObjects::Element
66
58
  # latitude() # -> instance of ::AePageObjects::Element
67
- #
59
+ #
68
60
  # ------------------------------------------------
69
- # Signature: (no :is, :contains, block)
70
- #
71
- # collection :addresses, :contains => Address do
61
+ # Signature: (:is, no :contains, no block)
62
+ #
63
+ # collection :addresses, :is => AddressList
64
+ #
65
+ # Collection class: AddressList
66
+ # Item class: AddressList.item_class
67
+ #
68
+ # ------------------------------------------------
69
+ # Signature: (:is, no :contains, block)
70
+ #
71
+ # collection :addresses, :is => AddressList do
72
72
  # element :longitude
73
73
  # element :latitude
74
74
  # end
75
- #
76
- # Collection class: one-off subclass of ::AePageObjects::Collection element
77
- # Item class: one-off subclass of Address
75
+ #
76
+ # Collection class: one-off subclass of AddressList
77
+ # Item class: one-off subclass of AddressList.item_class
78
78
  # Methods defined on item class:
79
79
  # longitude() # -> instance of ::AePageObjects::Element
80
80
  # latitude() # -> instance of ::AePageObjects::Element
81
+ #
82
+ # ------------------------------------------------
83
+ # Signature: (:is, :contains, no block)
81
84
  #
85
+ # collection :addresses, :is => AddressList, :contains => ExtendedAddress
86
+ #
87
+ # Collection class: one-off subclass ofAddressList
88
+ # Item class: ExtendedAddress
89
+ #
82
90
  # ------------------------------------------------
83
91
  # Signature: (:is, :contains, block)
84
92
  #
@@ -111,8 +119,6 @@ module AePageObjects
111
119
  ensure_class_for_param!(:is, options[:is], ::AePageObjects::Collection)
112
120
  else
113
121
  options[:is] = ::AePageObjects::Collection
114
-
115
- raise ArgumentError, "Must specify either a block or a :contains option." if options[:contains].blank? && block.blank?
116
122
  end
117
123
 
118
124
  item_class = options.delete(:contains) || options[:is].item_class
@@ -16,13 +16,15 @@ module AePageObjects
16
16
  end
17
17
 
18
18
  def element(name, options = {}, &block)
19
- options = options.dup
19
+ options = options.dup
20
+ options[:name] ||= name
21
+
20
22
  klass = field_klass(options, &block)
21
23
 
22
24
  self.element_attributes[name.to_sym] = klass
23
25
 
24
26
  define_method name do |&block|
25
- ElementProxy.new(klass, self, name, options, &block)
27
+ ElementProxy.new(klass, self, options, &block)
26
28
  end
27
29
 
28
30
  klass
@@ -92,8 +92,10 @@ module AePageObjects
92
92
 
93
93
  class Param < Struct.new(:name, :optional)
94
94
  include Comparable
95
-
96
- alias :optional? :optional
95
+
96
+ def optional?
97
+ optional
98
+ end
97
99
 
98
100
  def <=>(other)
99
101
  name.to_s <=> other.name.to_s
@@ -1,14 +1,23 @@
1
1
  module AePageObjects
2
2
  class Element < Node
3
- attr_reader :parent, :default_name
3
+ attr_reader :parent
4
4
 
5
- def initialize(parent, name, options_or_locator = {})
5
+ class << self
6
+ def new(*args)
7
+ super(*args).tap do |me|
8
+ yield me if block_given?
9
+ end
10
+ end
11
+ end
12
+
13
+ def initialize(parent, options_or_locator = {})
6
14
  @parent = parent
7
- @default_name = name.to_s
8
15
  @locator = nil
9
16
  @name = nil
10
17
 
11
18
  configure(parse_options(options_or_locator))
19
+
20
+ raise ArgumentError, ":name or :locator is required" unless @name || @locator
12
21
 
13
22
  @locator ||= default_locator
14
23
 
@@ -26,26 +35,30 @@ module AePageObjects
26
35
  node
27
36
  end
28
37
  end
29
-
38
+
30
39
  def __full_name__
31
40
  if parent.respond_to?(:__full_name__)
32
- "#{parent.__full_name__}_#{__name__}"
41
+ [ parent.__full_name__, __name__ ].compact.join('_')
33
42
  else
34
43
  __name__
35
44
  end
36
45
  end
37
-
38
- alias_method :full_name, :__full_name__
39
-
46
+
47
+ def full_name
48
+ __full_name__
49
+ end
50
+
40
51
  def __name__
41
- @name || default_name
52
+ @name
53
+ end
54
+
55
+ def name
56
+ __name__
42
57
  end
43
-
44
- alias_method :name, :__name__
45
58
 
46
59
  def to_s
47
60
  super.tap do |str|
48
- str << "#name:<#{__name__}>"
61
+ str << "@name:<#{@name}>; #@locator:<#{@locator}>"
49
62
  end
50
63
  end
51
64
 
@@ -30,14 +30,28 @@ module AePageObjects
30
30
  !!presence.try(:visible?)
31
31
  end
32
32
 
33
+ def not_visible?
34
+ Capybara.current_session.wait_until do
35
+ Capybara.using_wait_time(0) do
36
+ ! visible?
37
+ end
38
+ end
39
+ rescue Capybara::TimeoutError
40
+ false
41
+ end
42
+
33
43
  def present?
34
44
  presence.present?
35
45
  end
36
46
 
37
- def not_present?(timeout = 0)
38
- Capybara.using_wait_time(timeout) do
39
- ! present?
47
+ def not_present?
48
+ Capybara.current_session.wait_until do
49
+ Capybara.using_wait_time(0) do
50
+ ! present?
51
+ end
40
52
  end
53
+ rescue Capybara::TimeoutError
54
+ false
41
55
  end
42
56
 
43
57
  def presence
@@ -49,7 +63,10 @@ module AePageObjects
49
63
  def is_a?(type)
50
64
  type == @element_class || type == ElementProxy
51
65
  end
52
- alias_method :kind_of?, :is_a?
66
+
67
+ def kind_of?(type)
68
+ is_a?(type)
69
+ end
53
70
 
54
71
  def method_missing(name, *args, &block)
55
72
  if name == "class"
@@ -7,11 +7,13 @@ module AePageObjects
7
7
  if index >= size || index < 0
8
8
  nil
9
9
  else
10
- self.item_class.new(self, index, [:xpath, "#{row_xpath}[#{index + 1}]"], &block)
10
+ self.item_class.new(self, :name => index, :locator => [:xpath, "#{row_xpath}[#{index + 1}]"], &block)
11
11
  end
12
12
  end
13
-
14
- alias_method :[], :at
13
+
14
+ def [](index, &block)
15
+ at(index, &block)
16
+ end
15
17
 
16
18
  def each(&block)
17
19
  (0..(size - 1)).each do |index|
@@ -56,12 +56,6 @@ module AePageObjects
56
56
  klass.class_eval(&block) if block
57
57
  klass
58
58
  end
59
-
60
- def new(*args)
61
- super(*args).tap do |me|
62
- yield me if block_given?
63
- end
64
- end
65
59
  end
66
60
  end
67
61
 
@@ -1,3 +1,3 @@
1
1
  module AePageObjects
2
- VERSION = '0.0.1.beta.6.0.0'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,17 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_page_objects
3
3
  version: !ruby/object:Gem::Version
4
- hash: -9661606936
5
- prerelease: 6
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- - beta
11
- - 6
12
- - 0
13
9
  - 0
14
- version: 0.0.1.beta.6.0.0
10
+ version: 0.1.0
15
11
  platform: ruby
16
12
  authors:
17
13
  - Donnie Tognazzini
@@ -19,12 +15,12 @@ autorequire:
19
15
  bindir: bin
20
16
  cert_chain: []
21
17
 
22
- date: 2013-01-08 00:00:00 Z
18
+ date: 2013-05-24 00:00:00 Z
23
19
  dependencies:
24
20
  - !ruby/object:Gem::Dependency
21
+ type: :runtime
25
22
  name: activesupport
26
- prerelease: false
27
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
28
24
  none: false
29
25
  requirements:
30
26
  - - ">="
@@ -35,28 +31,12 @@ dependencies:
35
31
  - 0
36
32
  - 0
37
33
  version: 3.0.0
38
- type: :runtime
39
- version_requirements: *id001
40
- - !ruby/object:Gem::Dependency
41
- name: railties
34
+ requirement: *id001
42
35
  prerelease: false
43
- requirement: &id002 !ruby/object:Gem::Requirement
44
- none: false
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- hash: 7
49
- segments:
50
- - 3
51
- - 0
52
- - 0
53
- version: 3.0.0
54
- type: :runtime
55
- version_requirements: *id002
56
36
  - !ruby/object:Gem::Dependency
37
+ type: :runtime
57
38
  name: capybara
58
- prerelease: false
59
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
60
40
  none: false
61
41
  requirements:
62
42
  - - ~>
@@ -66,12 +46,12 @@ dependencies:
66
46
  - 1
67
47
  - 1
68
48
  version: "1.1"
69
- type: :runtime
70
- version_requirements: *id003
49
+ requirement: *id002
50
+ prerelease: false
71
51
  - !ruby/object:Gem::Dependency
52
+ type: :development
72
53
  name: appraisal
73
- prerelease: false
74
- requirement: &id004 !ruby/object:Gem::Requirement
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
75
55
  none: false
76
56
  requirements:
77
57
  - - ~>
@@ -82,28 +62,28 @@ dependencies:
82
62
  - 5
83
63
  - 1
84
64
  version: 0.5.1
85
- type: :development
86
- version_requirements: *id004
65
+ requirement: *id003
66
+ prerelease: false
87
67
  - !ruby/object:Gem::Dependency
68
+ type: :development
88
69
  name: mocha
89
- prerelease: false
90
- requirement: &id005 !ruby/object:Gem::Requirement
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
91
71
  none: false
92
72
  requirements:
93
73
  - - "="
94
74
  - !ruby/object:Gem::Version
95
- hash: 43
75
+ hash: 45
96
76
  segments:
97
77
  - 0
98
- - 9
99
- - 8
100
- version: 0.9.8
101
- type: :development
102
- version_requirements: *id005
78
+ - 13
79
+ - 3
80
+ version: 0.13.3
81
+ requirement: *id004
82
+ prerelease: false
103
83
  - !ruby/object:Gem::Dependency
84
+ type: :development
104
85
  name: selenium-webdriver
105
- prerelease: false
106
- requirement: &id006 !ruby/object:Gem::Requirement
86
+ version_requirements: &id005 !ruby/object:Gem::Requirement
107
87
  none: false
108
88
  requirements:
109
89
  - - ">="
@@ -112,8 +92,8 @@ dependencies:
112
92
  segments:
113
93
  - 0
114
94
  version: "0"
115
- type: :development
116
- version_requirements: *id006
95
+ requirement: *id005
96
+ prerelease: false
117
97
  description: Capybara Page Objects pattern
118
98
  email:
119
99
  - engineering@appfolio.com
@@ -177,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
157
  requirements: []
178
158
 
179
159
  rubyforge_project:
180
- rubygems_version: 1.8.24
160
+ rubygems_version: 1.8.25
181
161
  signing_key:
182
162
  specification_version: 3
183
163
  summary: Capybara Page Objects pattern