site_prism 4.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a42324a6a59bf20f2c35c519c130d94e314c5170b47ddf1c9f1d3faae98238d7
4
- data.tar.gz: d17845d3b0131de25848bf85b86a7c696ef1160bdc4cf759bd43958d56742d00
3
+ metadata.gz: de1db2cfa8b40510768bbea0bee96e548ae949149428d669e1a038c83e2b7f8d
4
+ data.tar.gz: 3862848b777a9fbafb8c1640df914313b6deac6da942a3859ff2dfe6dbafb214
5
5
  SHA512:
6
- metadata.gz: 7e09efb630b6f8270c7c8bb23c9db92bcccaa09e54c0a7e9ef1a6f2a645f47d821bf912141588ccec1bb3c6aea73f181ff6c8e5b771116f84936d10f95e714ab
7
- data.tar.gz: d1dee7191ea9c01a8cc03e0726ae55ec1de91fe1d9bbb0f6db73e0c6b8af261d598b59d4d1be54e0589e481613b40e574f0d406ac1242d6a2e4cd46a9480c08c
6
+ metadata.gz: 8deff2edc00b2b4c0fab86c96e10bc184ed2afc8276b7daf9f69b97a9f7ab4b105ece138f6901456d76e57d508f546971f0262e6cec90787e64ea89bac904047
7
+ data.tar.gz: 505eb15872469490ab314497737e04eda896f14e7b98c631efae658d42eedb09d8a8aefa53fd5d845fa0a11936951aaf5cd9e6bc99563b4f454251eb212126d9
@@ -15,7 +15,8 @@ module SitePrism
15
15
  @pattern = pattern
16
16
  end
17
17
 
18
- # @return the hash of extracted mappings from
18
+ # @return Hash
19
+ #
19
20
  # parsing the provided URL according to our pattern,
20
21
  # or nil if the URL doesn't conform to the matcher template.
21
22
  def mappings(url)
@@ -30,6 +31,8 @@ module SitePrism
30
31
  result
31
32
  end
32
33
 
34
+ # @return Boolean
35
+ #
33
36
  # Determine whether URL matches our pattern, and
34
37
  # optionally whether the extracted mappings match
35
38
  # a hash of expected values. You can specify values
@@ -38,21 +41,24 @@ module SitePrism
38
41
  actual_mappings = mappings(url)
39
42
  return false unless actual_mappings
40
43
 
41
- expected_mappings.empty? ||
42
- all_expected_mappings_match?(expected_mappings, actual_mappings)
44
+ expected_mappings.empty? || all_expected_mappings_match?(expected_mappings, actual_mappings)
43
45
  end
44
46
 
45
47
  private
46
48
 
47
- def all_expected_mappings_match?(expected_mappings, actual_mappings)
48
- expected_mappings.all? do |key, expected_value|
49
- actual_value = actual_mappings[key.to_s]
50
- case expected_value
51
- when Numeric; then actual_value == expected_value.to_s
52
- when Regexp; then actual_value.match(expected_value)
53
- else expected_value == actual_value
54
- end
55
- end
49
+ def component_matches(component, uri)
50
+ component_template = component_templates[component]
51
+ return {} unless component_template
52
+
53
+ component_url = uri.public_send(component).to_s
54
+ mappings = component_template.extract(component_url)
55
+ return mappings if mappings
56
+
57
+ # To support Addressable's expansion of queries - ensure it's parsing the fragment as appropriate (e.g. {?params*})
58
+ prefix = component_prefixes[component]
59
+ return nil unless prefix
60
+
61
+ component_template.extract(prefix + component_url)
56
62
  end
57
63
 
58
64
  def component_templates
@@ -73,27 +79,6 @@ module SitePrism
73
79
  end
74
80
  end
75
81
 
76
- # Returns empty hash if the template omits the component or a set of
77
- # substitutions if the provided URI component matches the template
78
- # component or nil if the match fails.
79
- def component_matches(component, uri)
80
- component_template = component_templates[component]
81
- return {} unless component_template
82
-
83
- component_url = uri.public_send(component).to_s
84
- mappings = component_template.extract(component_url)
85
- return mappings if mappings
86
-
87
- # to support Addressable's expansion of queries
88
- # ensure it's parsing the fragment as appropriate (e.g. {?params*})
89
- prefix = component_prefixes[component]
90
- return nil unless prefix
91
-
92
- component_template.extract(prefix + component_url)
93
- end
94
-
95
- # Convert the pattern into an Addressable URI by substituting
96
- # the template slugs with nonsense strings.
97
82
  def to_substituted_uri
98
83
  url = pattern
99
84
  substitutions.each_pair { |slug, value| url = url.sub(slug, value) }
@@ -105,13 +90,6 @@ module SitePrism
105
90
  end
106
91
  end
107
92
 
108
- def substitutions
109
- @substitutions ||= slugs.each_with_index.reduce({}) do |memo, slug_index|
110
- slug, index = slug_index
111
- memo.merge(slug => slug_prefix(slug) + substitution_value(index))
112
- end
113
- end
114
-
115
93
  def reverse_substitutions
116
94
  @reverse_substitutions ||=
117
95
  slugs.each_with_index.reduce({}) do |memo, slug_index|
@@ -127,6 +105,24 @@ module SitePrism
127
105
  pattern.scan(/{[^}]+}/)
128
106
  end
129
107
 
108
+ def all_expected_mappings_match?(expected_mappings, actual_mappings)
109
+ expected_mappings.all? do |key, expected_value|
110
+ actual_value = actual_mappings[key.to_s]
111
+ case expected_value
112
+ when Numeric; then actual_value == expected_value.to_s
113
+ when Regexp; then actual_value.match(expected_value)
114
+ else expected_value == actual_value
115
+ end
116
+ end
117
+ end
118
+
119
+ def substitutions
120
+ @substitutions ||= slugs.each_with_index.reduce({}) do |memo, slug_index|
121
+ slug, index = slug_index
122
+ memo.merge(slug => slug_prefix(slug) + substitution_value(index))
123
+ end
124
+ end
125
+
130
126
  # If a slug begins with non-alpha characters, it may denote the start of
131
127
  # a new component (e.g. query or fragment). We emit this prefix as part of
132
128
  # the substituted slug so that Addressable's URI parser can see it as such.
@@ -135,8 +131,7 @@ module SitePrism
135
131
  (prefix && prefix[1]) || ''
136
132
  end
137
133
 
138
- # Generate a repeatable 5 character uniform alphabetical nonsense string
139
- # to allow parsing as a URI
134
+ # Generate a repeatable 5 character uniform alphabetical nonsense string to allow parsing as a URI
140
135
  def substitution_value(index)
141
136
  sha = Digest::SHA1.digest(index.to_s)
142
137
  Base64.urlsafe_encode64(sha).gsub(/[^A-Za-z]/, '')[0..5]
@@ -27,9 +27,9 @@ module SitePrism
27
27
  # NB: As this is bubbled up at debug level, often users will not see this. So it will
28
28
  # never be a candidate for removal directly
29
29
  def soft_deprecate(old, reason, new = nil)
30
- debug("The #{old} method is changing, as is SitePrism, and is now configurable.")
30
+ debug("The #{old} method is changing, as is SitePrism, and is now advised to be changed.")
31
31
  debug("REASON: #{reason}.")
32
- debug('Moving forwards into SitePrism v4, the default behaviour will change.')
32
+ debug('Moving forwards into SitePrism v5, the default behaviour will change.')
33
33
  debug("We advise you change to using #{new}") if new
34
34
  end
35
35
 
@@ -267,11 +267,13 @@ module SitePrism
267
267
  end
268
268
 
269
269
  def legacy_mapped_items
270
- SitePrism::Deprecator.deprecate(
271
- '.mapped_items structure (internally), on a class',
272
- 'Thew new .mapped_items structure'
273
- )
274
- @legacy_mapped_items ||= []
270
+ @legacy_mapped_items ||= begin
271
+ SitePrism::Deprecator.deprecate(
272
+ '.mapped_items structure (internally), on a class',
273
+ 'the new .mapped_items structure'
274
+ )
275
+ []
276
+ end
275
277
  end
276
278
 
277
279
  def map_item(type, name)
@@ -13,10 +13,16 @@ module SitePrism
13
13
  # for how the definition of "every item" is derived.
14
14
  #
15
15
  # Example
16
- # @my_page.mapped_items
17
- # { element => :button_one, element => :button_two, section => :filters }
16
+ # @my_page.class.mapped_items
17
+ # {
18
+ # element => [:button_one, :button_two],
19
+ # elements => [:button_collection_one, :button_collection_two],
20
+ # section => [:filters],
21
+ # sections => [:search_result],
22
+ # iframe => []
23
+ # }
18
24
  # @my_page.all_there?
19
- # => true - If the three items above are all present
25
+ # => true - If the items above are all present
20
26
  #
21
27
  # Note that #elements_to_check will check the hash of mapped_items
22
28
  #
@@ -48,8 +48,10 @@ module SitePrism
48
48
  #
49
49
  # @return [Capybara::Node::Simple || Capybara::Session]
50
50
  def page
51
- SitePrism::Deprecator.deprecate('Calling #page on a SitePrism::Page instance')
52
- (defined?(@page) && @page) || Capybara.current_session
51
+ @_page ||= begin
52
+ SitePrism::Deprecator.deprecate('Calling #page on a SitePrism::Page instance')
53
+ to_capybara_node
54
+ end
53
55
  end
54
56
 
55
57
  # This scopes our calls inside Page correctly to the `Capybara::Session`
@@ -1,15 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SitePrism
4
- # [SitePrism::Timer]
5
4
  #
6
- # Used to count asynchronously towards an overall desired duration or condition (Block)
5
+ # @api private
6
+ #
7
7
  class Timer
8
8
  attr_reader :wait_time
9
9
 
10
- # Count towards a specified time (Supplied)
11
- #
12
- # @return [Proc]
13
10
  def self.run(wait_time, &block)
14
11
  new(wait_time).run(&block)
15
12
  end
@@ -19,16 +16,10 @@ module SitePrism
19
16
  @done = false
20
17
  end
21
18
 
22
- # Whether the timer has completed
23
- #
24
- # @return [Boolean]
25
19
  def done?
26
20
  @done == true
27
21
  end
28
22
 
29
- # Start the Timer and re-evaluate the block repeatedly
30
- #
31
- # @return [Proc]
32
23
  def run
33
24
  start
34
25
  yield self
@@ -36,9 +27,8 @@ module SitePrism
36
27
  stop
37
28
  end
38
29
 
39
- # Start the Timer in a separate process
40
- #
41
- # Return [True]
30
+ private
31
+
42
32
  def start
43
33
  stop
44
34
  return if wait_time.zero?
@@ -50,9 +40,6 @@ module SitePrism
50
40
  end
51
41
  end
52
42
 
53
- # Forcibly stop the timer, and kill any threads created by it
54
- #
55
- # Return [True]
56
43
  def stop
57
44
  if @thread
58
45
  @thread.kill
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SitePrism
4
- VERSION = '4.0'
4
+ VERSION = '4.0.1'
5
5
  end
data/lib/site_prism.rb CHANGED
@@ -2,25 +2,25 @@
2
2
 
3
3
  require 'site_prism/error'
4
4
  require 'site_prism/all_there'
5
+
5
6
  require 'addressable/template'
6
7
  require 'forwardable'
7
8
 
8
- # [SitePrism] namespace
9
- # We autoload our files underneath here to provide a slightly more optimal load solution
10
- module SitePrism
11
- autoload :AddressableUrlMatcher, 'site_prism/addressable_url_matcher'
12
- autoload :DSL, 'site_prism/dsl'
13
- autoload :DSLValidator, 'site_prism/dsl_validator'
14
- autoload :Deprecator, 'site_prism/deprecator'
15
- autoload :ElementChecker, 'site_prism/element_checker'
16
- autoload :Loadable, 'site_prism/loadable'
17
- autoload :Logger, 'site_prism/logger'
18
- autoload :Page, 'site_prism/page'
19
- autoload :RSpecMatchers, 'site_prism/rspec_matchers'
20
- autoload :Section, 'site_prism/section'
21
- autoload :Timer, 'site_prism/timer'
22
- autoload :Waiter, 'site_prism/waiter'
9
+ require 'site_prism/addressable_url_matcher'
10
+ require 'site_prism/dsl'
11
+ require 'site_prism/dsl_validator'
12
+ require 'site_prism/deprecator'
13
+ require 'site_prism/element_checker'
14
+ require 'site_prism/loadable'
15
+ require 'site_prism/logger'
16
+ require 'site_prism/page'
17
+ require 'site_prism/rspec_matchers'
18
+ require 'site_prism/section'
19
+ require 'site_prism/timer'
20
+ require 'site_prism/waiter'
23
21
 
22
+ # [SitePrism]
23
+ module SitePrism
24
24
  class << self
25
25
  def configure
26
26
  yield self
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: '4.0'
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Hill
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-19 00:00:00.000000000 Z
12
+ date: 2023-05-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -107,28 +107,28 @@ dependencies:
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.16.0
110
+ version: 1.17.1
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: 1.16.0
117
+ version: 1.17.1
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: rubocop-rspec
120
120
  requirement: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 2.19.0
124
+ version: 2.20.0
125
125
  type: :development
126
126
  prerelease: false
127
127
  version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 2.19.0
131
+ version: 2.20.0
132
132
  - !ruby/object:Gem::Dependency
133
133
  name: selenium-webdriver
134
134
  requirement: !ruby/object:Gem::Requirement
@@ -161,22 +161,16 @@ dependencies:
161
161
  name: webdrivers
162
162
  requirement: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">"
165
- - !ruby/object:Gem::Version
166
- version: '4.6'
167
- - - "<"
164
+ - - "~>"
168
165
  - !ruby/object:Gem::Version
169
- version: '6'
166
+ version: '5.0'
170
167
  type: :development
171
168
  prerelease: false
172
169
  version_requirements: !ruby/object:Gem::Requirement
173
170
  requirements:
174
- - - ">"
175
- - !ruby/object:Gem::Version
176
- version: '4.6'
177
- - - "<"
171
+ - - "~>"
178
172
  - !ruby/object:Gem::Version
179
- version: '6'
173
+ version: '5.0'
180
174
  description: SitePrism gives you a simple, clean and semantic DSL for describing your
181
175
  site. SitePrism implements the Page Object Model pattern on top of Capybara.
182
176
  email: