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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99cb79c78e6dba7cac9a03b9bdc0bd5c3b68a25995ec38160e9705274ab04cfd
4
- data.tar.gz: 6d91b63cd449fe3f16a364008d5178d7175bd6c4bf65297e5dfe5ae1a0673848
3
+ metadata.gz: a04739bded9cabec9711ba25ac5167f69b7d17e532d106060aab7c03c0c0ff1d
4
+ data.tar.gz: 1da22d259b1dc8490d1a185fd273df0b7a10b9e15baf72a91fecd82daa07844c
5
5
  SHA512:
6
- metadata.gz: 2de60bd237a1d29d1594ba3a8db75e01a09310fe78e48a81d7ea0b1dd7fa53a36d6bdb274c4b592daa0c39a2768c7a371a2939d35177598b146d018dd6ff35f9
7
- data.tar.gz: bbc12f3639fc7bfe30ab28b3dd65b68f30f4c8c6943e306ae849a3b4e16dda104f96c746f21e3b5fe8162c7a4e05388ba9aebe5fd61c024fc27abc4df0b74a16
6
+ metadata.gz: efce339158f4d932f118d162a1284d8237a5e20daf89610f90bb71427fdaaf049dca5b65b22dbad471405f9d3d06dda24274e1dd2ba580fb82e4aa8bca3a817a
7
+ data.tar.gz: 312d3a77862f801b81ad92c5d304a7f2ade43b5ce9300f4e422970a9917189a62f291c4888efcb1f617fafc5b674607e83cc9aab7f136840ae250830e2f28bb0
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2019, Nathaniel Ritmeyer & the SitePrism team
1
+ Copyright (c) 2011-2019, The SitePrism team
2
2
 
3
3
  All rights reserved.
4
4
 
@@ -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 self
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
@@ -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 ||= Capybara.current_session
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
- @page = Capybara.string(expansion_or_html)
49
- yield self if block_given?
50
- else
51
- expanded_url = url(expansion_or_html)
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
- visit expanded_url
55
- when_loaded(&block) if block_given?
56
- end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SitePrism
4
- VERSION = '3.0.2'.freeze
4
+ VERSION = '3.0.3'.freeze
5
5
  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.0.2
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-01-21 00:00:00.000000000 Z
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.5'
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.5'
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.62.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.62.0
117
+ version: 0.63.0
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: selenium-webdriver
120
120
  requirement: !ruby/object:Gem::Requirement