site_prism 2.12 → 2.13

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
  SHA1:
3
- metadata.gz: 486bfe34bc7f4ab7dedc373ffdb850d146c731d8
4
- data.tar.gz: 324a724708c627fbc2242bc783ac80a1626472e0
3
+ metadata.gz: 4c6e366dcebe267faac30347ca1d1df9083a35a8
4
+ data.tar.gz: 073d46c7c242f29985a11f788d4647be3f1d0aa0
5
5
  SHA512:
6
- metadata.gz: 62687b2613246d5f2a9afc1623d961ec43249439dbb9f7d391758c723832a587524cd617e4893bdf53405ac42aed942656892eb4269d7a1092d08245573e2796
7
- data.tar.gz: c8065b3bb3cd831bb3ee12e975c701e9b29d998a45d8e640bca5b15c895fe4bfb18012c6fa24dba3ed40af9a53100424ffbc23c9ea212755a7a73bf195fcd60a
6
+ metadata.gz: cd48654ba019e204f5631b571f25e81d2a6dcdf4b8dda728fc40c1a1d8e26f74255cdd2b49dbf12dacd4dca489bc843b20c00cb711884b05cc43b0c94ee14c23
7
+ data.tar.gz: 1422a9b00a5a7a891e043d749bddb47efc1c65d85a01c2481d6bc420079171ea89a9ff63e289afd1a2bf4d91a888a9330d7508c7c8008d93bebf8ece9fc52e0f
data/README.md CHANGED
@@ -9,13 +9,19 @@ Find the pretty documentation here: http://rdoc.info/gems/site_prism/frames
9
9
 
10
10
  Make sure to add your project/company to https://github.com/natritmeyer/site_prism/wiki/Who-is-using-SitePrism
11
11
 
12
+ ## Developing / Contributing to SitePrism
13
+
14
+ We love it when people want to get involved with our Open Source Project.
15
+
16
+ We have a brief set of setup docs [HERE](https://github.com/natritmeyer/site_prism/development_setup.md)
17
+
12
18
  ## Supported Rubies / Browsers
13
19
 
14
- SitePrism is built and tested to work on Ruby 2.1 - 2.4. There is also some limited support for the Ruby 1.9/2.0 series.
20
+ SitePrism is built and tested to work on Ruby 2.1 - 2.5. There is also some limited support for Ruby 2.0.0.
15
21
 
16
- SitePrism should run on all major browsers. The gem's integration tests are ran on the latest version of Firefox.
22
+ SitePrism should run on all major browsers. The gem's integration tests are ran on the latest versions of Chrome and Firefox.
17
23
 
18
- If you find your browser isn't working correctly with SitePrism, please open an [issue request](https://github.com/natritmeyer/site_prism/issues/new)
24
+ If you find your browser doesn't integrate nicely with SitePrism, please open an [issue request](https://github.com/natritmeyer/site_prism/issues/new)
19
25
 
20
26
  ## Synopsis
21
27
 
@@ -60,35 +66,35 @@ end
60
66
 
61
67
  # now for some tests
62
68
 
63
- When /^I navigate to the google home page$/ do
69
+ When(/^I navigate to the google home page$/) do
64
70
  @home = Home.new
65
71
  @home.load
66
72
  end
67
73
 
68
- Then /^the home page should contain the menu and the search form$/ do
74
+ Then(/^the home page should contain the menu and the search form$/) do
69
75
  @home.wait_for_menu # menu loads after a second or 2, give it time to arrive
70
76
  expect(@home).to have_menu
71
77
  expect(@home).to have_search_field
72
78
  expect(@home).to have_search_button
73
79
  end
74
80
 
75
- When /^I search for Sausages$/ do
81
+ When(/^I search for Sausages$/) do
76
82
  @home.search_field.set "Sausages"
77
83
  @home.search_button.click
78
84
  end
79
85
 
80
- Then /^the search results page is displayed$/ do
86
+ Then(/^the search results page is displayed$/) do
81
87
  @results_page = SearchResults.new
82
88
  expect(@results_page).to be_displayed
83
89
  end
84
90
 
85
- Then /^the search results page contains 10 individual search results$/ do
91
+ Then(/^the search results page contains 10 individual search results$/) do
86
92
  @results_page.wait_for_search_results
87
- expect(@results_page).to have_search_results count: 10
93
+ expect(@results_page).to have_search_results(count: 10)
88
94
  end
89
95
 
90
- Then /^the search results contain a link to the wikipedia sausages page$/ do
91
- expect(@results_page.search_result_links).to include "http://en.wikipedia.org/wiki/Sausage"
96
+ Then(/^the search results contain a link to the wikipedia sausages page$/) do
97
+ expect(@results_page.search_result_links).to include('http://en.wikipedia.org/wiki/Sausage')
92
98
  end
93
99
  ```
94
100
 
@@ -166,7 +172,7 @@ you'll need to set its URL. Here's how:
166
172
 
167
173
  ```ruby
168
174
  class Home < SitePrism::Page
169
- set_url "http://www.google.com"
175
+ set_url 'http://www.google.com'
170
176
  end
171
177
  ```
172
178
 
@@ -174,7 +180,7 @@ If you've set Capybara's `app_host` then you can set the URL as follows:
174
180
 
175
181
  ```ruby
176
182
  class Home < SitePrism::Page
177
- set_url "/home.htm"
183
+ set_url '/home.htm'
178
184
  end
179
185
  ```
180
186
 
@@ -261,9 +267,9 @@ The following test code would pass:
261
267
 
262
268
  ```ruby
263
269
  @account_page = Account.new
264
- @account_page.load(id: 22, query: { token: "ca2786616a4285bc" })
270
+ @account_page.load(id: 22, query: { token: 'ca2786616a4285bc' })
265
271
 
266
- expect(@account_page.current_url).to end_with "/accounts/22?token=ca2786616a4285bc"
272
+ expect(@account_page.current_url).to end_with('/accounts/22?token=ca2786616a4285bc')
267
273
  expect(@account_page).to be_displayed
268
274
  ```
269
275
 
@@ -299,10 +305,10 @@ when comparing your page's URL template to the current_url:
299
305
 
300
306
  ```ruby
301
307
  @account_page = Account.new
302
- @account_page.load(id: 22, query: { token: "ca2786616a4285bc", color: 'irrelevant' })
308
+ @account_page.load(id: 22, query: { token: 'ca2786616a4285bc', color: 'irrelevant' })
303
309
 
304
310
  expect(@account_page).to be_displayed(id: 22)
305
- expect(@account_page.url_matches['query']['token']).to eq "ca2786616a4285bc"
311
+ expect(@account_page.url_matches['query']['token']).to eq('ca2786616a4285bc')
306
312
  ```
307
313
 
308
314
  #### Falling back to basic regexp matchers
@@ -341,7 +347,7 @@ end
341
347
  @account = Account.new
342
348
  #...
343
349
  @account.current_url #=> "http://www.example.com/account/123"
344
- expect(@account.current_url).to include 'example.com/account/'
350
+ expect(@account.current_url).to include('example.com/account/')
345
351
  ```
346
352
 
347
353
  ### Page Title
@@ -496,6 +502,19 @@ end
496
502
  @home.wait_for_search_field(10) #will wait for 10 seconds for the search field to appear
497
503
  ```
498
504
 
505
+ #### Waiting for an element to not exist on a page
506
+
507
+ Another method added by calling `element` is the `wait_for_no_<element_name>` method.
508
+ Calling the method will cause the test to wait for the Capybara's
509
+ default wait time for the element to not exist. It is also possible to use a
510
+ custom amount of time to wait. Using the same example as above:
511
+
512
+ ```ruby
513
+ @home.wait_for_no_search_field
514
+ # or...
515
+ @home.wait_for_no_search_field(10) #will wait for 10 seconds for the search field to disappear
516
+ ```
517
+
499
518
  #### Waiting for an element to become visible
500
519
 
501
520
  Another method added by calling `element` is the
@@ -559,6 +578,8 @@ end
559
578
  @home.has_no_search_field?
560
579
  @home.wait_for_search_field
561
580
  @home.wait_for_search_field(10)
581
+ @home.wait_for_no_search_field
582
+ @home.wait_for_no_search_field(10)
562
583
  @home.wait_until_search_field_visible
563
584
  @home.wait_until_search_field_visible(10)
564
585
  @home.wait_until_search_field_invisible
@@ -651,10 +672,12 @@ end
651
672
  #### Waiting for the element collection
652
673
 
653
674
  Just like for an individual element, the tests can be told to wait for
654
- the existence of the element collection. The `elements` method adds a
655
- `wait_for_<element collection name>` method that will wait for
675
+ the existence or non-existence of the element collection. The `elements`
676
+ method adds `wait_for_<element collection name>` and
677
+ `wait_for_no_<element collection name>` methods that will wait for
656
678
  Capybara's default wait time until at least 1 element is found that
657
- matches the selector. For example, with the following page:
679
+ matches the selector, or no elements are found that match the selector,
680
+ respectively. For example, with the following page:
658
681
 
659
682
  ```ruby
660
683
  class Friends < SitePrism::Page
@@ -663,17 +686,24 @@ end
663
686
 
664
687
  ```
665
688
 
666
- ... you can wait for the existence of a list of names like this:
689
+ ... you can also wait for the existence of a list of names like this:
667
690
 
668
691
  ```ruby
669
692
  @friends_page.wait_for_names
670
693
  ```
671
694
 
695
+ or wait for the non-existence of a list of names like this:
696
+
697
+ ```ruby
698
+ @friends_page.wait_for_no_names
699
+ ```
700
+
672
701
  Again, you can customise the wait time by supplying a number of seconds
673
702
  to wait for:
674
703
 
675
704
  ```ruby
676
705
  @friends_page.wait_for_names(10)
706
+ @friends_page.wait_for_no_names(10)
677
707
  ```
678
708
 
679
709
  #### Waiting for the elements to be visible or invisible
@@ -788,18 +818,18 @@ is added is one that returns an instance of the section, the method name
788
818
  being the first argument to the `section` method. Here's an example:
789
819
 
790
820
  ```ruby
791
- # the section:
821
+ # the section
792
822
 
793
823
  class MenuSection < SitePrism::Section
794
824
  end
795
825
 
796
- # the page that includes the section:
826
+ # the page that includes the section
797
827
 
798
828
  class Home < SitePrism::Page
799
829
  section :menu, MenuSection, '#gbx3'
800
830
  end
801
831
 
802
- # the page and section in action:
832
+ # the page and section in action
803
833
 
804
834
  @home = Home.new
805
835
  @home.menu #=> <MenuSection...>
@@ -879,7 +909,7 @@ end
879
909
  ```ruby
880
910
  Then /^the home page menu contains a link to the various search functions$/ do
881
911
  expect(@home.menu).to have_search
882
- expect(@home.menu.search['href']).to include "google.com"
912
+ expect(@home.menu.search['href']).to include('google.com')
883
913
  expect(@home.menu).to have_images
884
914
  expect(@home.menu).to have_maps
885
915
  end
@@ -894,7 +924,7 @@ Some of this test code can be made a little prettier by simply passing a block i
894
924
  Then /^the home page menu contains a link to the various search functions$/ do
895
925
  @home.menu do |menu|
896
926
  expect(menu).to have_search
897
- expect(menu.search['href']).to include "google.com"
927
+ expect(menu.search['href']).to include('google.com')
898
928
  expect(menu).to have_images
899
929
  expect(menu).to have_maps
900
930
  end
@@ -991,11 +1021,12 @@ expect(@home).not_to have_menu
991
1021
 
992
1022
  #### Waiting for a section to exist
993
1023
 
994
- Another method added to the page or section by the `section` method is
995
- `wait_for_<section name>`. Similar to what `element` does, this method
996
- waits for the section to appear - the test will wait up to capybara's
997
- default wait time until the root node of the element exists on the
998
- page/section that our section was added to. Given the following setup:
1024
+ Additional methods added to the page or section by the `section` method are
1025
+ `wait_for_<section name>` and `wait_for_no_<section name>`. Similar to what
1026
+ `element` does, these methods wait for the section to appear or disappear,
1027
+ respectively - the test will wait up to capybara's
1028
+ default wait time until the `root_element` of the section exists or does
1029
+ not exist on the page/section that our section was added to. Given the following setup:
999
1030
 
1000
1031
  ```ruby
1001
1032
  class MenuSection < SitePrism::Section
@@ -1016,6 +1047,13 @@ end
1016
1047
  @home.wait_for_menu(10) # waits for 10 seconds instead of capybara's default timeout
1017
1048
  ```
1018
1049
 
1050
+ ... and we can wait for the menu section to disappear on the page like this:
1051
+
1052
+ ```ruby
1053
+ @home.wait_for_no_menu
1054
+ @home.wait_for_no_menu(10) # waits for 10 seconds instead of capybara's default timeout
1055
+ ```
1056
+
1019
1057
  #### Waiting for a section to become visible or invisible
1020
1058
 
1021
1059
  Like an element, it is possible to wait for a section to become visible
@@ -1080,8 +1118,8 @@ Then /^I sign in$/ do
1080
1118
  @home.wait_for_login_and_registration
1081
1119
  expect(@home).to have_login_and_registration
1082
1120
  expect(@home.login_and_registration).to have_username
1083
- @home.login_and_registration.login.username.set "bob"
1084
- @home.login_and_registration.login.password.set "p4ssw0rd"
1121
+ @home.login_and_registration.login.username.set 'bob'
1122
+ @home.login_and_registration.login.password.set 'p4ssw0rd'
1085
1123
  @home.login_and_registration.login.sign_in.click
1086
1124
  end
1087
1125
 
@@ -1092,7 +1130,7 @@ When /^I enter my name into the home page's registration form$/ do
1092
1130
  @home.load
1093
1131
  expect(@home.login_and_registration).to have_first_name
1094
1132
  expect(@home.login_and_registration).to have_last_name
1095
- @home.login_and_registration.first_name.set "Bob"
1133
+ @home.login_and_registration.first_name.set 'Bob'
1096
1134
  # ...
1097
1135
  end
1098
1136
  ```
@@ -1233,10 +1271,11 @@ end
1233
1271
 
1234
1272
  #### Waiting for sections to appear
1235
1273
 
1236
- The final method added by `sections` to the page/section we're adding
1237
- our sections to is `wait_for_<sections name>`. It will wait for
1238
- capybara's default wait time for there to be at least one instance of
1239
- the section in the array of sections. For example:
1274
+ The last methods added by `sections` to the page/section we're adding
1275
+ our sections to are `wait_for_<sections name>` and `wait_for_no_<sections name>`.
1276
+ They will wait for capybara's default wait time for there to be at least one instance of
1277
+ the section in the array of sections or no instances of the section in the array
1278
+ of sections, respectively. For example:
1240
1279
 
1241
1280
  ```ruby
1242
1281
  class SearchResultSection < SitePrism::Section
@@ -1258,6 +1297,15 @@ end
1258
1297
  @results_page.wait_for_search_results(10) #=> waits for 10 seconds instead of the default capybara timeout
1259
1298
  ```
1260
1299
 
1300
+ ... and how to wait for the sections to disappear
1301
+
1302
+ ```ruby
1303
+ @results_page = SearchResults.new
1304
+ # ...
1305
+ @results_page.wait_for_no_search_results
1306
+ @results_page.wait_for_no_search_results(10) #=> waits for 10 seconds instead of the default capybara timeout
1307
+ ```
1308
+
1261
1309
  ## Load Validations
1262
1310
 
1263
1311
  Load validations enable common validations to be abstracted and performed on a Page or Section to determine
@@ -1432,11 +1480,12 @@ The method calls below will succeed, provided the elements appear on the page wi
1432
1480
  ```ruby
1433
1481
  @results_page = SearchResults.new
1434
1482
  # ...
1435
- @results_page.has_search_results? :count => 25
1483
+ @results_page.has_search_results?(count: 25)
1436
1484
  # OR
1437
- @results_page.search_results :count => 25
1485
+ @results_page.search_results(count: 25)
1438
1486
  # OR
1439
- @results_page.wait_for_search_results nil, :count => 25 # wait_for_<element_name> expects a timeout value to be passed as the first parameter or nil to use the default timeout value.
1487
+ @results_page.wait_for_search_results(nil, :count => 25)
1488
+ # Note that wait_for_<element_name> expects a timeout value to be passed as the first parameter or nil to use the default timeout value.
1440
1489
  ```
1441
1490
 
1442
1491
  Now we can write pretty, non-failing tests without hard coding these options
@@ -1444,7 +1493,7 @@ into our page and section classes:
1444
1493
 
1445
1494
  ```ruby
1446
1495
  Then /^there are search results on the page$/ do
1447
- expect(@results.page).to have_search_results :count => 25
1496
+ expect(@results.page).to have_search_results(count: 25)
1448
1497
  end
1449
1498
  ```
1450
1499
 
@@ -1464,12 +1513,13 @@ end
1464
1513
  The following element methods allow Capybara options to be passed as arguments to the method:
1465
1514
 
1466
1515
  ```ruby
1467
- @results_page.<element_or_section_name> :text => "Welcome!"
1468
- @results_page.has_<element_or_section_name>? :count => 25
1469
- @results_page.has_no_<element_or_section_name>? :text => "Logout"
1470
- @results_page.wait_for_<element_or_section_name> :count => 25
1471
- @results_page.wait_until_<element_or_section_name>_visible :text => "Some ajaxy text appears!"
1472
- @results_page.wait_until_<element_or_section_name>_invisible :text => "Some ajaxy text disappears!"
1516
+ @results_page.<element_or_section_name>(text: 'Welcome!')
1517
+ @results_page.has_<element_or_section_name>?(count: 25)
1518
+ @results_page.has_no_<element_or_section_name>?(text: 'Logout')
1519
+ @results_page.wait_for_<element_or_section_name>(nil, count: 25)
1520
+ @results_page.wait_for_no_<element_or_section_name>(nil, count: 25)
1521
+ @results_page.wait_until_<element_or_section_name>_visible(text: 'Some ajaxy text appears!')
1522
+ @results_page.wait_until_<element_or_section_name>_invisible(text: 'Some ajaxy text disappears!')
1473
1523
  ```
1474
1524
 
1475
1525
  ## Test views with Page objects
@@ -1557,12 +1607,14 @@ expect(@page).to have_my_iframe
1557
1607
  ### Waiting for an iframe
1558
1608
 
1559
1609
  Like an element or section, it is possible to wait for an iframe to
1560
- exist by using the `wait_for_<iframe_name>` method. For example:
1610
+ exist or not exist by using the `wait_for_<iframe_name>` and
1611
+ `wait_for_no_<iframe_name>` methods. For example:
1561
1612
 
1562
1613
  ```ruby
1563
1614
  @page = PageContainingIframe.new
1564
1615
  # ...
1565
1616
  @page.wait_for_my_iframe
1617
+ @page.wait_for_no_my_iframe
1566
1618
  ```
1567
1619
 
1568
1620
  ### Interacting with an iframe's contents:
@@ -1653,7 +1705,7 @@ all over the place. Here's an example of this common problem:
1653
1705
  ```ruby
1654
1706
  @home = Home.new # <-- noise
1655
1707
  @home.load
1656
- @home.search_field.set "Sausages"
1708
+ @home.search_field.set 'Sausages'
1657
1709
  @home.search_field.search_button.click
1658
1710
  @results_page = SearchResults.new # <-- noise
1659
1711
  expect(@results_page).to have_search_result_items
@@ -1697,20 +1749,20 @@ class App
1697
1749
  end
1698
1750
  end
1699
1751
 
1700
- # and here's how to use it:
1752
+ # and here's how to use it
1701
1753
 
1702
1754
  #first line of the test...
1703
- Given /^I start on the home page$/ do
1755
+ Given(/^I start on the home page$/) do
1704
1756
  @app = App.new
1705
1757
  @app.home.load
1706
1758
  end
1707
1759
 
1708
- When /^I search for Sausages$/ do
1709
- @app.home.search_field.set "sausages"
1760
+ When(/^I search for Sausages$/) do
1761
+ @app.home.search_field.set 'Sausages'
1710
1762
  @app.home.search_button.click
1711
1763
  end
1712
1764
 
1713
- Then /^I am on the results page$/ do
1765
+ Then(/^I am on the results page$/) do
1714
1766
  expect(@app.results_page).to be_displayed
1715
1767
  end
1716
1768
 
@@ -5,8 +5,8 @@ module SitePrism
5
5
  attr_reader :mapped_items, :expected_items
6
6
 
7
7
  def element(element_name, *find_args)
8
- build element_name, *find_args do
9
- define_method element_name.to_s do |*runtime_args, &element_block|
8
+ build(element_name, *find_args) do
9
+ define_method(element_name.to_s) do |*runtime_args, &element_block|
10
10
  self.class.raise_if_block(self, element_name.to_s, !element_block.nil?)
11
11
  find_first(*find_args, *runtime_args)
12
12
  end
@@ -14,8 +14,8 @@ module SitePrism
14
14
  end
15
15
 
16
16
  def elements(collection_name, *find_args)
17
- build collection_name, *find_args do
18
- define_method collection_name.to_s do |*runtime_args, &element_block|
17
+ build(collection_name, *find_args) do
18
+ define_method(collection_name.to_s) do |*runtime_args, &element_block|
19
19
  self.class.raise_if_block(self, collection_name.to_s, !element_block.nil?)
20
20
  find_all(*find_args, *runtime_args)
21
21
  end
@@ -28,8 +28,8 @@ module SitePrism
28
28
  end
29
29
 
30
30
  def section(section_name, *args, &block)
31
- section_class, find_args = extract_section_options args, &block
32
- build section_name, *find_args do
31
+ section_class, find_args = extract_section_options(args, &block)
32
+ build(section_name, *find_args) do
33
33
  define_method section_name do |*runtime_args, &runtime_block|
34
34
  section_class.new self, find_first(*find_args, *runtime_args), &runtime_block
35
35
  end
@@ -37,12 +37,12 @@ module SitePrism
37
37
  end
38
38
 
39
39
  def sections(section_collection_name, *args, &block)
40
- section_class, find_args = extract_section_options args, &block
41
- build section_collection_name, *find_args do
42
- define_method section_collection_name do |*runtime_args, &element_block|
40
+ section_class, find_args = extract_section_options(args, &block)
41
+ build(section_collection_name, *find_args) do
42
+ define_method(section_collection_name) do |*runtime_args, &element_block|
43
43
  self.class.raise_if_block(self, section_collection_name.to_s, !element_block.nil?)
44
44
  find_all(*find_args, *runtime_args).map do |element|
45
- section_class.new self, element
45
+ section_class.new(self, element)
46
46
  end
47
47
  end
48
48
  end
@@ -51,11 +51,9 @@ module SitePrism
51
51
  def iframe(iframe_name, iframe_page_class, *args)
52
52
  element_find_args = deduce_iframe_element_find_args(args)
53
53
  scope_find_args = deduce_iframe_scope_find_args(args)
54
- add_to_mapped_items iframe_name
55
- create_existence_checker iframe_name, *element_find_args
56
- create_nonexistence_checker iframe_name, *element_find_args
57
- create_waiter iframe_name, *element_find_args
58
- define_method iframe_name do |&block|
54
+ add_to_mapped_items(iframe_name)
55
+ add_iframe_helper_methods(iframe_name, *element_find_args)
56
+ define_method(iframe_name) do |&block|
59
57
  within_frame(*scope_find_args) do
60
58
  block.call iframe_page_class.new
61
59
  end
@@ -77,25 +75,33 @@ module SitePrism
77
75
 
78
76
  def build(name, *find_args)
79
77
  if find_args.empty?
80
- create_no_selector name
78
+ create_no_selector(name)
81
79
  else
82
- add_to_mapped_items name
80
+ add_to_mapped_items(name)
83
81
  yield
84
82
  end
85
- add_helper_methods name, *find_args
83
+ add_helper_methods(name, *find_args)
86
84
  end
87
85
 
88
86
  def add_helper_methods(name, *find_args)
89
- create_existence_checker name, *find_args
90
- create_nonexistence_checker name, *find_args
91
- create_waiter name, *find_args
92
- create_visibility_waiter name, *find_args
93
- create_invisibility_waiter name, *find_args
87
+ create_existence_checker(name, *find_args)
88
+ create_nonexistence_checker(name, *find_args)
89
+ create_waiter(name, *find_args)
90
+ create_nonexistence_waiter(name, *find_args)
91
+ create_visibility_waiter(name, *find_args)
92
+ create_invisibility_waiter(name, *find_args)
93
+ end
94
+
95
+ def add_iframe_helper_methods(name, *find_args)
96
+ create_existence_checker(name, *find_args)
97
+ create_nonexistence_checker(name, *find_args)
98
+ create_waiter(name, *find_args)
99
+ create_nonexistence_waiter(name, *find_args)
94
100
  end
95
101
 
96
102
  def create_helper_method(proposed_method_name, *find_args)
97
103
  if find_args.empty?
98
- create_no_selector proposed_method_name
104
+ create_no_selector(proposed_method_name)
99
105
  else
100
106
  yield
101
107
  end
@@ -103,10 +109,10 @@ module SitePrism
103
109
 
104
110
  def create_existence_checker(element_name, *find_args)
105
111
  method_name = "has_#{element_name}?"
106
- create_helper_method method_name, *find_args do
107
- define_method method_name do |*runtime_args|
108
- wait_time = SitePrism.use_implicit_waits ? Waiter.default_wait_time : 0
109
- Capybara.using_wait_time wait_time do
112
+ create_helper_method(method_name, *find_args) do
113
+ define_method(method_name) do |*runtime_args|
114
+ wait_time = SitePrism.use_implicit_waits ? Capybara.default_max_wait_time : 0
115
+ Capybara.using_wait_time(wait_time) do
110
116
  element_exists?(*find_args, *runtime_args)
111
117
  end
112
118
  end
@@ -115,10 +121,10 @@ module SitePrism
115
121
 
116
122
  def create_nonexistence_checker(element_name, *find_args)
117
123
  method_name = "has_no_#{element_name}?"
118
- create_helper_method method_name, *find_args do
119
- define_method method_name do |*runtime_args|
120
- wait_time = SitePrism.use_implicit_waits ? Waiter.default_wait_time : 0
121
- Capybara.using_wait_time wait_time do
124
+ create_helper_method(method_name, *find_args) do
125
+ define_method(method_name) do |*runtime_args|
126
+ wait_time = SitePrism.use_implicit_waits ? Capybara.default_max_wait_time : 0
127
+ Capybara.using_wait_time(wait_time) do
122
128
  element_does_not_exist?(*find_args, *runtime_args)
123
129
  end
124
130
  end
@@ -127,21 +133,33 @@ module SitePrism
127
133
 
128
134
  def create_waiter(element_name, *find_args)
129
135
  method_name = "wait_for_#{element_name}"
130
- create_helper_method method_name, *find_args do
131
- define_method method_name do |timeout = nil, *runtime_args|
132
- timeout = timeout.nil? ? Waiter.default_wait_time : timeout
133
- Capybara.using_wait_time timeout do
136
+ create_helper_method(method_name, *find_args) do
137
+ define_method(method_name) do |timeout = nil, *runtime_args|
138
+ timeout = timeout.nil? ? Capybara.default_max_wait_time : timeout
139
+ Capybara.using_wait_time(timeout) do
134
140
  element_exists?(*find_args, *runtime_args)
135
141
  end
136
142
  end
137
143
  end
138
144
  end
139
145
 
146
+ def create_nonexistence_waiter(element_name, *find_args)
147
+ method_name = "wait_for_no_#{element_name}"
148
+ create_helper_method(method_name, *find_args) do
149
+ define_method(method_name) do |timeout = nil, *runtime_args|
150
+ timeout = timeout.nil? ? Waiter.default_wait_time : timeout
151
+ Capybara.using_wait_time(timeout) do
152
+ element_does_not_exist?(*find_args, *runtime_args)
153
+ end
154
+ end
155
+ end
156
+ end
157
+
140
158
  def create_visibility_waiter(element_name, *find_args)
141
159
  method_name = "wait_until_#{element_name}_visible"
142
- create_helper_method method_name, *find_args do
143
- define_method method_name do |timeout = Waiter.default_wait_time, *runtime_args|
144
- Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementVisibility do
160
+ create_helper_method(method_name, *find_args) do
161
+ define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args|
162
+ Timeout.timeout(timeout, SitePrism::TimeOutWaitingForElementVisibility) do
145
163
  Capybara.using_wait_time 0 do
146
164
  sleep 0.05 until element_exists?(*find_args, *runtime_args, visible: true)
147
165
  end
@@ -152,9 +170,9 @@ module SitePrism
152
170
 
153
171
  def create_invisibility_waiter(element_name, *find_args)
154
172
  method_name = "wait_until_#{element_name}_invisible"
155
- create_helper_method method_name, *find_args do
156
- define_method method_name do |timeout = Waiter.default_wait_time, *runtime_args|
157
- Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementInvisibility do
173
+ create_helper_method(method_name, *find_args) do
174
+ define_method(method_name) do |timeout = Capybara.default_max_wait_time, *runtime_args|
175
+ Timeout.timeout(timeout, SitePrism::TimeOutWaitingForElementInvisibility) do
158
176
  Capybara.using_wait_time 0 do
159
177
  sleep 0.05 while element_exists?(*find_args, *runtime_args, visible: true)
160
178
  end
@@ -164,7 +182,7 @@ module SitePrism
164
182
  end
165
183
 
166
184
  def create_no_selector(method_name)
167
- define_method method_name do
185
+ define_method(method_name) do
168
186
  raise SitePrism::NoSelectorForElement.new, "#{self.class.name} => :#{method_name} needs a selector"
169
187
  end
170
188
  end
@@ -195,7 +213,7 @@ module SitePrism
195
213
  if args.first.is_a?(Class)
196
214
  section_class = args.shift
197
215
  elsif block_given?
198
- section_class = Class.new SitePrism::Section, &block
216
+ section_class = Class.new(SitePrism::Section, &block)
199
217
  else
200
218
  raise ArgumentError, 'You should provide section class either as a block, or as the second argument.'
201
219
  end
@@ -11,7 +11,13 @@ module SitePrism
11
11
  end
12
12
 
13
13
  class NoSelectorForElement < StandardError; end
14
- class TimeoutException < StandardError; end
14
+
15
+ class TimeoutException < StandardError
16
+ def message
17
+ "Timed out after #{super}s while waiting for block to evaluate as true."
18
+ end
19
+ end
20
+
15
21
  class TimeOutWaitingForElementVisibility < StandardError; end
16
22
  class TimeOutWaitingForElementInvisibility < StandardError; end
17
23
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SitePrism
4
- VERSION = '2.12'.freeze
4
+ VERSION = '2.13'.freeze
5
5
  end
@@ -2,18 +2,21 @@
2
2
 
3
3
  module SitePrism
4
4
  class Waiter
5
- def self.wait_until_true(wait_time_seconds = default_wait_time)
5
+ def self.wait_until_true(wait_time = Capybara.default_max_wait_time)
6
6
  start_time = Time.now
7
+
7
8
  loop do
8
9
  return true if yield
9
- break unless Time.now - start_time <= wait_time_seconds
10
+ break if Time.now - start_time > wait_time
10
11
  sleep(0.05)
11
12
  end
12
- raise SitePrism::TimeoutException, 'Timed out while waiting for block to return true'
13
+
14
+ raise SitePrism::TimeoutException, wait_time
13
15
  end
14
16
 
15
17
  def self.default_wait_time
16
- Capybara.respond_to?(:default_max_wait_time) ? Capybara.default_max_wait_time : Capybara.default_wait_time
18
+ warn 'default_wait_time is now deprecated. This will be removed in an upcoming release.'
19
+ Capybara.default_max_wait_time
17
20
  end
18
21
  end
19
22
  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: '2.12'
4
+ version: '2.13'
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: 2018-04-17 00:00:00.000000000 Z
12
+ date: 2018-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -45,42 +45,42 @@ dependencies:
45
45
  requirements:
46
46
  - - '='
47
47
  - !ruby/object:Gem::Version
48
- version: 2.4.0
48
+ version: 3.0.1
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - '='
54
54
  - !ruby/object:Gem::Version
55
- version: 2.4.0
55
+ version: 3.0.1
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '11.0'
62
+ version: '12.0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '11.0'
69
+ version: '12.0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '3.3'
76
+ version: '3.5'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '3.3'
83
+ version: '3.5'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rubocop
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +104,7 @@ dependencies:
104
104
  version: 3.4.0
105
105
  - - "<="
106
106
  - !ruby/object:Gem::Version
107
- version: 3.8.0
107
+ version: 3.10.0
108
108
  type: :development
109
109
  prerelease: false
110
110
  version_requirements: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ dependencies:
114
114
  version: 3.4.0
115
115
  - - "<="
116
116
  - !ruby/object:Gem::Version
117
- version: 3.8.0
117
+ version: 3.10.0
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: simplecov
120
120
  requirement: !ruby/object:Gem::Requirement
@@ -133,16 +133,16 @@ dependencies:
133
133
  name: dotenv
134
134
  requirement: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '2.1'
138
+ version: '2.2'
139
139
  type: :development
140
140
  prerelease: false
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '2.1'
145
+ version: '2.2'
146
146
  description: |-
147
147
  SitePrism gives you a simple, clean and semantic DSL for describing your site.
148
148
  SitePrism implements the Page Object Model pattern on top of Capybara.
@@ -177,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- version: '2.0'
180
+ version: '2.1'
181
181
  required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  requirements:
183
183
  - - ">="