capybara 2.9.2 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +10 -1
  3. data/README.md +34 -27
  4. data/lib/capybara.rb +2 -2
  5. data/lib/capybara/node/actions.rb +3 -3
  6. data/lib/capybara/node/base.rb +2 -2
  7. data/lib/capybara/node/element.rb +1 -1
  8. data/lib/capybara/node/finders.rb +37 -32
  9. data/lib/capybara/node/matchers.rb +187 -171
  10. data/lib/capybara/queries/selector_query.rb +11 -14
  11. data/lib/capybara/rack_test/driver.rb +3 -3
  12. data/lib/capybara/rails.rb +1 -1
  13. data/lib/capybara/rspec/features.rb +1 -1
  14. data/lib/capybara/rspec/matchers.rb +31 -22
  15. data/lib/capybara/selector.rb +2 -2
  16. data/lib/capybara/selector/selector.rb +22 -0
  17. data/lib/capybara/session.rb +4 -4
  18. data/lib/capybara/spec/session/accept_alert_spec.rb +4 -4
  19. data/lib/capybara/spec/session/accept_confirm_spec.rb +1 -1
  20. data/lib/capybara/spec/session/accept_prompt_spec.rb +5 -5
  21. data/lib/capybara/spec/session/all_spec.rb +27 -27
  22. data/lib/capybara/spec/session/assert_current_path.rb +2 -2
  23. data/lib/capybara/spec/session/assert_selector.rb +28 -28
  24. data/lib/capybara/spec/session/assert_text.rb +20 -20
  25. data/lib/capybara/spec/session/assert_title.rb +2 -2
  26. data/lib/capybara/spec/session/attach_file_spec.rb +2 -2
  27. data/lib/capybara/spec/session/check_spec.rb +5 -5
  28. data/lib/capybara/spec/session/choose_spec.rb +4 -4
  29. data/lib/capybara/spec/session/click_button_spec.rb +18 -5
  30. data/lib/capybara/spec/session/click_link_or_button_spec.rb +6 -6
  31. data/lib/capybara/spec/session/click_link_spec.rb +13 -13
  32. data/lib/capybara/spec/session/current_url_spec.rb +2 -2
  33. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
  34. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -1
  35. data/lib/capybara/spec/session/element/matches_selector_spec.rb +15 -8
  36. data/lib/capybara/spec/session/evaluate_script_spec.rb +1 -1
  37. data/lib/capybara/spec/session/execute_script_spec.rb +2 -2
  38. data/lib/capybara/spec/session/fill_in_spec.rb +30 -30
  39. data/lib/capybara/spec/session/find_button_spec.rb +5 -5
  40. data/lib/capybara/spec/session/find_by_id_spec.rb +2 -2
  41. data/lib/capybara/spec/session/find_field_spec.rb +11 -7
  42. data/lib/capybara/spec/session/find_link_spec.rb +2 -2
  43. data/lib/capybara/spec/session/find_spec.rb +52 -48
  44. data/lib/capybara/spec/session/first_spec.rb +9 -9
  45. data/lib/capybara/spec/session/go_back_spec.rb +1 -1
  46. data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
  47. data/lib/capybara/spec/session/has_button_spec.rb +12 -12
  48. data/lib/capybara/spec/session/has_css_spec.rb +73 -73
  49. data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
  50. data/lib/capybara/spec/session/has_field_spec.rb +78 -68
  51. data/lib/capybara/spec/session/has_link_spec.rb +8 -8
  52. data/lib/capybara/spec/session/has_select_spec.rb +70 -61
  53. data/lib/capybara/spec/session/has_selector_spec.rb +28 -28
  54. data/lib/capybara/spec/session/has_text_spec.rb +6 -6
  55. data/lib/capybara/spec/session/has_title_spec.rb +2 -2
  56. data/lib/capybara/spec/session/has_xpath_spec.rb +26 -26
  57. data/lib/capybara/spec/session/headers.rb +1 -1
  58. data/lib/capybara/spec/session/html_spec.rb +3 -3
  59. data/lib/capybara/spec/session/node_spec.rb +15 -15
  60. data/lib/capybara/spec/session/reset_session_spec.rb +4 -4
  61. data/lib/capybara/spec/session/response_code.rb +1 -1
  62. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +3 -3
  63. data/lib/capybara/spec/session/screenshot_spec.rb +1 -1
  64. data/lib/capybara/spec/session/select_spec.rb +30 -30
  65. data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
  66. data/lib/capybara/spec/session/unselect_spec.rb +14 -14
  67. data/lib/capybara/spec/session/visit_spec.rb +2 -2
  68. data/lib/capybara/spec/session/within_frame_spec.rb +2 -2
  69. data/lib/capybara/spec/session/within_spec.rb +6 -6
  70. data/lib/capybara/spec/spec_helper.rb +1 -1
  71. data/lib/capybara/spec/test_app.rb +1 -1
  72. data/lib/capybara/spec/views/form.erb +1 -0
  73. data/lib/capybara/version.rb +1 -1
  74. data/spec/basic_node_spec.rb +5 -5
  75. data/spec/capybara_spec.rb +1 -1
  76. data/spec/dsl_spec.rb +1 -1
  77. data/spec/rack_test_spec.rb +7 -7
  78. data/spec/rspec/matchers_spec.rb +6 -6
  79. data/spec/rspec_spec.rb +1 -1
  80. data/spec/selector_spec.rb +13 -0
  81. data/spec/selenium_firefox_spec.rb +1 -1
  82. data/spec/selenium_spec_chrome.rb +1 -1
  83. data/spec/shared_selenium_session.rb +10 -10
  84. metadata +2 -2
@@ -85,13 +85,13 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
85
85
  should_be_on 0, "/landed"
86
86
  end
87
87
 
88
- it "is affected by pushState", :requires => [:js] do
88
+ it "is affected by pushState", requires: [:js] do
89
89
  @session.visit("/with_js")
90
90
  @session.execute_script("window.history.pushState({}, '', '/pushed')")
91
91
  expect(@session.current_path).to eq("/pushed")
92
92
  end
93
93
 
94
- it "is affected by replaceState", :requires => [:js] do
94
+ it "is affected by replaceState", requires: [:js] do
95
95
  @session.visit("/with_js")
96
96
  @session.execute_script("window.history.replaceState({}, '', '/replaced')")
97
97
  expect(@session.current_path).to eq("/replaced")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- Capybara::SpecHelper.spec '#dismiss_confirm', :requires => [:modals] do
2
+ Capybara::SpecHelper.spec '#dismiss_confirm', requires: [:modals] do
3
3
  before do
4
4
  @session.visit('/with_js')
5
5
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- Capybara::SpecHelper.spec '#dismiss_prompt', :requires => [:modals] do
2
+ Capybara::SpecHelper.spec '#dismiss_prompt', requires: [:modals] do
3
3
  before do
4
4
  @session.visit('/with_js')
5
5
  end
@@ -24,8 +24,8 @@ Capybara::SpecHelper.spec '#match_selector?' do
24
24
 
25
25
  context "with text" do
26
26
  it "should discard all matches where the given string is not contained" do
27
- expect(@element).to match_selector("//span", :text => "42")
28
- expect(@element).not_to match_selector("//span", :text => "Doesnotexist")
27
+ expect(@element).to match_selector("//span", text: "42")
28
+ expect(@element).not_to match_selector("//span", text: "Doesnotexist")
29
29
  end
30
30
  end
31
31
 
@@ -48,6 +48,13 @@ Capybara::SpecHelper.spec '#match_selector?' do
48
48
  cbox = @session.find(:css, '#form_pets_dog')
49
49
  expect(cbox.matches_selector?(:checkbox, id: 'form_pets_dog', option: 'dog', name: 'form[pets][]', checked: true)).to be true
50
50
  end
51
+
52
+ it 'should accept a custom filter block' do
53
+ @session.visit('/form')
54
+ cbox = @session.find(:css, '#form_pets_dog')
55
+ expect(cbox.matches_selector?(:checkbox){ |node| node[:id] == "form_pets_dog"}).to be true
56
+ expect(cbox.matches_selector?(:checkbox){ |node| node[:id] != "form_pets_dog"}).to be false
57
+ end
51
58
  end
52
59
 
53
60
  Capybara::SpecHelper.spec '#not_matches_selector?' do
@@ -76,22 +83,22 @@ Capybara::SpecHelper.spec '#not_matches_selector?' do
76
83
 
77
84
  context "with text" do
78
85
  it "should discard all matches where the given string is contained" do
79
- expect(@element).not_to not_match_selector(:css, "span.number", :text => "42")
80
- expect(@element).to not_match_selector(:css, "span.number", :text => "Doesnotexist")
86
+ expect(@element).not_to not_match_selector(:css, "span.number", text: "42")
87
+ expect(@element).to not_match_selector(:css, "span.number", text: "Doesnotexist")
81
88
  end
82
89
  end
83
90
 
84
91
  it "should have CSS sugar" do
85
92
  expect(@element.not_matches_css?("span.number")).to be false
86
93
  expect(@element.not_matches_css?("p a#doesnotexist")).to be true
87
- expect(@element.not_matches_css?("span.number", :text => "42")).to be false
88
- expect(@element.not_matches_css?("span.number", :text => "Doesnotexist")).to be true
94
+ expect(@element.not_matches_css?("span.number", text: "42")).to be false
95
+ expect(@element.not_matches_css?("span.number", text: "Doesnotexist")).to be true
89
96
  end
90
97
 
91
98
  it "should have xpath sugar" do
92
99
  expect(@element.not_matches_xpath?("//span")).to be false
93
100
  expect(@element.not_matches_xpath?("//div")).to be true
94
- expect(@element.not_matches_xpath?("//span", :text => "42")).to be false
95
- expect(@element.not_matches_xpath?("//span", :text => "Doesnotexist")).to be true
101
+ expect(@element.not_matches_xpath?("//span", text: "42")).to be false
102
+ expect(@element.not_matches_xpath?("//span", text: "Doesnotexist")).to be true
96
103
  end
97
104
  end if Gem::Version.new(RSpec::Expectations::Version::STRING) >= Gem::Version.new('3.1')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- Capybara::SpecHelper.spec "#evaluate_script", :requires => [:js] do
2
+ Capybara::SpecHelper.spec "#evaluate_script", requires: [:js] do
3
3
  it "should evaluate the given script and return whatever it produces" do
4
4
  @session.visit('/with_js')
5
5
  expect(@session.evaluate_script("1+3")).to eq(4)
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
- Capybara::SpecHelper.spec "#execute_script", :requires => [:js] do
2
+ Capybara::SpecHelper.spec "#execute_script", requires: [:js] do
3
3
  it "should execute the given script and return nothing" do
4
4
  @session.visit('/with_js')
5
5
  expect(@session.execute_script("document.getElementById('change').textContent = 'Funky Doodle'")).to be_nil
6
- expect(@session).to have_css('#change', :text => 'Funky Doodle')
6
+ expect(@session).to have_css('#change', text: 'Funky Doodle')
7
7
  end
8
8
 
9
9
  it "should be able to call functions defined in the page" do
@@ -5,97 +5,97 @@ Capybara::SpecHelper.spec "#fill_in" do
5
5
  end
6
6
 
7
7
  it "should fill in a text field by id" do
8
- @session.fill_in('form_first_name', :with => 'Harry')
8
+ @session.fill_in('form_first_name', with: 'Harry')
9
9
  @session.click_button('awesome')
10
10
  expect(extract_results(@session)['first_name']).to eq('Harry')
11
11
  end
12
12
 
13
13
  it "should fill in a text field by name" do
14
- @session.fill_in('form[last_name]', :with => 'Green')
14
+ @session.fill_in('form[last_name]', with: 'Green')
15
15
  @session.click_button('awesome')
16
16
  expect(extract_results(@session)['last_name']).to eq('Green')
17
17
  end
18
18
 
19
19
  it "should fill in a text field by label without for" do
20
- @session.fill_in('First Name', :with => 'Harry')
20
+ @session.fill_in('First Name', with: 'Harry')
21
21
  @session.click_button('awesome')
22
22
  expect(extract_results(@session)['first_name']).to eq('Harry')
23
23
  end
24
24
 
25
25
  it "should fill in a url field by label without for" do
26
- @session.fill_in('Html5 Url', :with => 'http://www.avenueq.com')
26
+ @session.fill_in('Html5 Url', with: 'http://www.avenueq.com')
27
27
  @session.click_button('html5_submit')
28
28
  expect(extract_results(@session)['html5_url']).to eq('http://www.avenueq.com')
29
29
  end
30
30
 
31
31
  it "should fill in a textarea by id" do
32
- @session.fill_in('form_description', :with => 'Texty text')
32
+ @session.fill_in('form_description', with: 'Texty text')
33
33
  @session.click_button('awesome')
34
34
  expect(extract_results(@session)['description']).to eq('Texty text')
35
35
  end
36
36
 
37
37
  it "should fill in a textarea by label" do
38
- @session.fill_in('Description', :with => 'Texty text')
38
+ @session.fill_in('Description', with: 'Texty text')
39
39
  @session.click_button('awesome')
40
40
  expect(extract_results(@session)['description']).to eq('Texty text')
41
41
  end
42
42
 
43
43
  it "should fill in a textarea by name" do
44
- @session.fill_in('form[description]', :with => 'Texty text')
44
+ @session.fill_in('form[description]', with: 'Texty text')
45
45
  @session.click_button('awesome')
46
46
  expect(extract_results(@session)['description']).to eq('Texty text')
47
47
  end
48
48
 
49
49
  it "should fill in a password field by id" do
50
- @session.fill_in('form_password', :with => 'supasikrit')
50
+ @session.fill_in('form_password', with: 'supasikrit')
51
51
  @session.click_button('awesome')
52
52
  expect(extract_results(@session)['password']).to eq('supasikrit')
53
53
  end
54
54
 
55
55
  it "should handle HTML in a textarea" do
56
- @session.fill_in('form_description', :with => 'is <strong>very</strong> secret!')
56
+ @session.fill_in('form_description', with: 'is <strong>very</strong> secret!')
57
57
  @session.click_button('awesome')
58
58
  expect(extract_results(@session)['description']).to eq('is <strong>very</strong> secret!')
59
59
  end
60
60
 
61
61
  it "should handle newlines in a textarea" do
62
- @session.fill_in('form_description', :with => "\nSome text\n")
62
+ @session.fill_in('form_description', with: "\nSome text\n")
63
63
  @session.click_button('awesome')
64
64
  expect(extract_results(@session)['description']).to eq("\r\nSome text\r\n")
65
65
  end
66
66
 
67
67
  it "should fill in a field with a custom type" do
68
- @session.fill_in('Schmooo', :with => 'Schmooo is the game')
68
+ @session.fill_in('Schmooo', with: 'Schmooo is the game')
69
69
  @session.click_button('awesome')
70
70
  expect(extract_results(@session)['schmooo']).to eq('Schmooo is the game')
71
71
  end
72
72
 
73
73
  it "should fill in a field without a type" do
74
- @session.fill_in('Phone', :with => '+1 555 7022')
74
+ @session.fill_in('Phone', with: '+1 555 7022')
75
75
  @session.click_button('awesome')
76
76
  expect(extract_results(@session)['phone']).to eq('+1 555 7022')
77
77
  end
78
78
 
79
79
  it "should fill in a text field respecting its maxlength attribute" do
80
- @session.fill_in('Zipcode', :with => '52071350')
80
+ @session.fill_in('Zipcode', with: '52071350')
81
81
  @session.click_button('awesome')
82
82
  expect(extract_results(@session)['zipcode']).to eq('52071')
83
83
  end
84
84
 
85
85
  it "should fill in a password field by name" do
86
- @session.fill_in('form[password]', :with => 'supasikrit')
86
+ @session.fill_in('form[password]', with: 'supasikrit')
87
87
  @session.click_button('awesome')
88
88
  expect(extract_results(@session)['password']).to eq('supasikrit')
89
89
  end
90
90
 
91
91
  it "should fill in a password field by label" do
92
- @session.fill_in('Password', :with => 'supasikrit')
92
+ @session.fill_in('Password', with: 'supasikrit')
93
93
  @session.click_button('awesome')
94
94
  expect(extract_results(@session)['password']).to eq('supasikrit')
95
95
  end
96
96
 
97
97
  it "should fill in a password field by name" do
98
- @session.fill_in('form[password]', :with => 'supasikrit')
98
+ @session.fill_in('form[password]', with: 'supasikrit')
99
99
  @session.click_button('awesome')
100
100
  expect(extract_results(@session)['password']).to eq('supasikrit')
101
101
  end
@@ -104,39 +104,39 @@ Capybara::SpecHelper.spec "#fill_in" do
104
104
  expect {@session.fill_in 'Name', 'ignu'}.to raise_error(RuntimeError, /with/)
105
105
  end
106
106
 
107
- it "should wait for asynchronous load", :requires => [:js] do
107
+ it "should wait for asynchronous load", requires: [:js] do
108
108
  @session.visit('/with_js')
109
109
  @session.click_link('Click me')
110
- @session.fill_in('new_field', :with => 'Testing...')
110
+ @session.fill_in('new_field', with: 'Testing...')
111
111
  end
112
112
 
113
113
  it "casts to string" do
114
- @session.fill_in(:'form_first_name', :with => :'Harry')
114
+ @session.fill_in(:'form_first_name', with: :'Harry')
115
115
  @session.click_button('awesome')
116
116
  expect(extract_results(@session)['first_name']).to eq('Harry')
117
117
  end
118
118
 
119
119
  it "casts to string if field has maxlength" do
120
- @session.fill_in(:'form_zipcode', :with => 1234567)
120
+ @session.fill_in(:'form_zipcode', with: 1234567)
121
121
  @session.click_button('awesome')
122
122
  expect(extract_results(@session)['zipcode']).to eq('12345')
123
123
  end
124
124
 
125
- context 'on a pre-populated textfield with a reformatting onchange', :requires => [:js] do
125
+ context 'on a pre-populated textfield with a reformatting onchange', requires: [:js] do
126
126
  it 'should only trigger onchange once' do
127
127
  @session.visit('/with_js')
128
- @session.fill_in('with_change_event', :with => 'some value')
128
+ @session.fill_in('with_change_event', with: 'some value')
129
129
  # click outside the field to trigger the change event
130
130
  @session.find(:css, 'body').click
131
- expect(@session.find(:css, '.change_event_triggered', :match => :one)).to have_text 'some value'
131
+ expect(@session.find(:css, '.change_event_triggered', match: :one)).to have_text 'some value'
132
132
  end
133
133
 
134
134
  it 'should trigger change when clearing field' do
135
135
  @session.visit('/with_js')
136
- @session.fill_in('with_change_event', :with => '')
136
+ @session.fill_in('with_change_event', with: '')
137
137
  # click outside the field to trigger the change event
138
138
  @session.find(:css, 'body').click
139
- expect(@session).to have_selector(:css, '.change_event_triggered', :match => :one)
139
+ expect(@session).to have_selector(:css, '.change_event_triggered', match: :one)
140
140
  end
141
141
  end
142
142
 
@@ -146,7 +146,7 @@ Capybara::SpecHelper.spec "#fill_in" do
146
146
  it "should not find a hidden field" do
147
147
  msg = "Unable to find field \"Super Secret\""
148
148
  expect do
149
- @session.fill_in('Super Secret', :with => '777')
149
+ @session.fill_in('Super Secret', with: '777')
150
150
  end.to raise_error(Capybara::ElementNotFound, msg)
151
151
  end
152
152
  end
@@ -155,7 +155,7 @@ Capybara::SpecHelper.spec "#fill_in" do
155
155
  it "should raise an error" do
156
156
  msg = "Unable to find field \"does not exist\""
157
157
  expect do
158
- @session.fill_in('does not exist', :with => 'Blah blah')
158
+ @session.fill_in('does not exist', with: 'Blah blah')
159
159
  end.to raise_error(Capybara::ElementNotFound, msg)
160
160
  end
161
161
  end
@@ -163,21 +163,21 @@ Capybara::SpecHelper.spec "#fill_in" do
163
163
  context "on a disabled field" do
164
164
  it "should raise an error" do
165
165
  expect do
166
- @session.fill_in('Disabled Text Field', :with => 'Blah blah')
166
+ @session.fill_in('Disabled Text Field', with: 'Blah blah')
167
167
  end.to raise_error(Capybara::ElementNotFound)
168
168
  end
169
169
  end
170
170
 
171
171
  context "with :exact option" do
172
172
  it "should accept partial matches when false" do
173
- @session.fill_in("Explanation", :with => "Dude", :exact => false)
173
+ @session.fill_in("Explanation", with: "Dude", exact: false)
174
174
  @session.click_button("awesome")
175
175
  expect(extract_results(@session)["name_explanation"]).to eq("Dude")
176
176
  end
177
177
 
178
178
  it "should not accept partial matches when true" do
179
179
  expect do
180
- @session.fill_in("Explanation", :with => "Dude", :exact => true)
180
+ @session.fill_in("Explanation", with: "Dude", exact: true)
181
181
  end.to raise_error(Capybara::ElementNotFound)
182
182
  end
183
183
  end
@@ -33,24 +33,24 @@ Capybara::SpecHelper.spec '#find_button' do
33
33
 
34
34
  context "with :exact option" do
35
35
  it "should accept partial matches when false" do
36
- expect(@session.find_button('What an Awesome', :exact => false).value).to eq("awesome")
36
+ expect(@session.find_button('What an Awesome', exact: false).value).to eq("awesome")
37
37
  end
38
38
 
39
39
  it "should not accept partial matches when true" do
40
40
  expect do
41
- @session.find_button('What an Awesome', :exact => true)
41
+ @session.find_button('What an Awesome', exact: true)
42
42
  end.to raise_error(Capybara::ElementNotFound)
43
43
  end
44
44
  end
45
45
 
46
46
  context "with :disabled option" do
47
47
  it "should find disabled buttons when true" do
48
- expect(@session.find_button('Disabled button', :disabled => true).value).to eq("Disabled button")
48
+ expect(@session.find_button('Disabled button', disabled: true).value).to eq("Disabled button")
49
49
  end
50
50
 
51
51
  it "should not find disabled buttons when false" do
52
52
  expect do
53
- @session.find_button('Disabled button', :disabled => false)
53
+ @session.find_button('Disabled button', disabled: false)
54
54
  end.to raise_error(Capybara::ElementNotFound)
55
55
  end
56
56
 
@@ -61,7 +61,7 @@ Capybara::SpecHelper.spec '#find_button' do
61
61
  end
62
62
 
63
63
  it "should find disabled buttons when :all" do
64
- expect(@session.find_button('Disabled button', :disabled => :all).value).to eq("Disabled button")
64
+ expect(@session.find_button('Disabled button', disabled: :all).value).to eq("Disabled button")
65
65
  end
66
66
  end
67
67
 
@@ -20,12 +20,12 @@ Capybara::SpecHelper.spec '#find_by_id' do
20
20
 
21
21
  context "with :visible option" do
22
22
  it "finds invisible elements when `false`" do
23
- expect(@session.find_by_id("hidden_via_ancestor", :visible => false).text(:all)).to match(/with hidden ancestor/)
23
+ expect(@session.find_by_id("hidden_via_ancestor", visible: false).text(:all)).to match(/with hidden ancestor/)
24
24
  end
25
25
 
26
26
  it "finds invisible elements when `false`" do
27
27
  expect do
28
- @session.find_by_id("hidden_via_ancestor", :visible => true)
28
+ @session.find_by_id("hidden_via_ancestor", visible: true)
29
29
  end.to raise_error(Capybara::ElementNotFound)
30
30
  end
31
31
  end
@@ -8,7 +8,6 @@ Capybara::SpecHelper.spec '#find_field' do
8
8
  expect(@session.find_field('Dog').value).to eq('dog')
9
9
  expect(@session.find_field('form_description').text).to eq('Descriptive text goes here')
10
10
  expect(@session.find_field('Region')[:name]).to eq('form[region]')
11
-
12
11
  end
13
12
 
14
13
  context "aria_label attribute with Capybara.enable_aria_label" do
@@ -50,24 +49,24 @@ Capybara::SpecHelper.spec '#find_field' do
50
49
 
51
50
  context "with :exact option" do
52
51
  it "should accept partial matches when false" do
53
- expect(@session.find_field("Explanation", :exact => false)[:name]).to eq("form[name_explanation]")
52
+ expect(@session.find_field("Explanation", exact: false)[:name]).to eq("form[name_explanation]")
54
53
  end
55
54
 
56
55
  it "should not accept partial matches when true" do
57
56
  expect do
58
- @session.find_field("Explanation", :exact => true)
57
+ @session.find_field("Explanation", exact: true)
59
58
  end.to raise_error(Capybara::ElementNotFound)
60
59
  end
61
60
  end
62
61
 
63
62
  context "with :disabled option" do
64
63
  it "should find disabled fields when true" do
65
- expect(@session.find_field("Disabled Checkbox", :disabled => true)[:name]).to eq("form[disabled_checkbox]")
64
+ expect(@session.find_field("Disabled Checkbox", disabled: true)[:name]).to eq("form[disabled_checkbox]")
66
65
  end
67
66
 
68
67
  it "should not find disabled fields when false" do
69
68
  expect do
70
- @session.find_field("Disabled Checkbox", :disabled => false)
69
+ @session.find_field("Disabled Checkbox", disabled: false)
71
70
  end.to raise_error(Capybara::ElementNotFound)
72
71
  end
73
72
 
@@ -78,11 +77,11 @@ Capybara::SpecHelper.spec '#find_field' do
78
77
  end
79
78
 
80
79
  it "should find disabled fields when :all" do
81
- expect(@session.find_field("Disabled Checkbox", :disabled => :all)[:name]).to eq("form[disabled_checkbox]")
80
+ expect(@session.find_field("Disabled Checkbox", disabled: :all)[:name]).to eq("form[disabled_checkbox]")
82
81
  end
83
82
 
84
83
  it "should find enabled fields when :all" do
85
- expect(@session.find_field('Dog', :disabled => :all).value).to eq('dog')
84
+ expect(@session.find_field('Dog', disabled: :all).value).to eq('dog')
86
85
  end
87
86
  end
88
87
 
@@ -107,4 +106,9 @@ Capybara::SpecHelper.spec '#find_field' do
107
106
  expect(@session.find_field(with: 'dog')['id']).to eq "form_pets_dog"
108
107
  end
109
108
  end
109
+
110
+ it "should accept an optional filter block" do
111
+ # this would be better done with the :with option but this is just a test
112
+ expect(@session.find_field('form[pets][]'){ |node| node.value == 'dog' }[:id]).to eq "form_pets_dog"
113
+ end
110
114
  end
@@ -33,12 +33,12 @@ Capybara::SpecHelper.spec '#find_link' do
33
33
 
34
34
  context "with :exact option" do
35
35
  it "should accept partial matches when false" do
36
- expect(@session.find_link('abo', :exact => false).text).to eq("labore")
36
+ expect(@session.find_link('abo', exact: false).text).to eq("labore")
37
37
  end
38
38
 
39
39
  it "should not accept partial matches when true" do
40
40
  expect do
41
- @session.find_link('abo', :exact => true)
41
+ @session.find_link('abo', exact: true)
42
42
  end.to raise_error(Capybara::ElementNotFound)
43
43
  end
44
44
  end
@@ -14,15 +14,15 @@ Capybara::SpecHelper.spec '#find' do
14
14
  end
15
15
 
16
16
  it "should find the first element using the given locator and options" do
17
- expect(@session.find('//a', :text => 'Redirect')[:id]).to eq('red')
18
- expect(@session.find(:css, 'a', :text => 'A link came first')[:title]).to eq('twas a fine link')
17
+ expect(@session.find('//a', text: 'Redirect')[:id]).to eq('red')
18
+ expect(@session.find(:css, 'a', text: 'A link came first')[:title]).to eq('twas a fine link')
19
19
  end
20
20
 
21
21
  it "should raise an error if there are multiple matches" do
22
22
  expect { @session.find('//a') }.to raise_error(Capybara::Ambiguous)
23
23
  end
24
24
 
25
- it "should wait for asynchronous load", :requires => [:js] do
25
+ it "should wait for asynchronous load", requires: [:js] do
26
26
  @session.visit('/with_js')
27
27
  @session.click_link('Click me')
28
28
  expect(@session.find(:css, "a#has-been-clicked").text).to include('Has been clicked')
@@ -34,12 +34,12 @@ Capybara::SpecHelper.spec '#find' do
34
34
  end
35
35
  end
36
36
 
37
- context "with :wait option", :requires => [:js] do
37
+ context "with :wait option", requires: [:js] do
38
38
  it "should not wait for asynchronous load when `false` given" do
39
39
  @session.visit('/with_js')
40
40
  @session.click_link('Click me')
41
41
  expect do
42
- @session.find(:css, "a#has-been-clicked", :wait => false)
42
+ @session.find(:css, "a#has-been-clicked", wait: false)
43
43
  end.to raise_error(Capybara::ElementNotFound)
44
44
  end
45
45
 
@@ -47,18 +47,18 @@ Capybara::SpecHelper.spec '#find' do
47
47
  @session.visit('/with_js')
48
48
  @session.click_link('Slowly')
49
49
  expect do
50
- @session.find(:css, "a#slow-clicked", :wait => 0.2)
50
+ @session.find(:css, "a#slow-clicked", wait: 0.2)
51
51
  end.to raise_error(Capybara::ElementNotFound)
52
52
  end
53
53
 
54
54
  it "should find element if it appears before given wait duration" do
55
55
  @session.visit('/with_js')
56
56
  @session.click_link('Click me')
57
- expect(@session.find(:css, "a#has-been-clicked", :wait => 0.9).text).to include('Has been clicked')
57
+ expect(@session.find(:css, "a#has-been-clicked", wait: 0.9).text).to include('Has been clicked')
58
58
  end
59
59
  end
60
60
 
61
- context "with frozen time", :requires => [:js] do
61
+ context "with frozen time", requires: [:js] do
62
62
  if defined?(Process::CLOCK_MONOTONIC)
63
63
  it "will time out even if time is frozen" do
64
64
  @session.visit('/with_js')
@@ -126,8 +126,8 @@ Capybara::SpecHelper.spec '#find' do
126
126
  end
127
127
 
128
128
  it "should find elements that match the filter" do
129
- expect(@session.find(:beatle, 'Paul', :type => 'drummer').text).to eq('Paul')
130
- expect(@session.find(:beatle, 'Ringo', :type => 'drummer').text).to eq('Ringo')
129
+ expect(@session.find(:beatle, 'Paul', type: 'drummer').text).to eq('Paul')
130
+ expect(@session.find(:beatle, 'Ringo', type: 'drummer').text).to eq('Ringo')
131
131
  end
132
132
 
133
133
  it "ignores filter when it is not given" do
@@ -136,8 +136,8 @@ Capybara::SpecHelper.spec '#find' do
136
136
  end
137
137
 
138
138
  it "should not find elements that don't match the filter" do
139
- expect { @session.find(:beatle, 'John', :type => 'drummer') }.to raise_error(Capybara::ElementNotFound)
140
- expect { @session.find(:beatle, 'George', :type => 'drummer') }.to raise_error(Capybara::ElementNotFound)
139
+ expect { @session.find(:beatle, 'John', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
140
+ expect { @session.find(:beatle, 'George', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
141
141
  end
142
142
  end
143
143
 
@@ -145,13 +145,13 @@ Capybara::SpecHelper.spec '#find' do
145
145
  before do
146
146
  Capybara.add_selector(:beatle) do
147
147
  xpath { |name| ".//li[contains(@class, 'beatle')][contains(text(), '#{name}')]" }
148
- filter(:type, :default => "drummer") { |node, type| node[:class].split(/\s+/).include?(type) }
148
+ filter(:type, default: "drummer") { |node, type| node[:class].split(/\s+/).include?(type) }
149
149
  end
150
150
  end
151
151
 
152
152
  it "should find elements that match the filter" do
153
- expect(@session.find(:beatle, 'Paul', :type => 'drummer').text).to eq('Paul')
154
- expect(@session.find(:beatle, 'Ringo', :type => 'drummer').text).to eq('Ringo')
153
+ expect(@session.find(:beatle, 'Paul', type: 'drummer').text).to eq('Paul')
154
+ expect(@session.find(:beatle, 'Ringo', type: 'drummer').text).to eq('Ringo')
155
155
  end
156
156
 
157
157
  it "should use default value when filter is not given" do
@@ -160,8 +160,8 @@ Capybara::SpecHelper.spec '#find' do
160
160
  end
161
161
 
162
162
  it "should not find elements that don't match the filter" do
163
- expect { @session.find(:beatle, 'John', :type => 'drummer') }.to raise_error(Capybara::ElementNotFound)
164
- expect { @session.find(:beatle, 'George', :type => 'drummer') }.to raise_error(Capybara::ElementNotFound)
163
+ expect { @session.find(:beatle, 'John', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
164
+ expect { @session.find(:beatle, 'George', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
165
165
  end
166
166
  end
167
167
 
@@ -216,15 +216,15 @@ Capybara::SpecHelper.spec '#find' do
216
216
 
217
217
  context "with :exact option" do
218
218
  it "matches exactly when true" do
219
- expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => true).value).to eq("monkey")
219
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: true).value).to eq("monkey")
220
220
  expect do
221
- @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :exact => true)
221
+ @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: true)
222
222
  end.to raise_error(Capybara::ElementNotFound)
223
223
  end
224
224
 
225
225
  it "matches loosely when false" do
226
- expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => false).value).to eq("monkey")
227
- expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :exact => false).value).to eq("monkey")
226
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: false).value).to eq("monkey")
227
+ expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: false).value).to eq("monkey")
228
228
  end
229
229
 
230
230
  it "defaults to `Capybara.exact`" do
@@ -247,31 +247,31 @@ Capybara::SpecHelper.spec '#find' do
247
247
  context "when set to `one`" do
248
248
  it "raises an error when multiple matches exist" do
249
249
  expect do
250
- @session.find(:css, ".multiple", :match => :one)
250
+ @session.find(:css, ".multiple", match: :one)
251
251
  end.to raise_error(Capybara::Ambiguous)
252
252
  end
253
253
  it "raises an error even if there the match is exact and the others are inexact" do
254
254
  expect do
255
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :exact => false, :match => :one)
255
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], exact: false, match: :one)
256
256
  end.to raise_error(Capybara::Ambiguous)
257
257
  end
258
258
  it "returns the element if there is only one" do
259
- expect(@session.find(:css, ".singular", :match => :one).text).to eq("singular")
259
+ expect(@session.find(:css, ".singular", match: :one).text).to eq("singular")
260
260
  end
261
261
  it "raises an error if there is no match" do
262
262
  expect do
263
- @session.find(:css, ".does-not-exist", :match => :one)
263
+ @session.find(:css, ".does-not-exist", match: :one)
264
264
  end.to raise_error(Capybara::ElementNotFound)
265
265
  end
266
266
  end
267
267
 
268
268
  context "when set to `first`" do
269
269
  it "returns the first matched element" do
270
- expect(@session.find(:css, ".multiple", :match => :first).text).to eq("multiple one")
270
+ expect(@session.find(:css, ".multiple", match: :first).text).to eq("multiple one")
271
271
  end
272
272
  it "raises an error if there is no match" do
273
273
  expect do
274
- @session.find(:css, ".does-not-exist", :match => :first)
274
+ @session.find(:css, ".does-not-exist", match: :first)
275
275
  end.to raise_error(Capybara::ElementNotFound)
276
276
  end
277
277
  end
@@ -280,25 +280,25 @@ Capybara::SpecHelper.spec '#find' do
280
280
  context "and `exact` set to `false`" do
281
281
  it "raises an error when there are multiple exact matches" do
282
282
  expect do
283
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :smart, :exact => false)
283
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: false)
284
284
  end.to raise_error(Capybara::Ambiguous)
285
285
  end
286
286
  it "finds a single exact match when there also are inexact matches" do
287
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :smart, :exact => false)
287
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: false)
288
288
  expect(result.text).to eq("almost singular")
289
289
  end
290
290
  it "raises an error when there are multiple inexact matches" do
291
291
  expect do
292
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :smart, :exact => false)
292
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: false)
293
293
  end.to raise_error(Capybara::Ambiguous)
294
294
  end
295
295
  it "finds a single inexact match" do
296
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :smart, :exact => false)
296
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: false)
297
297
  expect(result.text).to eq("almost singular but not quite")
298
298
  end
299
299
  it "raises an error if there is no match" do
300
300
  expect do
301
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :smart, :exact => false)
301
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: false)
302
302
  end.to raise_error(Capybara::ElementNotFound)
303
303
  end
304
304
  end
@@ -306,26 +306,26 @@ Capybara::SpecHelper.spec '#find' do
306
306
  context "with `exact` set to `true`" do
307
307
  it "raises an error when there are multiple exact matches" do
308
308
  expect do
309
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :smart, :exact => true)
309
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: true)
310
310
  end.to raise_error(Capybara::Ambiguous)
311
311
  end
312
312
  it "finds a single exact match when there also are inexact matches" do
313
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :smart, :exact => true)
313
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: true)
314
314
  expect(result.text).to eq("almost singular")
315
315
  end
316
316
  it "raises an error when there are multiple inexact matches" do
317
317
  expect do
318
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :smart, :exact => true)
318
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: true)
319
319
  end.to raise_error(Capybara::ElementNotFound)
320
320
  end
321
321
  it "raises an error when there is a single inexact matches" do
322
322
  expect do
323
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :smart, :exact => true)
323
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: true)
324
324
  end.to raise_error(Capybara::ElementNotFound)
325
325
  end
326
326
  it "raises an error if there is no match" do
327
327
  expect do
328
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :smart, :exact => true)
328
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: true)
329
329
  end.to raise_error(Capybara::ElementNotFound)
330
330
  end
331
331
  end
@@ -334,50 +334,50 @@ Capybara::SpecHelper.spec '#find' do
334
334
  context "when set to `prefer_exact`" do
335
335
  context "and `exact` set to `false`" do
336
336
  it "picks the first one when there are multiple exact matches" do
337
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :prefer_exact, :exact => false)
337
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: false)
338
338
  expect(result.text).to eq("multiple one")
339
339
  end
340
340
  it "finds a single exact match when there also are inexact matches" do
341
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :prefer_exact, :exact => false)
341
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: false)
342
342
  expect(result.text).to eq("almost singular")
343
343
  end
344
344
  it "picks the first one when there are multiple inexact matches" do
345
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :prefer_exact, :exact => false)
345
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: false)
346
346
  expect(result.text).to eq("almost singular but not quite")
347
347
  end
348
348
  it "finds a single inexact match" do
349
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :prefer_exact, :exact => false)
349
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: false)
350
350
  expect(result.text).to eq("almost singular but not quite")
351
351
  end
352
352
  it "raises an error if there is no match" do
353
353
  expect do
354
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :prefer_exact, :exact => false)
354
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: false)
355
355
  end.to raise_error(Capybara::ElementNotFound)
356
356
  end
357
357
  end
358
358
 
359
359
  context "with `exact` set to `true`" do
360
360
  it "picks the first one when there are multiple exact matches" do
361
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :prefer_exact, :exact => true)
361
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: true)
362
362
  expect(result.text).to eq("multiple one")
363
363
  end
364
364
  it "finds a single exact match when there also are inexact matches" do
365
- result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :prefer_exact, :exact => true)
365
+ result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: true)
366
366
  expect(result.text).to eq("almost singular")
367
367
  end
368
368
  it "raises an error if there are multiple inexact matches" do
369
369
  expect do
370
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :prefer_exact, :exact => true)
370
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: true)
371
371
  end.to raise_error(Capybara::ElementNotFound)
372
372
  end
373
373
  it "raises an error if there is a single inexact match" do
374
374
  expect do
375
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :prefer_exact, :exact => true)
375
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: true)
376
376
  end.to raise_error(Capybara::ElementNotFound)
377
377
  end
378
378
  it "raises an error if there is no match" do
379
379
  expect do
380
- @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :prefer_exact, :exact => true)
380
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: true)
381
381
  end.to raise_error(Capybara::ElementNotFound)
382
382
  end
383
383
  end
@@ -394,11 +394,15 @@ Capybara::SpecHelper.spec '#find' do
394
394
 
395
395
  it "raises an error when unknown option given" do
396
396
  expect do
397
- @session.find(:css, ".singular", :match => :schmoo)
397
+ @session.find(:css, ".singular", match: :schmoo)
398
398
  end.to raise_error(ArgumentError)
399
399
  end
400
400
  end
401
401
 
402
+ it "supports a custom filter block" do
403
+ expect(@session.find(:css, 'input'){|node| node.disabled? }[:name]).to eq('disabled_text')
404
+ end
405
+
402
406
  context "within a scope" do
403
407
  before do
404
408
  @session.visit('/with_scope')