site_prism 3.4.2 → 3.5

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: 249c59b53d5563948e846ffbfc9b3880c47f39a8687d769789554260e7f493ff
4
- data.tar.gz: f047a19029312871c1934b925026a15ad351b41fb895503bb98410a322f60307
3
+ metadata.gz: 95c8d9ff0cf7f2b818a8b8cb987ca39f2b512138d572a08533b8466feae6cb63
4
+ data.tar.gz: 6239a4a2cd9be9233396f2b221328645dcb50a56e531ee0d5b63faa3dbd9bf53
5
5
  SHA512:
6
- metadata.gz: 304c67ad2c1f84d1f69072d290ad772a89e92da6863e059077dc2070823314243de54ab05c9ae2044ba1cf72fb7e587c4c63904d8f977a48354415fcd00b0390
7
- data.tar.gz: ffe3bf872b24e78f66ffc2437045801688a9c9f49b60d1453bd4a8b0d1859f942c9f733f37781f0c84e9f97e7e3d961fa88af0b9a94e9acf6abd8f2307da5331
6
+ metadata.gz: a9a7a79356b8f4c16aad85f923db99a549bba2c78ec23624f245504ce3bbffd7698bad6a572ddbb34cbf9f2406da76bda7ce5d2433d874270112025e5e9d79ea
7
+ data.tar.gz: 897ae6d1b6a944b52bc5f36ebb81e2796657a276bfa41994fd0a5315031457d404b46408660556644eb262258c8033b72aa5d7400bd79d13f8085993575df826
data/README.md CHANGED
@@ -15,7 +15,7 @@ Make sure to add your project/company to https://github.com/site-prism/site_pris
15
15
 
16
16
  We love it when people want to get involved with our Open Source Project.
17
17
 
18
- We have a brief set of setup docs [HERE](https://github.com/site-prism/site_prism/blob/master/development_setup.md)
18
+ We have a brief set of setup docs [HERE](https://github.com/site-prism/site_prism/blob/master/HACKING.md)
19
19
 
20
20
  ## Supported Rubies / Browsers
21
21
 
@@ -498,7 +498,7 @@ end
498
498
 
499
499
  #### Waiting for an element to become visible
500
500
 
501
- A method that gets added by calling `element` is the
501
+ A method that gets added by calling `element` is the
502
502
  `wait_until_<element_name>_visible` method. Calling this method will
503
503
  cause the test to wait for Capybara's default wait time for the element
504
504
  to become visible. You can customise the wait time by supplying a number
@@ -921,14 +921,13 @@ end
921
921
 
922
922
  ##### Accessing section elements using a block
923
923
 
924
- A Section can be scoped so it is only accessible inside a block. This is
924
+ You can execute a block within the context of a Section. This is
925
925
  similar to Capybara's `within` method and allows for shorter test code
926
- particularly with nested sections. Some of this test code can be
927
- made a little prettier by simply passing a block in.
926
+ particularly with nested sections. Test code that might have to repeat the block name can be shortened up this way.
928
927
 
929
928
  ```ruby
930
929
  Then(/^the home page menu contains a link to the various search functions$/) do
931
- @home.menu do |menu|
930
+ @home.menu.within do |menu|
932
931
  expect(menu).to have_search
933
932
  expect(menu.search['href']).to include('google.com')
934
933
  expect(menu).to have_images
@@ -937,6 +936,16 @@ Then(/^the home page menu contains a link to the various search functions$/) do
937
936
  end
938
937
  ```
939
938
 
939
+ Note that on an individual section it's possible to pass a block directly to the section without using `within`. Because the block is executed only during `Section` initialization this won't work when accessing a single Section from an array of Sections. For that reason we recommend using `within` which works in either case.
940
+
941
+ ```ruby
942
+ Then(/^the home page menu contains a link to the various search functions$/) do
943
+ @home.menu do |menu| # possible, but prefer: `@home.menu.within`
944
+ expect(menu).to have_search
945
+ end
946
+ end
947
+ ```
948
+
940
949
  #### Getting a section's parent
941
950
 
942
951
  It is possible to ask a section for its parent (page, or section if this
@@ -1175,7 +1184,7 @@ This allows for pretty tests ...
1175
1184
  ```ruby
1176
1185
  Then(/^there are lots of search_results$/) do
1177
1186
  expect(@results_page.search_results.size).to eq(10)
1178
-
1187
+
1179
1188
  @home.search_results.each do |result|
1180
1189
  expect(result).to have_title
1181
1190
  expect(result.blurb.text).not_to be_empty
@@ -1191,6 +1200,26 @@ element. So if the css selector finds 3 `li` elements, calling
1191
1200
  `search_results` will return an array containing 3 instances of
1192
1201
  `SearchResults`, each with one of the `li` elements as it's root element.
1193
1202
 
1203
+ ##### Accessing Within a Collection of Sections
1204
+
1205
+ When using an iterator such as `each` to pass a block through to a collection of sections it is possible to skip using `within`. However some caution is warranted when accessing the Sections directly from an array, as the block can only be executed when the section is being initialized. The following does not work:
1206
+
1207
+ ```rb
1208
+ @home.search_results.first do |result|
1209
+ # This block is silently ignored.
1210
+ expect(result).to have_title
1211
+ end
1212
+ ```
1213
+ Instead use `within` to access the inner-context of the Section.
1214
+
1215
+ ```rb
1216
+ @home.search_results.first.within do |result|
1217
+ # This block is run within the context of the Section.
1218
+ expect(result).to have_title
1219
+ end
1220
+ ```
1221
+
1222
+
1194
1223
  #### Anonymous Section Collections
1195
1224
 
1196
1225
  You can define collections of anonymous sections the same way you would
@@ -1387,7 +1416,7 @@ instance of the class when created.
1387
1416
 
1388
1417
  ### Skipping load Validations
1389
1418
 
1390
- Defined load validations can be skipped for one `load` call by
1419
+ Defined load validations can be skipped for one `load` call by
1391
1420
  passing in `with_validations: false`.
1392
1421
 
1393
1422
  ```ruby
@@ -1654,7 +1683,7 @@ as per the code below
1654
1683
  Capybara.configure do |config|
1655
1684
  config.default_max_wait_time = 11 #=> Wait up to 11 seconds for all queries to fail
1656
1685
  # or if you don't want to ever wait
1657
- config.default_max_wait_time = 0 #=> Don't ever wait!
1686
+ config.default_max_wait_time = 0 #=> Don't ever wait!
1658
1687
  end
1659
1688
  ```
1660
1689
 
@@ -36,6 +36,14 @@ module SitePrism
36
36
  raise SitePrism::UnsupportedBlockError
37
37
  end
38
38
 
39
+ # Warn users from naming the elements starting with no_
40
+ def warn_if_dsl_collision(obj, name)
41
+ return unless name.to_s.start_with?('no_')
42
+
43
+ SitePrism.logger.warn("#{obj.class}##{name} should not start with no_")
44
+ SitePrism::Deprecator.deprecate('Using no_ prefix in DSL definition')
45
+ end
46
+
39
47
  # Sanitize method called before calling any SitePrism DSL method or
40
48
  # meta-programmed method. This ensures that the Capybara query is correct.
41
49
  #
@@ -49,7 +57,7 @@ module SitePrism
49
57
 
50
58
  recombine_args(find_args, runtime_args, options)
51
59
 
52
- return [*find_args, *runtime_args] if options.empty?
60
+ return [*find_args, *runtime_args, {}] if options.empty?
53
61
 
54
62
  [*find_args, *runtime_args, options]
55
63
  end
@@ -79,6 +87,7 @@ module SitePrism
79
87
  SitePrism::Deprecator.deprecate('Passing a block to :element') if block_given?
80
88
  build(:element, name, *find_args) do
81
89
  define_method(name) do |*runtime_args, &element_block|
90
+ warn_if_dsl_collision(self, name)
82
91
  raise_if_block(self, name, !element_block.nil?, :element)
83
92
  _find(*merge_args(find_args, runtime_args))
84
93
  end
@@ -89,6 +98,7 @@ module SitePrism
89
98
  SitePrism::Deprecator.deprecate('Passing a block to :elements') if block_given?
90
99
  build(:elements, name, *find_args) do
91
100
  define_method(name) do |*runtime_args, &element_block|
101
+ warn_if_dsl_collision(self, name)
92
102
  raise_if_block(self, name, !element_block.nil?, :elements)
93
103
  _all(*merge_args(find_args, runtime_args))
94
104
  end
@@ -103,6 +113,7 @@ module SitePrism
103
113
  section_class, find_args = extract_section_options(args, &block)
104
114
  build(:section, name, *find_args) do
105
115
  define_method(name) do |*runtime_args, &runtime_block|
116
+ warn_if_dsl_collision(self, name)
106
117
  section_element = _find(*merge_args(find_args, runtime_args))
107
118
  section_class.new(self, section_element, &runtime_block)
108
119
  end
@@ -103,19 +103,23 @@ module SitePrism
103
103
  private
104
104
 
105
105
  def _find(*find_args)
106
- page.find(*find_args)
106
+ kwargs = find_args.pop
107
+ page.find(*find_args, **kwargs)
107
108
  end
108
109
 
109
110
  def _all(*find_args)
110
- page.all(*find_args)
111
+ kwargs = find_args.pop
112
+ page.all(*find_args, **kwargs)
111
113
  end
112
114
 
113
115
  def element_exists?(*find_args)
114
- page.has_selector?(*find_args)
116
+ kwargs = find_args.pop
117
+ page.has_selector?(*find_args, **kwargs)
115
118
  end
116
119
 
117
120
  def element_does_not_exist?(*find_args)
118
- page.has_no_selector?(*find_args)
121
+ kwargs = find_args.pop
122
+ page.has_no_selector?(*find_args, **kwargs)
119
123
  end
120
124
 
121
125
  def regexp_backed_matches
@@ -25,10 +25,14 @@ module SitePrism
25
25
  nil
26
26
  end
27
27
 
28
- def initialize(parent, root_element)
28
+ def initialize(parent, root_element, &block)
29
29
  @parent = parent
30
30
  @root_element = root_element
31
- Capybara.within(@root_element) { yield(self) } if block_given?
31
+ within(&block) if block_given?
32
+ end
33
+
34
+ def within
35
+ Capybara.within(@root_element) { yield(self) }
32
36
  end
33
37
 
34
38
  # Capybara::DSL module "delegates" Capybara methods to the "page" method
@@ -68,19 +72,23 @@ module SitePrism
68
72
  private
69
73
 
70
74
  def _find(*find_args)
71
- page.find(*find_args)
75
+ kwargs = find_args.pop
76
+ page.find(*find_args, **kwargs)
72
77
  end
73
78
 
74
79
  def _all(*find_args)
75
- page.all(*find_args)
80
+ kwargs = find_args.pop
81
+ page.all(*find_args, **kwargs)
76
82
  end
77
83
 
78
84
  def element_exists?(*find_args)
79
- page.has_selector?(*find_args)
85
+ kwargs = find_args.pop
86
+ page.has_selector?(*find_args, **kwargs)
80
87
  end
81
88
 
82
89
  def element_does_not_exist?(*find_args)
83
- page.has_no_selector?(*find_args)
90
+ kwargs = find_args.pop
91
+ page.has_no_selector?(*find_args, **kwargs)
84
92
  end
85
93
  end
86
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SitePrism
4
- VERSION = '3.4.2'
4
+ VERSION = '3.5'
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.4.2
4
+ version: '3.5'
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: 2020-01-30 00:00:00.000000000 Z
12
+ date: 2020-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -29,16 +29,16 @@ dependencies:
29
29
  name: capybara
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - "<="
33
33
  - !ruby/object:Gem::Version
34
- version: '3.3'
34
+ version: '3.29'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - "<="
40
40
  - !ruby/object:Gem::Version
41
- version: '3.3'
41
+ version: '3.29'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: site_prism-all_there
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -73,6 +73,20 @@ dependencies:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.1'
76
+ - !ruby/object:Gem::Dependency
77
+ name: pry-byebug
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
76
90
  - !ruby/object:Gem::Dependency
77
91
  name: rake
78
92
  requirement: !ruby/object:Gem::Requirement
@@ -231,8 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
245
  - !ruby/object:Gem::Version
232
246
  version: '0'
233
247
  requirements: []
234
- rubyforge_project:
235
- rubygems_version: 2.7.8
248
+ rubygems_version: 3.0.6
236
249
  signing_key:
237
250
  specification_version: 4
238
251
  summary: A Page Object Model DSL for Capybara