site_prism 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/lib/site_prism/loadable.rb +2 -12
- data/lib/site_prism/page.rb +36 -15
- data/lib/site_prism/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a04739bded9cabec9711ba25ac5167f69b7d17e532d106060aab7c03c0c0ff1d
|
4
|
+
data.tar.gz: 1da22d259b1dc8490d1a185fd273df0b7a10b9e15baf72a91fecd82daa07844c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efce339158f4d932f118d162a1284d8237a5e20daf89610f90bb71427fdaaf049dca5b65b22dbad471405f9d3d06dda24274e1dd2ba580fb82e4aa8bca3a817a
|
7
|
+
data.tar.gz: 312d3a77862f801b81ad92c5d304a7f2ade43b5ce9300f4e422970a9917189a62f291c4888efcb1f617fafc5b674607e83cc9aab7f136840ae250830e2f28bb0
|
data/LICENSE.md
CHANGED
data/lib/site_prism/loadable.rb
CHANGED
@@ -58,11 +58,6 @@ module SitePrism
|
|
58
58
|
# inside another when_loaded block.
|
59
59
|
previously_loaded = loaded
|
60
60
|
|
61
|
-
# Ensure we have passed in a block. else stop the system.
|
62
|
-
# This would be because a user has not defined the load validation
|
63
|
-
# correctly (i.e. with a block argument)
|
64
|
-
throw_missing_block_error unless block_given?
|
65
|
-
|
66
61
|
# Within the block, check (and cache) loaded?, to see whether the
|
67
62
|
# page has indeed loaded according to the rules defined by the user.
|
68
63
|
self.loaded = loaded?
|
@@ -71,7 +66,8 @@ module SitePrism
|
|
71
66
|
# If one isn't defined, just return the Error code.
|
72
67
|
raise SitePrism::FailedLoadValidationError, load_error unless loaded
|
73
68
|
|
74
|
-
yield
|
69
|
+
# Return the yield value of the block if one was supplied.
|
70
|
+
yield self if block_given?
|
75
71
|
ensure
|
76
72
|
self.loaded = previously_loaded
|
77
73
|
end
|
@@ -102,11 +98,5 @@ module SitePrism
|
|
102
98
|
passed
|
103
99
|
end
|
104
100
|
end
|
105
|
-
|
106
|
-
def throw_missing_block_error
|
107
|
-
SitePrism.logger.debug('This code point should not be reachable')
|
108
|
-
SitePrism.logger.error('A block was expected, but none received.')
|
109
|
-
raise SitePrism::MissingBlockError
|
110
|
-
end
|
111
101
|
end
|
112
102
|
end
|
data/lib/site_prism/page.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'site_prism/loadable'
|
4
4
|
|
5
5
|
module SitePrism
|
6
|
+
# rubocop:disable Metrics/ClassLength
|
6
7
|
class Page
|
7
8
|
include Capybara::DSL
|
8
9
|
include ElementChecker
|
@@ -25,13 +26,12 @@ module SitePrism
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
# When instantiating the page. A default validation will be added to all
|
29
|
-
# validations you define and add to the Page Class.
|
30
|
-
# When calling #load, all of the validations that are set will be ran
|
31
|
-
# in order, with the default "displayed?" validation being ran _FIRST_
|
32
|
-
|
33
29
|
def page
|
34
|
-
@page
|
30
|
+
if defined?(@page)
|
31
|
+
@page
|
32
|
+
else
|
33
|
+
Capybara.current_session
|
34
|
+
end
|
35
35
|
end
|
36
36
|
|
37
37
|
# Loads the page.
|
@@ -41,19 +41,26 @@ module SitePrism
|
|
41
41
|
#
|
42
42
|
# Executes the block, if given.
|
43
43
|
# Runs load validations on the page, unless input is a string
|
44
|
+
#
|
45
|
+
# When calling #load, all the validations that are set will be ran in order
|
44
46
|
def load(expansion_or_html = {}, &block)
|
45
47
|
self.loaded = false
|
48
|
+
SitePrism.logger.debug("Reset loaded state on #{self.class}.")
|
46
49
|
|
47
|
-
if expansion_or_html.is_a?(String)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
raise SitePrism::NoUrlForPageError unless expanded_url
|
50
|
+
return_yield = if expansion_or_html.is_a?(String)
|
51
|
+
load_html_string(expansion_or_html, &block)
|
52
|
+
else
|
53
|
+
load_html_website(expansion_or_html, &block)
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
# Ensure that we represent that the page we loaded is now indeed loaded!
|
57
|
+
# This ensures that future calls to #loaded? do not perform the
|
58
|
+
# instance evaluations against all load validations procs another time.
|
59
|
+
self.loaded = true
|
60
|
+
|
61
|
+
SitePrism.logger.info("#{self.class} loaded.")
|
62
|
+
# Return the yield from the block if there was one, otherwise return true
|
63
|
+
return_yield || true
|
57
64
|
end
|
58
65
|
|
59
66
|
def displayed?(*args)
|
@@ -139,5 +146,19 @@ module SitePrism
|
|
139
146
|
def matcher_template
|
140
147
|
@matcher_template ||= AddressableUrlMatcher.new(url_matcher)
|
141
148
|
end
|
149
|
+
|
150
|
+
def load_html_string(string)
|
151
|
+
@page = Capybara.string(string)
|
152
|
+
yield self if block_given?
|
153
|
+
end
|
154
|
+
|
155
|
+
def load_html_website(html, &block)
|
156
|
+
expanded_url = url(html)
|
157
|
+
raise SitePrism::NoUrlForPageError unless expanded_url
|
158
|
+
|
159
|
+
visit expanded_url
|
160
|
+
when_loaded(&block)
|
161
|
+
end
|
142
162
|
end
|
163
|
+
# rubocop:enable Metrics/ClassLength
|
143
164
|
end
|
data/lib/site_prism/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_prism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nat Ritmeyer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -65,14 +65,14 @@ dependencies:
|
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2.
|
68
|
+
version: '2.6'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '2.
|
75
|
+
version: '2.6'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: rake
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,14 +107,14 @@ dependencies:
|
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: 0.63.0
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
113
|
version_requirements: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
117
|
+
version: 0.63.0
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: selenium-webdriver
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|