capybara 3.3.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +16 -0
  3. data/README.md +5 -7
  4. data/lib/capybara.rb +7 -6
  5. data/lib/capybara/config.rb +1 -1
  6. data/lib/capybara/dsl.rb +2 -2
  7. data/lib/capybara/helpers.rb +3 -3
  8. data/lib/capybara/minitest/spec.rb +3 -3
  9. data/lib/capybara/node/actions.rb +18 -18
  10. data/lib/capybara/node/base.rb +1 -1
  11. data/lib/capybara/node/element.rb +2 -2
  12. data/lib/capybara/node/finders.rb +6 -6
  13. data/lib/capybara/node/matchers.rb +5 -5
  14. data/lib/capybara/node/simple.rb +2 -2
  15. data/lib/capybara/queries/ancestor_query.rb +1 -1
  16. data/lib/capybara/queries/base_query.rb +12 -11
  17. data/lib/capybara/queries/current_path_query.rb +1 -1
  18. data/lib/capybara/queries/selector_query.rb +39 -15
  19. data/lib/capybara/queries/sibling_query.rb +1 -1
  20. data/lib/capybara/queries/text_query.rb +1 -1
  21. data/lib/capybara/rack_test/browser.rb +7 -7
  22. data/lib/capybara/rack_test/driver.rb +1 -1
  23. data/lib/capybara/rack_test/form.rb +7 -7
  24. data/lib/capybara/rack_test/node.rb +16 -16
  25. data/lib/capybara/rails.rb +1 -1
  26. data/lib/capybara/result.rb +8 -4
  27. data/lib/capybara/rspec/features.rb +4 -4
  28. data/lib/capybara/rspec/matchers.rb +6 -6
  29. data/lib/capybara/selector.rb +106 -90
  30. data/lib/capybara/selector/css.rb +4 -4
  31. data/lib/capybara/selector/filter_set.rb +52 -8
  32. data/lib/capybara/selector/selector.rb +39 -15
  33. data/lib/capybara/selenium/driver.rb +10 -10
  34. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +8 -0
  35. data/lib/capybara/selenium/node.rb +9 -10
  36. data/lib/capybara/selenium/nodes/chrome_node.rb +18 -0
  37. data/lib/capybara/selenium/nodes/marionette_node.rb +32 -7
  38. data/lib/capybara/server.rb +3 -3
  39. data/lib/capybara/server/animation_disabler.rb +1 -1
  40. data/lib/capybara/server/middleware.rb +1 -1
  41. data/lib/capybara/session.rb +23 -19
  42. data/lib/capybara/session/config.rb +18 -3
  43. data/lib/capybara/spec/public/test.js +1 -1
  44. data/lib/capybara/spec/session/accept_alert_spec.rb +10 -10
  45. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -3
  46. data/lib/capybara/spec/session/accept_prompt_spec.rb +9 -10
  47. data/lib/capybara/spec/session/all_spec.rb +33 -32
  48. data/lib/capybara/spec/session/ancestor_spec.rb +19 -19
  49. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +38 -38
  50. data/lib/capybara/spec/session/assert_current_path_spec.rb +16 -16
  51. data/lib/capybara/spec/session/assert_selector_spec.rb +53 -53
  52. data/lib/capybara/spec/session/assert_style_spec.rb +3 -3
  53. data/lib/capybara/spec/session/assert_text_spec.rb +31 -30
  54. data/lib/capybara/spec/session/assert_title_spec.rb +12 -12
  55. data/lib/capybara/spec/session/attach_file_spec.rb +51 -52
  56. data/lib/capybara/spec/session/body_spec.rb +6 -6
  57. data/lib/capybara/spec/session/check_spec.rb +52 -47
  58. data/lib/capybara/spec/session/choose_spec.rb +32 -32
  59. data/lib/capybara/spec/session/click_button_spec.rb +103 -103
  60. data/lib/capybara/spec/session/click_link_or_button_spec.rb +24 -23
  61. data/lib/capybara/spec/session/click_link_spec.rb +49 -48
  62. data/lib/capybara/spec/session/current_scope_spec.rb +7 -7
  63. data/lib/capybara/spec/session/current_url_spec.rb +26 -27
  64. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +3 -3
  65. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -2
  66. data/lib/capybara/spec/session/element/assert_match_selector_spec.rb +8 -8
  67. data/lib/capybara/spec/session/element/match_css_spec.rb +10 -10
  68. data/lib/capybara/spec/session/element/match_xpath_spec.rb +6 -6
  69. data/lib/capybara/spec/session/element/matches_selector_spec.rb +51 -51
  70. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +7 -7
  71. data/lib/capybara/spec/session/evaluate_script_spec.rb +15 -8
  72. data/lib/capybara/spec/session/execute_script_spec.rb +7 -7
  73. data/lib/capybara/spec/session/fill_in_spec.rb +43 -42
  74. data/lib/capybara/spec/session/find_button_spec.rb +23 -23
  75. data/lib/capybara/spec/session/find_by_id_spec.rb +7 -7
  76. data/lib/capybara/spec/session/find_field_spec.rb +32 -30
  77. data/lib/capybara/spec/session/find_link_spec.rb +21 -21
  78. data/lib/capybara/spec/session/find_spec.rb +153 -135
  79. data/lib/capybara/spec/session/first_spec.rb +41 -41
  80. data/lib/capybara/spec/session/frame/frame_title_spec.rb +5 -5
  81. data/lib/capybara/spec/session/frame/frame_url_spec.rb +5 -5
  82. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +17 -17
  83. data/lib/capybara/spec/session/frame/within_frame_spec.rb +31 -17
  84. data/lib/capybara/spec/session/go_back_spec.rb +1 -1
  85. data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
  86. data/lib/capybara/spec/session/has_all_selectors_spec.rb +17 -17
  87. data/lib/capybara/spec/session/has_button_spec.rb +13 -13
  88. data/lib/capybara/spec/session/has_css_spec.rb +133 -131
  89. data/lib/capybara/spec/session/has_current_path_spec.rb +29 -29
  90. data/lib/capybara/spec/session/has_field_spec.rb +58 -58
  91. data/lib/capybara/spec/session/has_link_spec.rb +4 -4
  92. data/lib/capybara/spec/session/has_none_selectors_spec.rb +24 -24
  93. data/lib/capybara/spec/session/has_select_spec.rb +43 -43
  94. data/lib/capybara/spec/session/has_selector_spec.rb +71 -71
  95. data/lib/capybara/spec/session/has_style_spec.rb +3 -3
  96. data/lib/capybara/spec/session/has_table_spec.rb +4 -4
  97. data/lib/capybara/spec/session/has_text_spec.rb +53 -52
  98. data/lib/capybara/spec/session/has_title_spec.rb +14 -14
  99. data/lib/capybara/spec/session/has_xpath_spec.rb +39 -38
  100. data/lib/capybara/spec/session/headers_spec.rb +1 -1
  101. data/lib/capybara/spec/session/html_spec.rb +6 -6
  102. data/lib/capybara/spec/session/node_spec.rb +129 -123
  103. data/lib/capybara/spec/session/node_wrapper_spec.rb +10 -7
  104. data/lib/capybara/spec/session/refresh_spec.rb +4 -7
  105. data/lib/capybara/spec/session/reset_session_spec.rb +28 -28
  106. data/lib/capybara/spec/session/response_code_spec.rb +1 -1
  107. data/lib/capybara/spec/session/save_and_open_page_spec.rb +2 -2
  108. data/lib/capybara/spec/session/save_page_spec.rb +37 -37
  109. data/lib/capybara/spec/session/save_screenshot_spec.rb +6 -6
  110. data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
  111. data/lib/capybara/spec/session/select_spec.rb +81 -81
  112. data/lib/capybara/spec/session/selectors_spec.rb +17 -17
  113. data/lib/capybara/spec/session/sibling_spec.rb +9 -9
  114. data/lib/capybara/spec/session/text_spec.rb +23 -23
  115. data/lib/capybara/spec/session/title_spec.rb +5 -5
  116. data/lib/capybara/spec/session/uncheck_spec.rb +24 -20
  117. data/lib/capybara/spec/session/unselect_spec.rb +37 -37
  118. data/lib/capybara/spec/session/visit_spec.rb +48 -49
  119. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -1
  120. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -16
  121. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -2
  122. data/lib/capybara/spec/session/window/window_spec.rb +4 -4
  123. data/lib/capybara/spec/session/window/within_window_spec.rb +14 -14
  124. data/lib/capybara/spec/session/within_spec.rb +41 -41
  125. data/lib/capybara/spec/spec_helper.rb +11 -9
  126. data/lib/capybara/spec/test_app.rb +18 -17
  127. data/lib/capybara/spec/views/form.erb +29 -31
  128. data/lib/capybara/spec/views/with_html.erb +2 -2
  129. data/lib/capybara/version.rb +1 -1
  130. data/spec/basic_node_spec.rb +23 -23
  131. data/spec/capybara_spec.rb +20 -20
  132. data/spec/css_splitter_spec.rb +7 -7
  133. data/spec/dsl_spec.rb +37 -32
  134. data/spec/filter_set_spec.rb +4 -4
  135. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
  136. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  137. data/spec/minitest_spec.rb +4 -4
  138. data/spec/minitest_spec_spec.rb +23 -23
  139. data/spec/per_session_config_spec.rb +5 -5
  140. data/spec/rack_test_spec.rb +44 -44
  141. data/spec/result_spec.rb +14 -14
  142. data/spec/rspec/features_spec.rb +13 -13
  143. data/spec/rspec/scenarios_spec.rb +4 -4
  144. data/spec/rspec/shared_spec_matchers.rb +282 -281
  145. data/spec/rspec/views_spec.rb +3 -3
  146. data/spec/rspec_matchers_spec.rb +10 -10
  147. data/spec/rspec_spec.rb +29 -29
  148. data/spec/selector_spec.rb +64 -64
  149. data/spec/selenium_spec_chrome.rb +14 -22
  150. data/spec/selenium_spec_chrome_remote.rb +28 -8
  151. data/spec/selenium_spec_edge.rb +9 -4
  152. data/spec/selenium_spec_firefox_remote.rb +87 -0
  153. data/spec/selenium_spec_ie.rb +9 -4
  154. data/spec/selenium_spec_marionette.rb +42 -18
  155. data/spec/server_spec.rb +29 -27
  156. data/spec/session_spec.rb +17 -17
  157. data/spec/shared_selenium_session.rb +70 -52
  158. data/spec/spec_helper.rb +1 -1
  159. metadata +4 -2
@@ -11,13 +11,13 @@ Capybara::SpecHelper.spec '#assert_title' do
11
11
  end.not_to raise_error
12
12
  end
13
13
 
14
- it "should not raise when given an empty string" do
14
+ it 'should not raise when given an empty string' do
15
15
  expect do
16
16
  @session.assert_title('')
17
17
  end.not_to raise_error
18
18
  end
19
19
 
20
- it "should allow regexp matches" do
20
+ it 'should allow regexp matches' do
21
21
  expect do
22
22
  @session.assert_title(/w[a-z]{3}_js/)
23
23
  end.not_to raise_error
@@ -27,10 +27,10 @@ Capybara::SpecHelper.spec '#assert_title' do
27
27
  end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to match /w[a-z]{10}_js/')
28
28
  end
29
29
 
30
- it "should wait for title", requires: [:js] do
31
- @session.click_link("Change title")
30
+ it 'should wait for title', requires: [:js] do
31
+ @session.click_link('Change title')
32
32
  expect do
33
- @session.assert_title("changed title", wait: 3)
33
+ @session.assert_title('changed title', wait: 3)
34
34
  end.not_to raise_error
35
35
  end
36
36
 
@@ -40,12 +40,12 @@ Capybara::SpecHelper.spec '#assert_title' do
40
40
  end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to include "monkey"')
41
41
  end
42
42
 
43
- it "should not normalize given title" do
43
+ it 'should not normalize given title' do
44
44
  @session.visit('/with_js')
45
45
  expect { @session.assert_title(' with_js ') }.to raise_error(Capybara::ExpectationNotMet)
46
46
  end
47
47
 
48
- it "should match correctly normalized title" do
48
+ it 'should match correctly normalized title' do
49
49
  uri = Addressable::URI.parse('/with_title')
50
50
  uri.query_values = { title: '   with space  title ' }
51
51
  @session.visit(uri.to_s)
@@ -53,7 +53,7 @@ Capybara::SpecHelper.spec '#assert_title' do
53
53
  expect { @session.assert_title('with space title') }.to raise_error(Capybara::ExpectationNotMet)
54
54
  end
55
55
 
56
- it "should not normalize given title in error message" do
56
+ it 'should not normalize given title in error message' do
57
57
  expect do
58
58
  @session.assert_title(2)
59
59
  end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to include "2"')
@@ -65,21 +65,21 @@ Capybara::SpecHelper.spec '#assert_no_title' do
65
65
  @session.visit('/with_js')
66
66
  end
67
67
 
68
- it "should raise error if the title contains the given string" do
68
+ it 'should raise error if the title contains the given string' do
69
69
  expect do
70
70
  @session.assert_no_title('with_j')
71
71
  end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" not to include "with_j"')
72
72
  end
73
73
 
74
- it "should allow regexp matches" do
74
+ it 'should allow regexp matches' do
75
75
  expect do
76
76
  @session.assert_no_title(/w[a-z]{3}_js/)
77
77
  end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" not to match /w[a-z]{3}_js/')
78
78
  @session.assert_no_title(/monkey/)
79
79
  end
80
80
 
81
- it "should wait for title to disappear", requires: [:js] do
82
- @session.click_link("Change title")
81
+ it 'should wait for title to disappear', requires: [:js] do
82
+ @session.click_link('Change title')
83
83
  expect do
84
84
  @session.assert_no_title('with_js', wait: 3)
85
85
  end.not_to raise_error
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Capybara::SpecHelper.spec "#attach_file" do
3
+ Capybara::SpecHelper.spec '#attach_file' do
4
4
  before do
5
5
  @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
6
6
  @another_test_file_path = File.expand_path('../fixtures/another_test_file.txt', File.dirname(__FILE__))
@@ -9,97 +9,96 @@ Capybara::SpecHelper.spec "#attach_file" do
9
9
  @session.visit('/form')
10
10
  end
11
11
 
12
- context "with normal form" do
13
- it "should set a file path by id" do
14
- @session.attach_file "form_image", with_os_path_separators(__FILE__)
12
+ context 'with normal form' do
13
+ it 'should set a file path by id' do
14
+ @session.attach_file 'form_image', with_os_path_separators(__FILE__)
15
15
  @session.click_button('awesome')
16
16
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
17
17
  end
18
18
 
19
- it "should set a file path by label" do
20
- @session.attach_file "Image", with_os_path_separators(__FILE__)
19
+ it 'should set a file path by label' do
20
+ @session.attach_file 'Image', with_os_path_separators(__FILE__)
21
21
  @session.click_button('awesome')
22
22
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
23
23
  end
24
24
 
25
- it "casts to string" do
25
+ it 'casts to string' do
26
26
  @session.attach_file :form_image, with_os_path_separators(__FILE__)
27
27
  @session.click_button('awesome')
28
28
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
29
29
  end
30
30
  end
31
31
 
32
- context "with multipart form" do
33
- it "should set a file path by id" do
34
- @session.attach_file "form_document", with_os_path_separators(@test_file_path)
32
+ context 'with multipart form' do
33
+ it 'should set a file path by id' do
34
+ @session.attach_file 'form_document', with_os_path_separators(@test_file_path)
35
35
  @session.click_button('Upload Single')
36
36
  expect(@session).to have_content(File.read(@test_file_path))
37
37
  end
38
38
 
39
- it "should set a file path by label" do
40
- @session.attach_file "Single Document", with_os_path_separators(@test_file_path)
39
+ it 'should set a file path by label' do
40
+ @session.attach_file 'Single Document', with_os_path_separators(@test_file_path)
41
41
  @session.click_button('Upload Single')
42
42
  expect(@session).to have_content(File.read(@test_file_path))
43
43
  end
44
44
 
45
- it "should not break if no file is submitted" do
45
+ it 'should not break if no file is submitted' do
46
46
  @session.click_button('Upload Single')
47
47
  expect(@session).to have_content('No file uploaded')
48
48
  end
49
49
 
50
- it "should send content type text/plain when uploading a text file" do
51
- @session.attach_file "Single Document", with_os_path_separators(@test_file_path)
50
+ it 'should send content type text/plain when uploading a text file' do
51
+ @session.attach_file 'Single Document', with_os_path_separators(@test_file_path)
52
52
  @session.click_button 'Upload Single'
53
53
  expect(@session).to have_content('text/plain')
54
54
  end
55
55
 
56
- it "should send content type image/jpeg when uploading an image" do
57
- @session.attach_file "Single Document", with_os_path_separators(@test_jpg_file_path)
56
+ it 'should send content type image/jpeg when uploading an image' do
57
+ @session.attach_file 'Single Document', with_os_path_separators(@test_jpg_file_path)
58
58
  @session.click_button 'Upload Single'
59
59
  expect(@session).to have_content('image/jpeg')
60
60
  end
61
61
 
62
- it "should not break when uploading a file without extension" do
63
- @session.attach_file "Single Document", with_os_path_separators(@no_extension_file_path)
62
+ it 'should not break when uploading a file without extension' do
63
+ @session.attach_file 'Single Document', with_os_path_separators(@no_extension_file_path)
64
64
  @session.click_button 'Upload Single'
65
65
  expect(@session).to have_content(File.read(@no_extension_file_path))
66
66
  end
67
67
 
68
- it "should not break when using HTML5 multiple file input" do
69
- @session.attach_file "Multiple Documents", with_os_path_separators(@test_file_path)
68
+ it 'should not break when using HTML5 multiple file input' do
69
+ @session.attach_file 'Multiple Documents', with_os_path_separators(@test_file_path)
70
70
  @session.click_button('Upload Multiple')
71
71
  expect(@session).to have_content(File.read(@test_file_path))
72
- expect(@session.body).to include("1 | ") # number of files
72
+ expect(@session.body).to include('1 | ') # number of files
73
73
  end
74
74
 
75
- it "should not break when using HTML5 multiple file input uploading multiple files" do
76
- @session.attach_file("Multiple Documents",
75
+ it 'should not break when using HTML5 multiple file input uploading multiple files' do
76
+ @session.attach_file('Multiple Documents',
77
77
  [@test_file_path, @another_test_file_path].map { |f| with_os_path_separators(f) })
78
78
  @session.click_button('Upload Multiple')
79
- expect(@session.body).to include("2 | ") # number of files
79
+ expect(@session.body).to include('2 | ') # number of files
80
80
  expect(@session.body).to include(File.read(@test_file_path))
81
81
  expect(@session.body).to include(File.read(@another_test_file_path))
82
82
  end
83
83
 
84
- it "should not send anything when attaching no files to a multiple upload field" do
84
+ it 'should not send anything when attaching no files to a multiple upload field' do
85
85
  @session.click_button('Upload Empty Multiple')
86
- expect(@session).to have_content("Successfully ignored empty file field")
86
+ expect(@session).to have_content('Successfully ignored empty file field')
87
87
  end
88
88
 
89
- it "should not append files to already attached" do
90
- @session.attach_file "Multiple Documents", with_os_path_separators(@test_file_path)
91
- @session.attach_file("Multiple Documents",
92
- [@test_file_path, @another_test_file_path].map { |f| with_os_path_separators(f) })
89
+ it 'should not append files to already attached' do
90
+ @session.attach_file 'Multiple Documents', with_os_path_separators(@test_file_path)
91
+ @session.attach_file 'Multiple Documents', with_os_path_separators(@another_test_file_path)
93
92
  @session.click_button('Upload Multiple')
94
- expect(@session.body).to include("2 | ") # number of files
95
- expect(@session.body).to include(File.read(@test_file_path))
93
+ expect(@session.body).to include('1 | ') # number of files
96
94
  expect(@session.body).to include(File.read(@another_test_file_path))
95
+ expect(@session.body).not_to include(File.read(@test_file_path))
97
96
  end
98
97
  end
99
98
 
100
99
  context "with a locator that doesn't exist" do
101
- it "should raise an error" do
102
- msg = "Unable to find visible file field \"does not exist\" that is not disabled"
100
+ it 'should raise an error' do
101
+ msg = 'Unable to find file field "does not exist"'
103
102
  expect do
104
103
  @session.attach_file('does not exist', with_os_path_separators(@test_file_path))
105
104
  end.to raise_error(Capybara::ElementNotFound, msg)
@@ -107,56 +106,56 @@ Capybara::SpecHelper.spec "#attach_file" do
107
106
  end
108
107
 
109
108
  context "with a path that doesn't exist" do
110
- it "should raise an error" do
109
+ it 'should raise an error' do
111
110
  expect { @session.attach_file('Image', '/no_such_file.png') }.to raise_error(Capybara::FileNotFound)
112
111
  end
113
112
  end
114
113
 
115
- context "with :exact option" do
116
- it "should set a file path by partial label when false" do
117
- @session.attach_file "Imag", with_os_path_separators(__FILE__), exact: false
114
+ context 'with :exact option' do
115
+ it 'should set a file path by partial label when false' do
116
+ @session.attach_file 'Imag', with_os_path_separators(__FILE__), exact: false
118
117
  @session.click_button('awesome')
119
118
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
120
119
  end
121
120
 
122
- it "should not allow partial matches when true" do
121
+ it 'should not allow partial matches when true' do
123
122
  expect do
124
- @session.attach_file "Imag", with_os_path_separators(__FILE__), exact: true
123
+ @session.attach_file 'Imag', with_os_path_separators(__FILE__), exact: true
125
124
  end.to raise_error(Capybara::ElementNotFound)
126
125
  end
127
126
  end
128
127
 
129
- context "with :make_visible option", requires: %i[js es_args] do
130
- it "applies a default style change when true" do
128
+ context 'with :make_visible option', requires: %i[js es_args] do
129
+ it 'applies a default style change when true' do
131
130
  @session.visit('/with_js')
132
131
  expect do
133
- @session.attach_file("hidden_file", with_os_path_separators(__FILE__))
132
+ @session.attach_file('hidden_file', with_os_path_separators(__FILE__))
134
133
  end.to raise_error Capybara::ElementNotFound
135
134
  expect do
136
- @session.attach_file("hidden_file", with_os_path_separators(__FILE__), make_visible: true)
135
+ @session.attach_file('hidden_file', with_os_path_separators(__FILE__), make_visible: true)
137
136
  end.not_to raise_error
138
137
  end
139
138
 
140
- it "accepts a hash of styles to be applied" do
139
+ it 'accepts a hash of styles to be applied' do
141
140
  @session.visit('/with_js')
142
141
  expect do
143
- @session.attach_file("hidden_file",
142
+ @session.attach_file('hidden_file',
144
143
  with_os_path_separators(__FILE__),
145
144
  make_visible: { opacity: 1, display: 'block' })
146
145
  end.not_to raise_error
147
146
  end
148
147
 
149
- it "raises an error when the file input is not made visible" do
148
+ it 'raises an error when the file input is not made visible' do
150
149
  @session.visit('/with_js')
151
150
  expect do
152
- @session.attach_file("hidden_file", with_os_path_separators(__FILE__), make_visible: { color: 'red' })
151
+ @session.attach_file('hidden_file', with_os_path_separators(__FILE__), make_visible: { color: 'red' })
153
152
  end.to raise_error(Capybara::ExpectationNotMet)
154
153
  end
155
154
 
156
- it "resets the style when done" do
155
+ it 'resets the style when done' do
157
156
  @session.visit('/with_js')
158
- @session.attach_file("hidden_file", with_os_path_separators(__FILE__), make_visible: true)
159
- expect(@session.evaluate_script("arguments[0].style.display", @session.find(:css, '#hidden_file', visible: :all))).to eq 'none'
157
+ @session.attach_file('hidden_file', with_os_path_separators(__FILE__), make_visible: true)
158
+ expect(@session.evaluate_script('arguments[0].style.display', @session.find(:css, '#hidden_file', visible: :all))).to eq 'none'
160
159
  end
161
160
  end
162
161
 
@@ -1,23 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Capybara::SpecHelper.spec '#body' do
4
- it "should return the unmodified page body" do
4
+ it 'should return the unmodified page body' do
5
5
  @session.visit('/')
6
6
  expect(@session).to have_content('Hello world!') # wait for content to appear if visit is async
7
7
  expect(@session.body).to include('Hello world!')
8
8
  end
9
9
 
10
- context "encoding of response between ascii and utf8" do
11
- it "should be valid with html entities" do
10
+ context 'encoding of response between ascii and utf8' do
11
+ it 'should be valid with html entities' do
12
12
  @session.visit('/with_html_entities')
13
13
  expect(@session).to have_content('Encoding') # wait for content to appear if visit is async
14
- expect { @session.body.encode!("UTF-8") }.not_to raise_error
14
+ expect { @session.body.encode!('UTF-8') }.not_to raise_error
15
15
  end
16
16
 
17
- it "should be valid without html entities" do
17
+ it 'should be valid without html entities' do
18
18
  @session.visit('/with_html')
19
19
  expect(@session).to have_content('This is a test') # wait for content to appear if visit is async
20
- expect { @session.body.encode!("UTF-8") }.not_to raise_error
20
+ expect { @session.body.encode!('UTF-8') }.not_to raise_error
21
21
  end
22
22
  end
23
23
  end
@@ -1,182 +1,187 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Capybara::SpecHelper.spec "#check" do
3
+ Capybara::SpecHelper.spec '#check' do
4
4
  before do
5
5
  @session.visit('/form')
6
6
  end
7
7
 
8
8
  describe "'checked' attribute" do
9
- it "should be true if checked" do
10
- @session.check("Terms of Use")
9
+ it 'should be true if checked' do
10
+ @session.check('Terms of Use')
11
11
  expect(@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked']).to be_truthy
12
12
  end
13
13
 
14
- it "should be false if unchecked" do
14
+ it 'should be false if unchecked' do
15
15
  expect(@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked']).to be_falsey
16
16
  end
17
17
  end
18
18
 
19
- it "should trigger associated events", requires: [:js] do
19
+ it 'should trigger associated events', requires: [:js] do
20
20
  @session.visit('/with_js')
21
21
  @session.check('checkbox_with_event')
22
22
  expect(@session).to have_css('#checkbox_event_triggered')
23
23
  end
24
24
 
25
- describe "checking" do
26
- it "should not change an already checked checkbox" do
25
+ describe 'checking' do
26
+ it 'should not change an already checked checkbox' do
27
27
  expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).to be_checked
28
28
  @session.check('form_pets_dog')
29
29
  expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).to be_checked
30
30
  end
31
31
 
32
- it "should check an unchecked checkbox" do
32
+ it 'should check an unchecked checkbox' do
33
33
  expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).not_to be_checked
34
34
  @session.check('form_pets_cat')
35
35
  expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).to be_checked
36
36
  end
37
37
  end
38
38
 
39
- describe "unchecking" do
40
- it "should not change an already unchecked checkbox" do
39
+ describe 'unchecking' do
40
+ it 'should not change an already unchecked checkbox' do
41
41
  expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).not_to be_checked
42
42
  @session.uncheck('form_pets_cat')
43
43
  expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).not_to be_checked
44
44
  end
45
45
 
46
- it "should uncheck a checked checkbox" do
46
+ it 'should uncheck a checked checkbox' do
47
47
  expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).to be_checked
48
48
  @session.uncheck('form_pets_dog')
49
49
  expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).not_to be_checked
50
50
  end
51
51
  end
52
52
 
53
- it "should check a checkbox by id" do
54
- @session.check("form_pets_cat")
53
+ it 'should check a checkbox by id' do
54
+ @session.check('form_pets_cat')
55
55
  @session.click_button('awesome')
56
56
  expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster')
57
57
  end
58
58
 
59
- it "should check a checkbox by label" do
60
- @session.check("Cat")
59
+ it 'should check a checkbox by label' do
60
+ @session.check('Cat')
61
61
  @session.click_button('awesome')
62
62
  expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster')
63
63
  end
64
64
 
65
- it "should work without a locator string" do
66
- @session.check(id: "form_pets_cat")
65
+ it 'should work without a locator string' do
66
+ @session.check(id: 'form_pets_cat')
67
67
  @session.click_button('awesome')
68
68
  expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster')
69
69
  end
70
70
 
71
- it "casts to string" do
71
+ it 'casts to string' do
72
72
  @session.check(:form_pets_cat)
73
73
  @session.click_button('awesome')
74
74
  expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster')
75
75
  end
76
76
 
77
77
  context "with a locator that doesn't exist" do
78
- it "should raise an error" do
79
- msg = "Unable to find visible checkbox \"does not exist\" that is not disabled"
78
+ it 'should raise an error' do
79
+ msg = 'Unable to find checkbox "does not exist"'
80
80
  expect do
81
81
  @session.check('does not exist')
82
82
  end.to raise_error(Capybara::ElementNotFound, msg)
83
83
  end
84
84
  end
85
85
 
86
- context "with a disabled checkbox" do
87
- it "should raise an error" do
86
+ context 'with a disabled checkbox' do
87
+ it 'should raise an error' do
88
+ msg = 'Unable to find visible checkbox "Disabled Checkbox" that is not disabled'
88
89
  expect do
89
90
  @session.check('Disabled Checkbox')
90
- end.to raise_error(Capybara::ElementNotFound)
91
+ end.to raise_error(Capybara::ElementNotFound, msg)
91
92
  end
92
93
  end
93
94
 
94
- context "with :exact option" do
95
- it "should accept partial matches when false" do
95
+ context 'with :exact option' do
96
+ it 'should accept partial matches when false' do
96
97
  @session.check('Ham', exact: false)
97
98
  @session.click_button('awesome')
98
99
  expect(extract_results(@session)['pets']).to include('hamster')
99
100
  end
100
101
 
101
- it "should not accept partial matches when true" do
102
+ it 'should not accept partial matches when true' do
102
103
  expect do
103
104
  @session.check('Ham', exact: true)
104
105
  end.to raise_error(Capybara::ElementNotFound)
105
106
  end
106
107
  end
107
108
 
108
- context "with `option` option" do
109
- it "can check boxes by their value" do
110
- @session.check('form[pets][]', option: "cat")
109
+ context 'with `option` option' do
110
+ it 'can check boxes by their value' do
111
+ @session.check('form[pets][]', option: 'cat')
111
112
  @session.click_button('awesome')
112
113
  expect(extract_results(@session)['pets']).to include('cat')
113
114
  end
114
115
 
115
- it "should raise an error if option not found" do
116
+ it 'should raise an error if option not found' do
116
117
  expect do
117
- @session.check('form[pets][]', option: "elephant")
118
+ @session.check('form[pets][]', option: 'elephant')
118
119
  end.to raise_error(Capybara::ElementNotFound)
119
120
  end
120
121
  end
121
122
 
122
- context "when checkbox hidden" do
123
- context "with Capybara.automatic_label_click == true" do
123
+ context 'when checkbox hidden' do
124
+ context 'with Capybara.automatic_label_click == true' do
124
125
  around do |spec|
125
126
  old_click_label, Capybara.automatic_label_click = Capybara.automatic_label_click, true
126
127
  spec.run
127
128
  Capybara.automatic_label_click = old_click_label
128
129
  end
129
130
 
130
- it "should check via clicking the label with :for attribute if possible" do
131
+ it 'should check via clicking the label with :for attribute if possible' do
131
132
  expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be_truthy
132
133
  @session.check('form_cars_tesla')
133
134
  @session.click_button('awesome')
134
135
  expect(extract_results(@session)['cars']).to include('tesla')
135
136
  end
136
137
 
137
- it "should check via clicking the wrapping label if possible" do
138
+ it 'should check via clicking the wrapping label if possible' do
138
139
  expect(@session.find(:checkbox, 'form_cars_mclaren', unchecked: true, visible: :hidden)).to be_truthy
139
140
  @session.check('form_cars_mclaren')
140
141
  @session.click_button('awesome')
141
142
  expect(extract_results(@session)['cars']).to include('mclaren')
142
143
  end
143
144
 
144
- it "should not click the label if unneeded" do
145
+ it 'should not click the label if unneeded' do
145
146
  expect(@session.find(:checkbox, 'form_cars_jaguar', checked: true, visible: :hidden)).to be_truthy
146
147
  @session.check('form_cars_jaguar')
147
148
  @session.click_button('awesome')
148
149
  expect(extract_results(@session)['cars']).to include('jaguar')
149
150
  end
150
151
 
151
- it "should raise original error when no label available" do
152
- expect { @session.check('form_cars_ariel') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_ariel" that is not disabled')
152
+ it 'should raise original error when no label available' do
153
+ expect { @session.check('form_cars_ariel') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_ariel"')
153
154
  end
154
155
 
155
- it "should raise error if not allowed to click label" do
156
- expect { @session.check('form_cars_mclaren', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren" that is not disabled')
156
+ it 'should raise error if not allowed to click label' do
157
+ expect { @session.check('form_cars_mclaren', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren"')
157
158
  end
158
159
  end
159
160
 
160
- context "with Capybara.automatic_label_click == false" do
161
+ context 'with Capybara.automatic_label_click == false' do
161
162
  around do |spec|
162
163
  old_label_click, Capybara.automatic_label_click = Capybara.automatic_label_click, false
163
164
  spec.run
164
165
  Capybara.automatic_label_click = old_label_click
165
166
  end
166
167
 
167
- it "should raise error if checkbox not visible" do
168
- expect { @session.check('form_cars_mclaren') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren" that is not disabled')
168
+ it 'should raise error if checkbox not visible' do
169
+ expect { @session.check('form_cars_mclaren') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren"')
170
+ end
171
+
172
+ it 'should include node filter in error if verified' do
173
+ expect { @session.check('form_cars_maserati') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_maserati" that is not disabled')
169
174
  end
170
175
 
171
- context "with allow_label_click == true" do
172
- it "should check via the label if input is hidden" do
176
+ context 'with allow_label_click == true' do
177
+ it 'should check via the label if input is hidden' do
173
178
  expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be_truthy
174
179
  @session.check('form_cars_tesla', allow_label_click: true)
175
180
  @session.click_button('awesome')
176
181
  expect(extract_results(@session)['cars']).to include('tesla')
177
182
  end
178
183
 
179
- it "should not wait the full time if label can be clicked" do
184
+ it 'should not wait the full time if label can be clicked' do
180
185
  expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be_truthy
181
186
  start_time = Time.now
182
187
  @session.check('form_cars_tesla', allow_label_click: true, wait: 10)
@@ -184,7 +189,7 @@ Capybara::SpecHelper.spec "#check" do
184
189
  expect(end_time - start_time).to be < 10
185
190
  end
186
191
 
187
- it "should check via the label if input is moved off the left edge of the page" do
192
+ it 'should check via the label if input is moved off the left edge of the page' do
188
193
  expect(@session.find(:checkbox, 'form_cars_pagani', unchecked: true, visible: :all)).to be_truthy
189
194
  @session.check('form_cars_pagani', allow_label_click: true)
190
195
  @session.click_button('awesome')