site_prism 3.1 → 3.2

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: 5ccf39fa12f16a3de0a020f5cc51bd0e8809424392120c490b5735c7bddf8eb8
4
- data.tar.gz: bd6daa8edb638af906e6582388aca9fb2185af9b71ac1bd27cddf8a7b0f1a78c
3
+ metadata.gz: 2bb0a772ccdabf209eba492206b0c664418fa46f1b2bdb2c8d08cbcf384b5522
4
+ data.tar.gz: be9c7ca220f2a20122a3bfd955fa617acda1ecb3d6aedac9472300f4c17ff014
5
5
  SHA512:
6
- metadata.gz: 0c84412248c810e5539053376619abe431912f33cdc903ed8455444d2b866b6287cdec771f8045d365660c28a5f9eaac4222059172b0f4b8e42424ab0c9f884a
7
- data.tar.gz: a385856b1c97a688d42a58e6ef36c4ca7e9f71a004065e505b58e0797f47c54b7ecb41a8721353b6f9625274f266768ba1492265665f4ecbd12230eff09ceae7
6
+ metadata.gz: d21079c647c16bcb896374557448fc9c514ce8d3d16379e77f64be741b2ef76f7c2438ff9fd3d0f5bdd96a3678d92b40e162d3847a04647de1ed553b7a786b2f
7
+ data.tar.gz: bf7ea9e4ff98d6ae92427a98b21a35bd519638080c5b3c55f9565e163710b748c11152374293ee783d32a1f1ef599bbac5be99a56f696d144fb1f53d0d7836d4
data/README.md CHANGED
@@ -1345,6 +1345,18 @@ Load validations may be defined on `SitePrism::Page` and `SitePrism::Section`
1345
1345
  classes (herein referred to as `Loadables`) and are evaluated against an
1346
1346
  instance of the class when created.
1347
1347
 
1348
+ ### Skipping load Validations
1349
+
1350
+ Defined load validations can be skipped for one `load` call by
1351
+ passing in `with_validations: false`.
1352
+
1353
+ ```ruby
1354
+ it 'loads the page without validations' do
1355
+ some_page.load(with_validations: false)
1356
+ some_page.loaded? #=> true unless something has gone wrong
1357
+ end
1358
+ ```
1359
+
1348
1360
  ### Load Validation Inheritance and Execution Order
1349
1361
 
1350
1362
  Any number of load validations may be defined on a Loadable and they are
@@ -122,14 +122,11 @@ module SitePrism
122
122
  def iframe(name, klass, *args)
123
123
  element_find_args = deduce_iframe_element_find_args(args)
124
124
  scope_find_args = deduce_iframe_scope_find_args(args)
125
-
126
125
  build(:iframe, name, *element_find_args) do
127
126
  define_method(name) do |&block|
128
127
  raise MissingBlockError unless block
129
128
 
130
- within_frame(*scope_find_args) do
131
- block.call(klass.new)
132
- end
129
+ within_frame(*scope_find_args) { block.call(klass.new) }
133
130
  end
134
131
  end
135
132
  end
@@ -157,6 +154,7 @@ module SitePrism
157
154
  def add_helper_methods(name, *find_args)
158
155
  create_existence_checker(name, *find_args)
159
156
  create_nonexistence_checker(name, *find_args)
157
+ create_rspec_existence_matchers(name) if defined?(RSpec)
160
158
  create_visibility_waiter(name, *find_args)
161
159
  create_invisibility_waiter(name, *find_args)
162
160
  end
@@ -169,6 +167,18 @@ module SitePrism
169
167
  end
170
168
  end
171
169
 
170
+ def create_rspec_existence_matchers(element_name)
171
+ matcher = "has_#{element_name}?"
172
+ negated_matcher = "has_no_#{element_name}?"
173
+
174
+ RSpec::Matchers.define "have_#{element_name}" do |*args|
175
+ match { |actual| actual.public_send(matcher, *args) }
176
+ match_when_negated do |actual|
177
+ actual.public_send(negated_matcher, *args)
178
+ end
179
+ end
180
+ end
181
+
172
182
  def create_existence_checker(element_name, *find_args)
173
183
  method_name = "has_#{element_name}?"
174
184
  create_helper_method(method_name, *find_args) do
@@ -215,10 +225,7 @@ module SitePrism
215
225
 
216
226
  def create_error_method(name)
217
227
  SitePrism.logger.error("#{name} has come from an item with 0 locators.")
218
-
219
- define_method(name) do
220
- raise SitePrism::InvalidElementError
221
- end
228
+ define_method(name) { raise SitePrism::InvalidElementError }
222
229
  end
223
230
 
224
231
  def deduce_iframe_scope_find_args(args)
@@ -242,8 +249,7 @@ module SitePrism
242
249
  def warn_on_invalid_selector_input(args)
243
250
  return unless looks_like_xpath?(args[0])
244
251
 
245
- msg = 'The arguments passed in look like xpath. Check your locators.'
246
- SitePrism.logger.warn(msg)
252
+ SitePrism.logger.warn('The arguments passed in look like xpath. Check your locators.')
247
253
  SitePrism.logger.debug("Default locator: #{Capybara.default_selector}")
248
254
  end
249
255
 
@@ -25,6 +25,14 @@ module SitePrism
25
25
  # Formerly known as `NoSelectorForElement`
26
26
  class InvalidElementError < SitePrismError; end
27
27
 
28
+ # A tool like Timecop is being used to "freeze time" by overriding Time.now
29
+ # and similar methods. In this case, our waiter functions won't work, because
30
+ # Time.now does not change.
31
+ # If you encounter this issue, check that you are not doing Timecop.freeze without
32
+ # an accompanying Timecop.return.
33
+ # Also check out Timecop.safe_mode https://github.com/travisjeffery/timecop#timecopsafe_mode
34
+ class FrozenInTimeError < SitePrismError; end
35
+
28
36
  # The condition that was being evaluated inside the block did not evaluate
29
37
  # to true within the time limit
30
38
  # Formerly known as `TimeoutException`
@@ -64,18 +64,20 @@ module SitePrism
64
64
  end
65
65
 
66
66
  def displayed?(*args)
67
- expected_mappings = args.last.is_a?(::Hash) ? args.pop : {}
68
- seconds = !args.empty? ? args.first : Capybara.default_max_wait_time
67
+ wait_until_displayed(*args)
68
+ rescue SitePrism::TimeoutError
69
+ false
70
+ end
71
+
72
+ def wait_until_displayed(*args)
69
73
  raise SitePrism::NoUrlMatcherForPageError unless url_matcher
70
74
 
71
- begin
72
- Waiter.wait_until_true(seconds) { url_matches?(expected_mappings) }
73
- rescue SitePrism::TimeoutError
74
- false
75
- end
75
+ expected_mappings = args.last.is_a?(::Hash) ? args.pop : {}
76
+ seconds = args&.first || wait_time
77
+ Waiter.wait_until_true(seconds) { url_matches?(expected_mappings) }
76
78
  end
77
79
 
78
- def url_matches(seconds = Capybara.default_max_wait_time)
80
+ def url_matches(seconds = wait_time)
79
81
  return unless displayed?(seconds)
80
82
 
81
83
  if url_matcher.is_a?(Regexp)
@@ -153,11 +155,16 @@ module SitePrism
153
155
  end
154
156
 
155
157
  def load_html_website(html, &block)
158
+ with_validations = html.delete(:with_validations) { true }
156
159
  expanded_url = url(html)
157
160
  raise SitePrism::NoUrlForPageError unless expanded_url
158
161
 
159
162
  visit expanded_url
160
- when_loaded(&block)
163
+ if with_validations
164
+ when_loaded(&block)
165
+ elsif block_given?
166
+ yield self
167
+ end
161
168
  end
162
169
  end
163
170
  # rubocop:enable Metrics/ClassLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SitePrism
4
- VERSION = '3.1'
4
+ VERSION = '3.2'
5
5
  end
@@ -2,17 +2,33 @@
2
2
 
3
3
  module SitePrism
4
4
  class Waiter
5
- def self.wait_until_true(wait_time = Capybara.default_max_wait_time)
6
- start_time = Time.now
5
+ class << self
6
+ def wait_until_true(wait_time = Capybara.default_max_wait_time)
7
+ start_time = Time.now
7
8
 
8
- loop do
9
- return true if yield
10
- break if Time.now - start_time > wait_time
9
+ loop do
10
+ return true if yield
11
+ break if Time.now - start_time > wait_time
11
12
 
12
- sleep(0.05)
13
+ sleep(0.05)
14
+
15
+ check_for_time_stopped!(start_time)
16
+ end
17
+
18
+ raise SitePrism::TimeoutError, "Timed out after #{wait_time}s."
13
19
  end
14
20
 
15
- raise SitePrism::TimeoutError, "Timed out after #{wait_time}s."
21
+ private
22
+
23
+ def check_for_time_stopped!(start_time)
24
+ return unless start_time == Time.now
25
+
26
+ raise(
27
+ SitePrism::FrozenInTimeError,
28
+ 'Time appears to be frozen. For more info, see ' \
29
+ 'https://github.com/natritmeyer/site_prism/blob/master/lib/site_prism/error.rb'
30
+ )
31
+ end
16
32
  end
17
33
  end
18
34
  end
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.1'
4
+ version: '3.2'
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-03-26 00:00:00.000000000 Z
12
+ date: 2019-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -101,14 +101,28 @@ dependencies:
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: 0.63.0
104
+ version: 0.67.0
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: 0.63.0
111
+ version: 0.67.0
112
+ - !ruby/object:Gem::Dependency
113
+ name: rubocop-performance
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 1.0.0
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 1.0.0
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: selenium-webdriver
114
128
  requirement: !ruby/object:Gem::Requirement
@@ -137,8 +151,23 @@ dependencies:
137
151
  - - "~>"
138
152
  - !ruby/object:Gem::Version
139
153
  version: '0.16'
154
+ - !ruby/object:Gem::Dependency
155
+ name: webdrivers
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: 3.9.1
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: 3.9.1
140
168
  description: |-
141
- SitePrism gives you a simple, clean and semantic DSL for describing your site.
169
+ SitePrism gives you a simple,
170
+ clean and semantic DSL for describing your site.
142
171
  SitePrism implements the Page Object Model pattern on top of Capybara.
143
172
  email:
144
173
  - nat@natontesting.com
@@ -165,7 +194,7 @@ licenses:
165
194
  - BSD-3-Clause
166
195
  metadata:
167
196
  bug_tracker_uri: https://github.com/natritmeyer/site_prism/issues
168
- changelog_uri: https://github.com/natritmeyer/site_prism/blob/master/HISTORY.md
197
+ changelog_uri: https://github.com/natritmeyer/site_prism/blob/master/CHANGELOG.md
169
198
  source_code_uri: https://github.com/natritmeyer/site_prism
170
199
  post_install_message:
171
200
  rdoc_options: []