ae_page_objects 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ae_page_objects.rb +3 -1
- data/lib/ae_page_objects/concerns/load_ensuring.rb +0 -3
- data/lib/ae_page_objects/concerns/staleable.rb +2 -5
- data/lib/ae_page_objects/concerns/visitable.rb +3 -6
- data/lib/ae_page_objects/core/application_router.rb +111 -41
- data/lib/ae_page_objects/core/basic_router.rb +11 -0
- data/lib/ae_page_objects/core/rake_router.rb +4 -4
- data/lib/ae_page_objects/core/{application.rb → site.rb} +6 -6
- data/lib/ae_page_objects/core/universe.rb +1 -1
- data/lib/ae_page_objects/document.rb +6 -2
- data/lib/ae_page_objects/exceptions.rb +10 -0
- data/lib/ae_page_objects/node.rb +1 -1
- data/lib/ae_page_objects/version.rb +1 -1
- metadata +13 -27
data/lib/ae_page_objects.rb
CHANGED
@@ -2,10 +2,12 @@ require 'capybara'
|
|
2
2
|
require 'capybara/dsl'
|
3
3
|
|
4
4
|
require 'ae_page_objects/version'
|
5
|
+
require 'ae_page_objects/exceptions'
|
5
6
|
|
6
7
|
module AePageObjects
|
7
8
|
autoload :Universe, 'ae_page_objects/core/universe'
|
8
|
-
autoload :
|
9
|
+
autoload :Site, 'ae_page_objects/core/site'
|
10
|
+
autoload :BasicRouter, 'ae_page_objects/core/basic_router'
|
9
11
|
autoload :ApplicationRouter, 'ae_page_objects/core/application_router'
|
10
12
|
autoload :RakeRouter, 'ae_page_objects/core/rake_router'
|
11
13
|
autoload :Dsl, 'ae_page_objects/core/dsl'
|
@@ -1,7 +1,4 @@
|
|
1
1
|
module AePageObjects
|
2
|
-
class PathNotResolvable < StandardError
|
3
|
-
end
|
4
|
-
|
5
2
|
module Concerns
|
6
3
|
module Visitable
|
7
4
|
|
@@ -23,7 +20,7 @@ module AePageObjects
|
|
23
20
|
def visit(*args)
|
24
21
|
raise ArgumentError, "Cannot pass block to visit()" if block_given?
|
25
22
|
|
26
|
-
full_path =
|
23
|
+
full_path = site.generate_path(paths.first, *args)
|
27
24
|
raise PathNotResolvable, "#{self.name} not visitable via #{paths.first}(#{args.inspect})" unless full_path
|
28
25
|
|
29
26
|
Capybara.current_session.visit(full_path)
|
@@ -39,7 +36,7 @@ module AePageObjects
|
|
39
36
|
url = current_url_without_params
|
40
37
|
|
41
38
|
paths.any? do |path|
|
42
|
-
|
39
|
+
site.path_recognizes_url?(path, url)
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
@@ -59,4 +56,4 @@ module AePageObjects
|
|
59
56
|
end
|
60
57
|
end
|
61
58
|
end
|
62
|
-
end
|
59
|
+
end
|
@@ -1,60 +1,130 @@
|
|
1
1
|
module AePageObjects
|
2
|
-
class ApplicationRouter
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
2
|
+
class ApplicationRouter < BasicRouter
|
3
|
+
|
4
|
+
# This whole file is a kludge and probably belongs in an ae_page_objects-rails extension
|
5
|
+
|
6
|
+
module Recognizer
|
7
|
+
|
8
|
+
class Base
|
9
|
+
def generate_path(named_route, *args)
|
10
|
+
if routes.respond_to?("#{named_route}_path")
|
11
|
+
routes.send("#{named_route}_path", *args)
|
12
12
|
end
|
13
13
|
end
|
14
|
-
false
|
15
14
|
end
|
16
|
-
end
|
17
15
|
|
18
|
-
|
19
|
-
|
16
|
+
class Rails23 < Base
|
17
|
+
def recognizes?(path, url)
|
18
|
+
["GET", "PUT", "POST", "DELETE", "PATCH"].map(&:downcase).map(&:to_sym).each do |method|
|
19
|
+
route = ActionController::Routing::Routes.named_routes[path]
|
20
|
+
route.recognize(url, {:method => method})
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
return true if route && route.recognize(url, {:method => method})
|
23
|
+
end
|
24
|
+
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def routes
|
31
|
+
@routes ||= begin
|
32
|
+
routes_class = Class.new do
|
33
|
+
include ActionController::UrlWriter
|
34
|
+
end
|
35
|
+
ActionController::Routing::Routes.install_helpers(routes_class)
|
36
|
+
routes_class.new
|
37
|
+
end
|
38
|
+
end
|
23
39
|
end
|
24
|
-
end
|
25
40
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
41
|
+
class Rails3 < Base
|
42
|
+
def recognizes?(path, url)
|
43
|
+
url, router = url_and_router(url)
|
44
|
+
|
45
|
+
["GET", "PUT", "POST", "DELETE", "PATCH"].each do |method|
|
46
|
+
router.recognize(request_for(url, method)) do |route, matches, params|
|
47
|
+
return true if route.name.to_s == path.to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def request_for(url, method)
|
58
|
+
Rails.application.routes.request_class.new(env_for(url, method))
|
59
|
+
end
|
60
|
+
|
61
|
+
def env_for(url, method)
|
62
|
+
begin
|
63
|
+
Rack::MockRequest.env_for(url, {:method => method})
|
64
|
+
rescue URI::InvalidURIError => e
|
65
|
+
raise ActionController::RoutingError, e.message
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def url_and_router(url)
|
70
|
+
url = Rack::Mount::Utils.normalize_path(url) unless url =~ %r{://}
|
71
|
+
router = Rails.application.routes.set
|
72
|
+
|
73
|
+
[url, router]
|
74
|
+
end
|
75
|
+
|
76
|
+
def routes
|
77
|
+
@routes ||= begin
|
78
|
+
routes_class = Class.new do
|
79
|
+
include Rails.application.routes.url_helpers
|
80
|
+
end
|
81
|
+
routes_class.new
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class Rails32 < Rails3
|
87
|
+
|
88
|
+
private
|
89
|
+
def url_and_router(url)
|
90
|
+
url = Journey::Router::Utils.normalize_path(url) unless url =~ %r{://}
|
91
|
+
router = Rails.application.routes.router
|
92
|
+
|
93
|
+
[url, router]
|
94
|
+
end
|
95
|
+
end
|
30
96
|
end
|
31
|
-
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
97
|
+
|
98
|
+
def path_recognizes_url?(path, url)
|
99
|
+
if path.is_a?(Symbol)
|
100
|
+
recognizer.recognizes?(path, url)
|
101
|
+
else
|
102
|
+
super
|
37
103
|
end
|
38
104
|
end
|
39
|
-
|
40
|
-
def
|
41
|
-
if
|
42
|
-
|
43
|
-
router = Rails.application.routes.set
|
105
|
+
|
106
|
+
def generate_path(named_route, *args)
|
107
|
+
if named_route.is_a?(Symbol)
|
108
|
+
recognizer.generate_path(named_route, *args)
|
44
109
|
else
|
45
|
-
|
46
|
-
router = Rails.application.routes.router
|
110
|
+
super
|
47
111
|
end
|
48
|
-
|
49
|
-
[url, router]
|
50
112
|
end
|
51
113
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
114
|
+
private
|
115
|
+
|
116
|
+
def recognizer
|
117
|
+
@recognizer ||= begin
|
118
|
+
if Rails.version =~ /\A2\.3/
|
119
|
+
Recognizer::Rails23.new
|
120
|
+
elsif Rails.version =~ /\A3\.[01]/
|
121
|
+
Recognizer::Rails3.new
|
122
|
+
elsif Rails.version =~ /\A3\.2/
|
123
|
+
Recognizer::Rails32.new
|
124
|
+
else
|
125
|
+
warn "[WARNING]: AePageObjects is not tested against Rails #{Rails.version} and may behave in an undefined manner."
|
126
|
+
Recognizer::Rails32.new
|
56
127
|
end
|
57
|
-
routes_class.new
|
58
128
|
end
|
59
129
|
end
|
60
130
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module AePageObjects
|
2
|
-
class RakeRouter
|
2
|
+
class RakeRouter < BasicRouter
|
3
3
|
|
4
4
|
attr_reader :routes
|
5
5
|
|
@@ -18,11 +18,11 @@ module AePageObjects
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def path_recognizes_url?(path, url)
|
21
|
-
if path.is_a?(
|
22
|
-
path.sub(/\/$/, '') == url.sub(/\/$/, '')
|
23
|
-
elsif path.is_a?(Symbol)
|
21
|
+
if path.is_a?(Symbol)
|
24
22
|
route = @routes[path]
|
25
23
|
route && route.matches?(url)
|
24
|
+
else
|
25
|
+
super
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module AePageObjects
|
2
|
-
class
|
2
|
+
class Site
|
3
3
|
extend AePageObjects::Singleton
|
4
|
-
|
4
|
+
|
5
5
|
class << self
|
6
6
|
private :new
|
7
7
|
|
@@ -13,11 +13,11 @@ module AePageObjects
|
|
13
13
|
instance.router = router
|
14
14
|
end
|
15
15
|
|
16
|
-
def inherited(
|
16
|
+
def inherited(site_class)
|
17
17
|
super
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
site_class.universe.send(:include, Universe)
|
20
|
+
site_class.universe.page_objects_site_class = site_class
|
21
21
|
end
|
22
22
|
|
23
23
|
def universe
|
@@ -27,7 +27,7 @@ module AePageObjects
|
|
27
27
|
def from(from_mod)
|
28
28
|
until from_mod == Object
|
29
29
|
if from_mod < AePageObjects::Universe
|
30
|
-
return from_mod.
|
30
|
+
return from_mod.page_objects_site_class.instance
|
31
31
|
end
|
32
32
|
|
33
33
|
from_mod = from_mod.parent
|
@@ -2,14 +2,18 @@ module AePageObjects
|
|
2
2
|
class Document < Node
|
3
3
|
include Concerns::Visitable
|
4
4
|
|
5
|
+
def initialize
|
6
|
+
super(Capybara.current_session)
|
7
|
+
end
|
8
|
+
|
5
9
|
def document
|
6
10
|
self
|
7
11
|
end
|
8
12
|
|
9
13
|
class << self
|
10
14
|
private
|
11
|
-
def
|
12
|
-
@
|
15
|
+
def site
|
16
|
+
@site ||= AePageObjects::Site.from(self)
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
data/lib/ae_page_objects/node.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae_page_objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Donnie Tognazzini
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-07-
|
18
|
+
date: 2013-07-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :runtime
|
@@ -32,26 +32,10 @@ dependencies:
|
|
32
32
|
version: "1.1"
|
33
33
|
requirement: *id001
|
34
34
|
prerelease: false
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
type: :runtime
|
37
|
-
name: nokogiri
|
38
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 17
|
44
|
-
segments:
|
45
|
-
- 1
|
46
|
-
- 5
|
47
|
-
- 9
|
48
|
-
version: 1.5.9
|
49
|
-
requirement: *id002
|
50
|
-
prerelease: false
|
51
35
|
- !ruby/object:Gem::Dependency
|
52
36
|
type: :development
|
53
37
|
name: appraisal
|
54
|
-
version_requirements: &
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
55
39
|
none: false
|
56
40
|
requirements:
|
57
41
|
- - ~>
|
@@ -62,12 +46,12 @@ dependencies:
|
|
62
46
|
- 5
|
63
47
|
- 1
|
64
48
|
version: 0.5.1
|
65
|
-
requirement: *
|
49
|
+
requirement: *id002
|
66
50
|
prerelease: false
|
67
51
|
- !ruby/object:Gem::Dependency
|
68
52
|
type: :development
|
69
53
|
name: mocha
|
70
|
-
version_requirements: &
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
71
55
|
none: false
|
72
56
|
requirements:
|
73
57
|
- - "="
|
@@ -78,12 +62,12 @@ dependencies:
|
|
78
62
|
- 13
|
79
63
|
- 3
|
80
64
|
version: 0.13.3
|
81
|
-
requirement: *
|
65
|
+
requirement: *id003
|
82
66
|
prerelease: false
|
83
67
|
- !ruby/object:Gem::Dependency
|
84
68
|
type: :development
|
85
69
|
name: selenium-webdriver
|
86
|
-
version_requirements: &
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
87
71
|
none: false
|
88
72
|
requirements:
|
89
73
|
- - ">="
|
@@ -92,7 +76,7 @@ dependencies:
|
|
92
76
|
segments:
|
93
77
|
- 0
|
94
78
|
version: "0"
|
95
|
-
requirement: *
|
79
|
+
requirement: *id004
|
96
80
|
prerelease: false
|
97
81
|
description: Capybara Page Objects pattern
|
98
82
|
email:
|
@@ -108,10 +92,11 @@ files:
|
|
108
92
|
- lib/ae_page_objects/concerns/load_ensuring.rb
|
109
93
|
- lib/ae_page_objects/concerns/staleable.rb
|
110
94
|
- lib/ae_page_objects/concerns/visitable.rb
|
111
|
-
- lib/ae_page_objects/core/application.rb
|
112
95
|
- lib/ae_page_objects/core/application_router.rb
|
96
|
+
- lib/ae_page_objects/core/basic_router.rb
|
113
97
|
- lib/ae_page_objects/core/dsl.rb
|
114
98
|
- lib/ae_page_objects/core/rake_router.rb
|
99
|
+
- lib/ae_page_objects/core/site.rb
|
115
100
|
- lib/ae_page_objects/core/universe.rb
|
116
101
|
- lib/ae_page_objects/core_ext/module.rb
|
117
102
|
- lib/ae_page_objects/document.rb
|
@@ -121,6 +106,7 @@ files:
|
|
121
106
|
- lib/ae_page_objects/elements/collection.rb
|
122
107
|
- lib/ae_page_objects/elements/form.rb
|
123
108
|
- lib/ae_page_objects/elements/select.rb
|
109
|
+
- lib/ae_page_objects/exceptions.rb
|
124
110
|
- lib/ae_page_objects/node.rb
|
125
111
|
- lib/ae_page_objects/util/hash_symbolizer.rb
|
126
112
|
- lib/ae_page_objects/util/inflector.rb
|