site_prism 2.17.1 → 3.0.beta

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.
@@ -13,37 +13,8 @@ module SitePrism
13
13
 
14
14
  class << self
15
15
  def configure
16
- yield self
17
- end
18
-
19
- attr_reader :use_implicit_waits
20
-
21
- def use_implicit_waits=(value)
22
- show_removed_config_warning_messages
23
- @use_implicit_waits = value
24
- end
25
-
26
- attr_reader :raise_on_wait_fors
27
-
28
- def raise_on_wait_fors=(value)
29
- show_removed_config_warning_messages
30
- @raise_on_wait_fors = value
31
- end
32
-
33
- attr_reader :default_load_validations
34
-
35
- def default_load_validations=(value)
36
- show_removed_config_warning_messages
37
- @default_load_validations = value
38
- end
39
-
40
- def show_removed_config_warning_messages
41
- warn 'This config option is being removed in SitePrism v3. See UPGRADING.md on the repo for more details.'
42
- warn 'Going forwards the configuration / configurability will more closely mimic Capybara.'
16
+ warn 'SitePrism configuration is now removed.'
17
+ warn 'All options fed directly from Capybara.'
43
18
  end
44
19
  end
45
-
46
- @default_load_validations = true
47
- @use_implicit_waits = false
48
- @raise_on_wait_fors = false
49
20
  end
@@ -96,7 +96,7 @@ module SitePrism
96
96
  begin
97
97
  Addressable::URI.parse(url)
98
98
  rescue Addressable::URI::InvalidURIError
99
- raise SitePrism::InvalidUrlMatcher
99
+ raise SitePrism::InvalidUrlMatcherError
100
100
  end
101
101
  end
102
102
 
@@ -3,30 +3,30 @@
3
3
  module SitePrism
4
4
  module ElementChecker
5
5
  def all_there?
6
- elements_to_check.all? { |element| there?(element) }
6
+ elements_to_check.all? { |element| present?(element) }
7
7
  end
8
8
 
9
9
  def elements_present
10
- mapped_items.select { |item_name| there?(item_name) }
10
+ mapped_items.select { |item_name| present?(item_name) }
11
11
  end
12
12
 
13
13
  private
14
14
 
15
15
  def elements_to_check
16
16
  if self.class.expected_items
17
- mapped_items.select do |el|
18
- self.class.expected_items.include?(el)
19
- end
17
+ mapped_items.select { |el| self.class.expected_items.include?(el) }
20
18
  else
21
19
  mapped_items
22
20
  end
23
21
  end
24
22
 
25
23
  def mapped_items
24
+ return unless self.class.mapped_items
25
+
26
26
  self.class.mapped_items.uniq
27
27
  end
28
28
 
29
- def there?(element)
29
+ def present?(element)
30
30
  send("has_#{element}?")
31
31
  end
32
32
  end
@@ -12,63 +12,35 @@ module SitePrism
12
12
  Capybara.default_max_wait_time
13
13
  end
14
14
 
15
- def checker_wait_time
16
- if SitePrism.use_implicit_waits
17
- wait_time
18
- else
19
- 0
20
- end
21
- end
22
-
23
15
  def raise_if_block(obj, name, has_block, type)
24
16
  return unless has_block
25
17
  warn "Type passed in: #{type}"
26
18
 
27
- raise SitePrism::UnsupportedBlock, "#{obj.class}##{name}"
28
- end
29
-
30
- def raise_wait_for_if_failed(obj, name, timeout, failed)
31
- return unless SitePrism.raise_on_wait_fors && failed
32
-
33
- deprecate('Listening for TimeOutWaitingForExistenceError')
34
- raise SitePrism::TimeOutWaitingForExistenceError, \
35
- "Timed out after #{timeout}s waiting for #{obj.class}##{name}"
36
- end
37
-
38
- def raise_wait_for_no_if_failed(obj, name, timeout, failed)
39
- return unless SitePrism.raise_on_wait_fors && failed
40
-
41
- deprecate('Listening for TimeOutWaitingForNonExistenceError')
42
- raise SitePrism::TimeOutWaitingForNonExistenceError, \
43
- "Timed out after #{timeout}s waiting for no #{obj.class}##{name}"
19
+ raise SitePrism::UnsupportedBlockError, "#{obj.class}##{name}"
44
20
  end
45
21
 
46
22
  # Sanitize method called before calling any SitePrism DSL method or
47
23
  # meta-programmed method. This ensures that the Capybara query is correct.
48
- #
49
24
  # Accepts any combination of arguments sent at DSL definition or runtime
50
25
  # and combines them in such a way that Capybara can operate with them.
51
- def merge_args(find_args, runtime_args, override_options = {})
26
+ # Initially it will duplicate all locators and run-time arguments,
27
+ # then it will combine them with any visibility arguments if defined.
28
+ def merge_args(find_args, runtime_args, visibility_args = {})
52
29
  find_args = find_args.dup
53
30
  runtime_args = runtime_args.dup
54
- options = {}
31
+
32
+ options = visibility_args
55
33
  options.merge!(find_args.pop) if find_args.last.is_a? Hash
56
34
  options.merge!(runtime_args.pop) if runtime_args.last.is_a? Hash
57
- options.merge!(override_options)
58
- options[:wait] = false unless wait_required?(options)
35
+ options[:wait] = wait_time unless wait_key_present?(options)
59
36
 
60
37
  return [*find_args, *runtime_args] if options.empty?
61
38
 
62
39
  [*find_args, *runtime_args, options]
63
40
  end
64
41
 
65
- def wait_required?(options)
66
- SitePrism.use_implicit_waits || options.key?(:wait)
67
- end
68
-
69
- def deprecate(previous, new = nil)
70
- warn "Usage of #{previous} is now deprecated and should be not used."
71
- warn "Use #{new} instead." if new
42
+ def wait_key_present?(options)
43
+ options.key?(:wait)
72
44
  end
73
45
 
74
46
  # rubocop:disable Metrics/ModuleLength
@@ -125,7 +97,7 @@ module SitePrism
125
97
  add_to_mapped_items(name)
126
98
  add_iframe_helper_methods(name, *element_find_args)
127
99
  define_method(name) do |&block|
128
- raise BlockMissingError unless block
100
+ raise MissingBlockError unless block
129
101
 
130
102
  within_frame(*scope_find_args) do
131
103
  block.call(klass.new)
@@ -153,8 +125,6 @@ module SitePrism
153
125
  def add_helper_methods(name, *find_args)
154
126
  create_existence_checker(name, *find_args)
155
127
  create_nonexistence_checker(name, *find_args)
156
- create_waiter(name, *find_args)
157
- create_nonexistence_waiter(name, *find_args)
158
128
  create_visibility_waiter(name, *find_args)
159
129
  create_invisibility_waiter(name, *find_args)
160
130
  end
@@ -162,8 +132,6 @@ module SitePrism
162
132
  def add_iframe_helper_methods(name, *find_args)
163
133
  create_existence_checker(name, *find_args)
164
134
  create_nonexistence_checker(name, *find_args)
165
- create_waiter(name, *find_args)
166
- create_nonexistence_waiter(name, *find_args)
167
135
  end
168
136
 
169
137
  def create_helper_method(proposed_method_name, *find_args)
@@ -178,8 +146,7 @@ module SitePrism
178
146
  method_name = "has_#{element_name}?"
179
147
  create_helper_method(method_name, *find_args) do
180
148
  define_method(method_name) do |*runtime_args|
181
- visibility_args = { wait: checker_wait_time }
182
- args = merge_args(find_args, runtime_args, visibility_args)
149
+ args = merge_args(find_args, runtime_args)
183
150
  element_exists?(*args)
184
151
  end
185
152
  end
@@ -189,49 +156,19 @@ module SitePrism
189
156
  method_name = "has_no_#{element_name}?"
190
157
  create_helper_method(method_name, *find_args) do
191
158
  define_method(method_name) do |*runtime_args|
192
- visibility_args = { wait: checker_wait_time }
193
- args = merge_args(find_args, runtime_args, visibility_args)
159
+ args = merge_args(find_args, runtime_args)
194
160
  element_does_not_exist?(*args)
195
161
  end
196
162
  end
197
163
  end
198
164
 
199
- def create_waiter(element_name, *find_args)
200
- method_name = "wait_for_#{element_name}"
201
- create_helper_method(method_name, *find_args) do
202
- define_method(method_name) do |timeout = wait_time, *runtime_args|
203
- deprecate('wait_for methods', 'wait key assignment at runtime')
204
- visibility_args = { wait: timeout }
205
- args = merge_args(find_args, runtime_args, visibility_args)
206
- result = element_exists?(*args)
207
- raise_wait_for_if_failed(self, element_name, timeout, !result)
208
- result
209
- end
210
- end
211
- end
212
-
213
- def create_nonexistence_waiter(element_name, *find_args)
214
- method_name = "wait_for_no_#{element_name}"
215
- create_helper_method(method_name, *find_args) do
216
- define_method(method_name) do |timeout = wait_time, *runtime_args|
217
- deprecate('wait_for_no methods', 'wait key assignment at runtime')
218
- visibility_args = { wait: timeout }
219
- args = merge_args(find_args, runtime_args, visibility_args)
220
- result = element_does_not_exist?(*args)
221
- raise_wait_for_no_if_failed(self, element_name, timeout, !result)
222
- result
223
- end
224
- end
225
- end
226
-
227
165
  def create_visibility_waiter(element_name, *find_args)
228
166
  method_name = "wait_until_#{element_name}_visible"
229
167
  create_helper_method(method_name, *find_args) do
230
- define_method(method_name) do |timeout = wait_time, *runtime_args|
231
- visibility_args = { visible: true, wait: timeout }
232
- args = merge_args(find_args, runtime_args, visibility_args)
168
+ define_method(method_name) do |*runtime_args|
169
+ args = merge_args(find_args, runtime_args, visible: true)
233
170
  return true if element_exists?(*args)
234
- raise SitePrism::TimeOutWaitingForElementVisibility
171
+ raise SitePrism::ElementVisibilityTimeoutError
235
172
  end
236
173
  end
237
174
  end
@@ -239,18 +176,17 @@ module SitePrism
239
176
  def create_invisibility_waiter(element_name, *find_args)
240
177
  method_name = "wait_until_#{element_name}_invisible"
241
178
  create_helper_method(method_name, *find_args) do
242
- define_method(method_name) do |timeout = wait_time, *runtime_args|
243
- visibility_args = { visible: true, wait: timeout }
244
- args = merge_args(find_args, runtime_args, visibility_args)
179
+ define_method(method_name) do |*runtime_args|
180
+ args = merge_args(find_args, runtime_args, visible: true)
245
181
  return true if element_does_not_exist?(*args)
246
- raise SitePrism::TimeOutWaitingForElementInvisibility
182
+ raise SitePrism::ElementInvisibilityTimeoutError
247
183
  end
248
184
  end
249
185
  end
250
186
 
251
187
  def create_no_selector(method_name)
252
188
  define_method(method_name) do
253
- raise SitePrism::NoSelectorForElement, "#{self.class}##{method_name}"
189
+ raise SitePrism::InvalidElementError, "#{self.class}##{method_name}"
254
190
  end
255
191
  end
256
192
 
@@ -8,13 +8,16 @@ module SitePrism
8
8
  class PageLoadError < SitePrismError; end
9
9
 
10
10
  # A page calls #load with no URL set
11
+ # Formerly known as `NoUrlForPage`
11
12
  class NoUrlForPageError < PageLoadError; end
12
13
 
13
14
  # A page calls #displayed? with no URL matcher set
15
+ # Formerly known as `NoUrlMatcherForPage`
14
16
  class NoUrlMatcherForPageError < PageLoadError; end
15
17
 
16
18
  # The URL matcher was not recognised as a Regex or String and as such
17
19
  # it couldn't be parsed by Addressable
20
+ # Formerly known as `InvalidUrlMatcher`
18
21
  class InvalidUrlMatcherError < PageLoadError
19
22
  def message
20
23
  warn 'Templated port numbers are unsupported.'
@@ -24,6 +27,7 @@ module SitePrism
24
27
  end
25
28
 
26
29
  # A SitePrism defined DSL item was defined without a selector
30
+ # Formerly known as `NoSelectorForElement`
27
31
  class InvalidElementError < SitePrismError
28
32
  def message
29
33
  "#{super} has been derived from an item with no selectors defined."
@@ -32,22 +36,28 @@ module SitePrism
32
36
 
33
37
  # The condition that was being evaluated inside the block did not evaluate
34
38
  # to true within the time limit
35
- class TimeoutError < SitePrismError
36
- def message
37
- "Timed out after #{super}s."
38
- end
39
- end
39
+ # Formerly known as `TimeoutException`
40
+ class TimeoutError < SitePrismError; end
40
41
 
41
42
  # These errors are not yet migrated and are fired from their source
42
43
  # They are raised when the meta-programmed method has not yielded true
43
44
  # in the prescribed time limit
45
+ # Formerly known as `TimeOutWaitingForExistenceError`,
46
+ # `TimeOutWaitingForNonExistenceError`
47
+ # `TimeOutWaitingForElementVisibility` and
48
+ # `TimeOutWaitingForElementInvisibility` respectively
49
+
44
50
  class ExistenceTimeoutError < TimeoutError; end
45
51
  class NonExistenceTimeoutError < TimeoutError; end
46
52
  class ElementVisibilityTimeoutError < TimeoutError; end
47
53
  class ElementInvisibilityTimeoutError < TimeoutError; end
48
54
 
55
+ # Generic Block validation family of errors inherit from this error
56
+ class BlockError < SitePrismError; end
57
+
49
58
  # A Block was passed to the method, which it cannot interpret
50
- class UnsupportedBlockError < SitePrismError
59
+ # Formerly known as `UnsupportedBlock`
60
+ class UnsupportedBlockError < BlockError
51
61
  def message
52
62
  warn 'section and iframe are the only items which can accept a block.'
53
63
 
@@ -56,7 +66,8 @@ module SitePrism
56
66
  end
57
67
 
58
68
  # A Block was required, but not passed into the iframe at runtime
59
- class MissingBlockError < SitePrismError
69
+ # Formerly known as `BlockMissingError`
70
+ class MissingBlockError < BlockError
60
71
  def message
61
72
  'You can only use iFrames in a block context - Please pass in a block.'
62
73
  end
@@ -64,6 +75,7 @@ module SitePrism
64
75
 
65
76
  # A page was loaded via #load - And then failed one of the load validations
66
77
  # that was either pre-defined or defined by the user
78
+ # Formerly known as `NotLoadedError`
67
79
  class FailedLoadValidationError < PageLoadError
68
80
  def message
69
81
  if super == self.class.to_s
@@ -73,19 +85,4 @@ module SitePrism
73
85
  end
74
86
  end
75
87
  end
76
-
77
- # Legacy Error Code aliases for backwards compatibility
78
- NoUrlForPage = NoUrlForPageError
79
- NoUrlMatcherForPage = NoUrlMatcherForPageError
80
- InvalidUrlMatcher = InvalidUrlMatcherError
81
- NoSelectorForElement = InvalidElementError
82
- TimeoutException = TimeoutError
83
- # Below four have different inheritance for now to avoid message leaking
84
- TimeOutWaitingForExistenceError = Class.new(StandardError)
85
- TimeOutWaitingForNonExistenceError = Class.new(StandardError)
86
- TimeOutWaitingForElementVisibility = Class.new(StandardError)
87
- TimeOutWaitingForElementInvisibility = Class.new(StandardError)
88
- UnsupportedBlock = UnsupportedBlockError
89
- BlockMissingError = MissingBlockError
90
- NotLoadedError = FailedLoadValidationError
91
88
  end
@@ -28,7 +28,7 @@ module SitePrism
28
28
  # This block can contain up to 2 elements in an array
29
29
  # The first is the physical validation test to be truthily evaluated
30
30
  # If this does not pass, then the 2nd item (If defined), is output
31
- # as an error message to the NotLoadedError Error that will be thrown
31
+ # as an error message to the FailedLoadValidationError that is thrown
32
32
  def load_validation(&block)
33
33
  _load_validations << block
34
34
  end
@@ -36,32 +36,7 @@ module SitePrism
36
36
  private
37
37
 
38
38
  def _load_validations
39
- @_load_validations ||= default_validations
40
- end
41
-
42
- def default_validations
43
- if enabled?
44
- [displayed_validation]
45
- else
46
- []
47
- end
48
- end
49
-
50
- def enabled?
51
- siteprism_page? && SitePrism.default_load_validations
52
- end
53
-
54
- def siteprism_page?
55
- self == SitePrism::Page
56
- end
57
-
58
- def displayed_validation
59
- proc do
60
- [
61
- displayed?,
62
- "Expected #{current_url} to match #{url_matcher} but it did not."
63
- ]
64
- end
39
+ @_load_validations ||= []
65
40
  end
66
41
  end
67
42
 
@@ -91,7 +66,7 @@ module SitePrism
91
66
  # Within the block, cache loaded? to optimize performance.
92
67
  self.loaded = loaded?
93
68
 
94
- raise SitePrism::NotLoadedError, load_error unless loaded
69
+ raise SitePrism::FailedLoadValidationError, load_error unless loaded
95
70
 
96
71
  yield self
97
72
  ensure
@@ -33,7 +33,7 @@ module SitePrism
33
33
  yield self if block_given?
34
34
  else
35
35
  expanded_url = url(expansion_or_html)
36
- raise SitePrism::NoUrlForPage if expanded_url.nil?
36
+ raise SitePrism::NoUrlForPageError unless expanded_url
37
37
  visit expanded_url
38
38
  when_loaded(&block) if block_given?
39
39
  end
@@ -43,10 +43,10 @@ module SitePrism
43
43
  expected_mappings = args.last.is_a?(::Hash) ? args.pop : {}
44
44
  seconds = !args.empty? ? args.first : Capybara.default_max_wait_time
45
45
 
46
- raise SitePrism::NoUrlMatcherForPage if url_matcher.nil?
46
+ raise SitePrism::NoUrlMatcherForPageError unless url_matcher
47
47
  begin
48
48
  Waiter.wait_until_true(seconds) { url_matches?(expected_mappings) }
49
- rescue SitePrism::TimeoutException
49
+ rescue SitePrism::TimeoutError
50
50
  false
51
51
  end
52
52
  end
@@ -122,7 +122,7 @@ module SitePrism
122
122
  elsif url_matcher.respond_to?(:to_str)
123
123
  url_matches_by_template?(expected_mappings)
124
124
  else
125
- raise SitePrism::InvalidUrlMatcher
125
+ raise SitePrism::InvalidUrlMatcherError
126
126
  end
127
127
  end
128
128