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
@@ -6,7 +6,7 @@ Capybara::SpecHelper.spec "#unselect" do
6
6
 
7
7
  context "with multiple select" do
8
8
  it "should unselect an option from a select box by id" do
9
- @session.unselect('Commando', :from => 'form_underwear')
9
+ @session.unselect('Commando', from: 'form_underwear')
10
10
  @session.click_button('awesome')
11
11
  expect(extract_results(@session)['underwear']).to include('Briefs', 'Boxerbriefs')
12
12
  expect(extract_results(@session)['underwear']).not_to include('Commando')
@@ -20,27 +20,27 @@ Capybara::SpecHelper.spec "#unselect" do
20
20
  end
21
21
 
22
22
  it "should unselect an option from a select box by label" do
23
- @session.unselect('Commando', :from => 'Underwear')
23
+ @session.unselect('Commando', from: 'Underwear')
24
24
  @session.click_button('awesome')
25
25
  expect(extract_results(@session)['underwear']).to include('Briefs', 'Boxerbriefs')
26
26
  expect(extract_results(@session)['underwear']).not_to include('Commando')
27
27
  end
28
28
 
29
29
  it "should favour exact matches to option labels" do
30
- @session.unselect("Briefs", :from => 'Underwear')
30
+ @session.unselect("Briefs", from: 'Underwear')
31
31
  @session.click_button('awesome')
32
32
  expect(extract_results(@session)['underwear']).to include('Commando', 'Boxerbriefs')
33
33
  expect(extract_results(@session)['underwear']).not_to include('Briefs')
34
34
  end
35
35
 
36
36
  it "should escape quotes" do
37
- @session.unselect("Frenchman's Pantalons", :from => 'Underwear')
37
+ @session.unselect("Frenchman's Pantalons", from: 'Underwear')
38
38
  @session.click_button('awesome')
39
39
  expect(extract_results(@session)['underwear']).not_to include("Frenchman's Pantalons")
40
40
  end
41
41
 
42
42
  it "casts to string" do
43
- @session.unselect(:"Briefs", :from => :'Underwear')
43
+ @session.unselect(:"Briefs", from: :'Underwear')
44
44
  @session.click_button('awesome')
45
45
  expect(extract_results(@session)['underwear']).to include('Commando', 'Boxerbriefs')
46
46
  expect(extract_results(@session)['underwear']).not_to include('Briefs')
@@ -49,7 +49,7 @@ Capybara::SpecHelper.spec "#unselect" do
49
49
 
50
50
  context "with single select" do
51
51
  it "should raise an error" do
52
- expect { @session.unselect("English", :from => 'form_locale') }.to raise_error(Capybara::UnselectNotAllowed)
52
+ expect { @session.unselect("English", from: 'form_locale') }.to raise_error(Capybara::UnselectNotAllowed)
53
53
  end
54
54
  end
55
55
 
@@ -57,7 +57,7 @@ Capybara::SpecHelper.spec "#unselect" do
57
57
  it "should raise an error" do
58
58
  msg = "Unable to find select box \"does not exist\""
59
59
  expect do
60
- @session.unselect('foo', :from => 'does not exist')
60
+ @session.unselect('foo', from: 'does not exist')
61
61
  end.to raise_error(Capybara::ElementNotFound, msg)
62
62
  end
63
63
  end
@@ -66,7 +66,7 @@ Capybara::SpecHelper.spec "#unselect" do
66
66
  it "should raise an error" do
67
67
  msg = "Unable to find option \"Does not Exist\""
68
68
  expect do
69
- @session.unselect('Does not Exist', :from => 'form_underwear')
69
+ @session.unselect('Does not Exist', from: 'form_underwear')
70
70
  end.to raise_error(Capybara::ElementNotFound, msg)
71
71
  end
72
72
  end
@@ -74,19 +74,19 @@ Capybara::SpecHelper.spec "#unselect" do
74
74
  context "with :exact option" do
75
75
  context "when `false`" do
76
76
  it "can match select box approximately" do
77
- @session.unselect("Boxerbriefs", :from => "Under", :exact => false)
77
+ @session.unselect("Boxerbriefs", from: "Under", exact: false)
78
78
  @session.click_button("awesome")
79
79
  expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
80
80
  end
81
81
 
82
82
  it "can match option approximately" do
83
- @session.unselect("Boxerbr", :from => "Underwear", :exact => false)
83
+ @session.unselect("Boxerbr", from: "Underwear", exact: false)
84
84
  @session.click_button("awesome")
85
85
  expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
86
86
  end
87
87
 
88
88
  it "can match option approximately when :from not given" do
89
- @session.unselect("Boxerbr", :exact => false)
89
+ @session.unselect("Boxerbr", exact: false)
90
90
  @session.click_button("awesome")
91
91
  expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
92
92
  end
@@ -95,19 +95,19 @@ Capybara::SpecHelper.spec "#unselect" do
95
95
  context "when `true`" do
96
96
  it "can match select box approximately" do
97
97
  expect do
98
- @session.unselect("Boxerbriefs", :from => "Under", :exact => true)
98
+ @session.unselect("Boxerbriefs", from: "Under", exact: true)
99
99
  end.to raise_error(Capybara::ElementNotFound)
100
100
  end
101
101
 
102
102
  it "can match option approximately" do
103
103
  expect do
104
- @session.unselect("Boxerbr", :from => "Underwear", :exact => true)
104
+ @session.unselect("Boxerbr", from: "Underwear", exact: true)
105
105
  end.to raise_error(Capybara::ElementNotFound)
106
106
  end
107
107
 
108
108
  it "can match option approximately when :from not given" do
109
109
  expect do
110
- @session.unselect("Boxerbr", :exact => true)
110
+ @session.unselect("Boxerbr", exact: true)
111
111
  end.to raise_error(Capybara::ElementNotFound)
112
112
  end
113
113
  end
@@ -27,7 +27,7 @@ Capybara::SpecHelper.spec '#visit' do
27
27
  expect(@session).to have_content('Hello world!')
28
28
  end
29
29
 
30
- it "raises any errors caught inside the server", :requires => [:server] do
30
+ it "raises any errors caught inside the server", requires: [:server] do
31
31
  quietly { @session.visit("/error") }
32
32
  expect do
33
33
  @session.visit("/")
@@ -65,7 +65,7 @@ Capybara::SpecHelper.spec '#visit' do
65
65
  end
66
66
  end
67
67
 
68
- context "without a server", :requires => [:server] do
68
+ context "without a server", requires: [:server] do
69
69
  it "should respect `app_host`" do
70
70
  serverless_session = Capybara::Session.new(@session.mode, nil)
71
71
  Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
2
+ Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
3
3
  before(:each) do
4
4
  @session.visit('/within_frames')
5
5
  end
@@ -58,7 +58,7 @@ Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
58
58
  end
59
59
  end
60
60
 
61
- it "works if the frame is closed", :requires => [:frames, :js] do
61
+ it "works if the frame is closed", requires: [:frames, :js] do
62
62
  @session.within_frame 'parentFrame' do
63
63
  @session.within_frame 'childFrame' do
64
64
  @session.click_link 'Close Window'
@@ -20,7 +20,7 @@ Capybara::SpecHelper.spec '#within' do
20
20
  end
21
21
 
22
22
  it "should accept additional options" do
23
- @session.within(:css, "#for_bar li", :text => 'With Simple HTML') do
23
+ @session.within(:css, "#for_bar li", text: 'With Simple HTML') do
24
24
  @session.click_link('Go')
25
25
  end
26
26
  expect(@session).to have_content('Bar')
@@ -114,7 +114,7 @@ Capybara::SpecHelper.spec '#within' do
114
114
  expect(extract_results(@session)['first_name']).to eq('Peter')
115
115
  @session.visit('/with_scope')
116
116
  @session.within("//li[contains(.,'Bar')]") do
117
- @session.fill_in('First Name', :with => 'Dagobert')
117
+ @session.fill_in('First Name', with: 'Dagobert')
118
118
  @session.click_button('Go')
119
119
  end
120
120
  expect(extract_results(@session)['first_name']).to eq('Dagobert')
@@ -128,7 +128,7 @@ Capybara::SpecHelper.spec '#within_fieldset' do
128
128
 
129
129
  it "should restrict scope to a fieldset given by id" do
130
130
  @session.within_fieldset("villain_fieldset") do
131
- @session.fill_in("Name", :with => 'Goldfinger')
131
+ @session.fill_in("Name", with: 'Goldfinger')
132
132
  @session.click_button("Create")
133
133
  end
134
134
  expect(extract_results(@session)['villain_name']).to eq('Goldfinger')
@@ -136,7 +136,7 @@ Capybara::SpecHelper.spec '#within_fieldset' do
136
136
 
137
137
  it "should restrict scope to a fieldset given by legend" do
138
138
  @session.within_fieldset("Villain") do
139
- @session.fill_in("Name", :with => 'Goldfinger')
139
+ @session.fill_in("Name", with: 'Goldfinger')
140
140
  @session.click_button("Create")
141
141
  end
142
142
  expect(extract_results(@session)['villain_name']).to eq('Goldfinger')
@@ -150,7 +150,7 @@ Capybara::SpecHelper.spec '#within_table' do
150
150
 
151
151
  it "should restrict scope to a fieldset given by id" do
152
152
  @session.within_table("girl_table") do
153
- @session.fill_in("Name", :with => 'Christmas')
153
+ @session.fill_in("Name", with: 'Christmas')
154
154
  @session.click_button("Create")
155
155
  end
156
156
  expect(extract_results(@session)['girl_name']).to eq('Christmas')
@@ -158,7 +158,7 @@ Capybara::SpecHelper.spec '#within_table' do
158
158
 
159
159
  it "should restrict scope to a fieldset given by legend" do
160
160
  @session.within_table("Villain") do
161
- @session.fill_in("Name", :with => 'Quantum')
161
+ @session.fill_in("Name", with: 'Quantum')
162
162
  @session.click_button("Create")
163
163
  end
164
164
  expect(extract_results(@session)['villain_name']).to eq('Quantum')
@@ -19,7 +19,7 @@ module Capybara
19
19
  module SpecHelper
20
20
  class << self
21
21
  def configure(config)
22
- config.filter_run_excluding :requires => method(:filter).to_proc
22
+ config.filter_run_excluding requires: method(:filter).to_proc
23
23
  config.before { Capybara::SpecHelper.reset! }
24
24
  config.after { Capybara::SpecHelper.reset! }
25
25
  # Test in 3.5+ where metadata doesn't autotrigger shared context inclusion - will be only behavior in RSpec 4
@@ -175,5 +175,5 @@ class TestApp < Sinatra::Base
175
175
  end
176
176
 
177
177
  if __FILE__ == $0
178
- Rack::Handler::WEBrick.run TestApp, :Port => 8070
178
+ Rack::Handler::WEBrick.run TestApp, Port: 8070
179
179
  end
@@ -351,6 +351,7 @@ New line after and before textarea tag
351
351
  <button type="submit" id="click_me_123" title="Click Title button" value="click_me">Click me!</button>
352
352
  <button type="submit" name="form[no_value]">No Value!</button>
353
353
  <button id="no_type">No Type!</button>
354
+ <button><img alt="A horse eating hay"/></button>
354
355
  <input type="button" disabled="disabled" value="Disabled button"/>
355
356
  </p>
356
357
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Capybara
3
- VERSION = '2.9.2'
3
+ VERSION = '2.10.0'
4
4
  end
@@ -69,13 +69,13 @@ RSpec.describe Capybara do
69
69
  end
70
70
 
71
71
  it "allows using matchers with text option" do
72
- expect(string).to have_css('h1', :text => 'Totally awesome')
73
- expect(string).not_to have_css('h1', :text => 'Not so awesome')
72
+ expect(string).to have_css('h1', text: 'Totally awesome')
73
+ expect(string).not_to have_css('h1', text: 'Not so awesome')
74
74
  end
75
75
 
76
76
  it "allows finding only visible nodes" do
77
- expect(string.all(:css, '#secret', :visible => true)).to be_empty
78
- expect(string.all(:css, '#secret', :visible => false).size).to eq(1)
77
+ expect(string.all(:css, '#secret', visible: true)).to be_empty
78
+ expect(string.all(:css, '#secret', visible: false).size).to eq(1)
79
79
  end
80
80
 
81
81
  it "allows finding elements and extracting text from them" do
@@ -101,7 +101,7 @@ RSpec.describe Capybara do
101
101
 
102
102
  it "allows finding elements and checking if they are visible" do
103
103
  expect(string.find('//h1')).to be_visible
104
- expect(string.find(:css, "#secret", :visible => false)).not_to be_visible
104
+ expect(string.find(:css, "#secret", visible: false)).not_to be_visible
105
105
  end
106
106
 
107
107
  it "allows finding elements and checking if they are disabled" do
@@ -47,7 +47,7 @@ RSpec.describe Capybara do
47
47
 
48
48
  it "should add a new server" do
49
49
  Capybara.register_server :blob do |app, port, host|
50
- Rack::Handler::WEBrick.run(app, :Host => host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
50
+ Rack::Handler::WEBrick.run(app, Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log::new(nil, 0))
51
51
  end
52
52
  Capybara.server = :blob
53
53
  session = Capybara::Session.new(:selenium, TestApp.dup)
@@ -6,7 +6,7 @@ class TestClass
6
6
  include Capybara::DSL
7
7
  end
8
8
 
9
- Capybara::SpecHelper.run_specs TestClass.new, "DSL", :capybara_skip => [
9
+ Capybara::SpecHelper.run_specs TestClass.new, "DSL", capybara_skip: [
10
10
  :js,
11
11
  :modals,
12
12
  :screenshot,
@@ -5,7 +5,7 @@ module TestSessions
5
5
  RackTest = Capybara::Session.new(:rack_test, TestApp)
6
6
  end
7
7
 
8
- Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", :capybara_skip => [
8
+ Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", capybara_skip: [
9
9
  :js,
10
10
  :modals,
11
11
  :screenshot,
@@ -122,27 +122,27 @@ RSpec.describe Capybara::RackTest::Driver do
122
122
 
123
123
  describe ':headers option' do
124
124
  it 'should always set headers' do
125
- @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
125
+ @driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
126
126
  @driver.visit('/get_header')
127
127
  expect(@driver.html).to include('foobar')
128
128
  end
129
129
 
130
130
  it 'should keep headers on link clicks' do
131
- @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
131
+ @driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
132
132
  @driver.visit('/header_links')
133
133
  @driver.find_xpath('.//a').first.click
134
134
  expect(@driver.html).to include('foobar')
135
135
  end
136
136
 
137
137
  it 'should keep headers on form submit' do
138
- @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
138
+ @driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
139
139
  @driver.visit('/header_links')
140
140
  @driver.find_xpath('.//input').first.click
141
141
  expect(@driver.html).to include('foobar')
142
142
  end
143
143
 
144
144
  it 'should keep headers on redirects' do
145
- @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
145
+ @driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
146
146
  @driver.visit('/get_header_via_redirect')
147
147
  expect(@driver.html).to include('foobar')
148
148
  end
@@ -158,7 +158,7 @@ RSpec.describe Capybara::RackTest::Driver do
158
158
  end
159
159
 
160
160
  it "is possible to not follow redirects" do
161
- @driver = Capybara::RackTest::Driver.new(TestApp, :follow_redirects => false)
161
+ @driver = Capybara::RackTest::Driver.new(TestApp, follow_redirects: false)
162
162
 
163
163
  @driver.visit('/redirect')
164
164
  expect(@driver.response.header['Location']).to match %r{/redirect_again$}
@@ -186,7 +186,7 @@ RSpec.describe Capybara::RackTest::Driver do
186
186
 
187
187
  context "with 21 redirect limit" do
188
188
  before do
189
- @driver = Capybara::RackTest::Driver.new(TestApp, :redirect_limit => 21)
189
+ @driver = Capybara::RackTest::Driver.new(TestApp, redirect_limit: 21)
190
190
  end
191
191
 
192
192
  it "should follow 21 redirects" do
@@ -25,7 +25,7 @@ RSpec.describe Capybara::RSpecMatchers do
25
25
  end
26
26
 
27
27
  it "passes if matched node count equals expected count" do
28
- expect("<h1>Text</h1>").to have_css('h1', :count => 1)
28
+ expect("<h1>Text</h1>").to have_css('h1', count: 1)
29
29
  end
30
30
 
31
31
  it "fails if matched node count does not equal expected count" do
@@ -66,12 +66,12 @@ RSpec.describe Capybara::RSpecMatchers do
66
66
  end
67
67
 
68
68
  it "passes if matched node count does not equal expected count" do
69
- expect("<h1>Text</h1>").not_to have_css('h1', :count => 2)
69
+ expect("<h1>Text</h1>").not_to have_css('h1', count: 2)
70
70
  end
71
71
 
72
72
  it "fails if matched node count equals expected count" do
73
73
  expect do
74
- expect("<h1>Text</h1>").not_to have_css('h1', :count => 1)
74
+ expect("<h1>Text</h1>").not_to have_css('h1', count: 1)
75
75
  end.to raise_error(/expected not to find css "h1"/)
76
76
  end
77
77
  end
@@ -220,7 +220,7 @@ RSpec.describe Capybara::RSpecMatchers do
220
220
 
221
221
  context "with should" do
222
222
  it "passes if has_selector? returns true" do
223
- expect(page).to have_selector('//h1', :text => 'test')
223
+ expect(page).to have_selector('//h1', text: 'test')
224
224
  end
225
225
 
226
226
  it "fails if has_selector? returns false" do
@@ -231,7 +231,7 @@ RSpec.describe Capybara::RSpecMatchers do
231
231
 
232
232
  it "includes text in error message" do
233
233
  expect do
234
- expect(page).to have_selector("//h1", :text => 'wrong text')
234
+ expect(page).to have_selector("//h1", text: 'wrong text')
235
235
  end.to raise_error(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
236
236
  end
237
237
  end
@@ -243,7 +243,7 @@ RSpec.describe Capybara::RSpecMatchers do
243
243
 
244
244
  it "fails if has_no_selector? returns false" do
245
245
  expect do
246
- expect(page).not_to have_selector(:css, 'h1', :text => 'test')
246
+ expect(page).not_to have_selector(:css, 'h1', text: 'test')
247
247
  end.to raise_error(%r(expected not to find css "h1" with text "test"))
248
248
  end
249
249
  end
@@ -29,7 +29,7 @@ RSpec.describe 'capybara/rspec', :type => :feature do
29
29
  end
30
30
  end
31
31
 
32
- it "switches to the javascript driver when giving it as metadata", :js => true do
32
+ it "switches to the javascript driver when giving it as metadata", js: true do
33
33
  expect(Capybara.current_driver).to eq(Capybara.javascript_driver)
34
34
  end
35
35
 
@@ -25,6 +25,7 @@ RSpec.describe Capybara do
25
25
  <label for="my_text_input">My Text Input</label>
26
26
  <input type="text" name="form[my_text_input]" placeholder="my text" id="my_text_input"/>
27
27
  <input type="file" id="file" class=".special file"/>
28
+ <input type="hidden" id="hidden_field" value="this is hidden"/>
28
29
  <a href="#">link</a>
29
30
  <fieldset></fieldset>
30
31
  <select>
@@ -51,6 +52,18 @@ RSpec.describe Capybara do
51
52
  end
52
53
  end
53
54
 
55
+ describe "adding a selector" do
56
+ it "can set default visiblity" do
57
+ Capybara.add_selector :hidden_field do
58
+ visible :hidden
59
+ css { |sel| 'input[type="hidden"]' }
60
+ end
61
+
62
+ expect(string).to have_no_css('input[type="hidden"]')
63
+ expect(string).to have_selector(:hidden_field)
64
+ end
65
+ end
66
+
54
67
  describe "modify_selector" do
55
68
  it "allows modifying a selector" do
56
69
  el = string.find(:custom_selector, 'a')
@@ -21,7 +21,7 @@ skipped_tests = [
21
21
  ]
22
22
  skipped_tests << :windows if ENV['TRAVIS'] && !ENV['WINDOW_TEST']
23
23
 
24
- Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => skipped_tests
24
+ Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", capybara_skip: skipped_tests
25
25
 
26
26
  RSpec.describe "Capybara::Session with firefox" do
27
27
  include_examples "Capybara::Session", TestSessions::Selenium, :selenium_focus
@@ -12,7 +12,7 @@ module TestSessions
12
12
  Chrome = Capybara::Session.new(:selenium_chrome, TestApp)
13
13
  end
14
14
 
15
- Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", :capybara_skip => [
15
+ Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", capybara_skip: [
16
16
  :response_headers,
17
17
  :status_code,
18
18
  :trigger
@@ -62,37 +62,37 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
62
62
  end
63
63
  end
64
64
 
65
- context "#fill_in with { :clear => :backspace } fill_option", :requires => [:js] do
65
+ context "#fill_in with { :clear => :backspace } fill_option", requires: [:js] do
66
66
  it 'should fill in a field, replacing an existing value' do
67
67
  @session.visit('/form')
68
- @session.fill_in('form_first_name', :with => 'Harry',
68
+ @session.fill_in('form_first_name', with: 'Harry',
69
69
  fill_options: { clear: :backspace} )
70
70
  expect(@session.find(:fillable_field, 'form_first_name').value).to eq('Harry')
71
71
  end
72
72
 
73
73
  it 'should only trigger onchange once' do
74
74
  @session.visit('/with_js')
75
- @session.fill_in('with_change_event', :with => 'some value',
76
- :fill_options => { :clear => :backspace })
75
+ @session.fill_in('with_change_event', with: 'some value',
76
+ fill_options: { :clear => :backspace })
77
77
  # click outside the field to trigger the change event
78
78
  @session.find(:css, 'body').click
79
- expect(@session.find(:css, '.change_event_triggered', :match => :one)).to have_text 'some value'
79
+ expect(@session.find(:css, '.change_event_triggered', match: :one)).to have_text 'some value'
80
80
  end
81
81
 
82
82
  it 'should trigger change when clearing field' do
83
83
  @session.visit('/with_js')
84
- @session.fill_in('with_change_event', :with => '',
85
- :fill_options => { :clear => :backspace })
84
+ @session.fill_in('with_change_event', with: '',
85
+ fill_options: { :clear => :backspace })
86
86
  # click outside the field to trigger the change event
87
87
  @session.find(:css, 'body').click
88
- expect(@session).to have_selector(:css, '.change_event_triggered', :match => :one)
88
+ expect(@session).to have_selector(:css, '.change_event_triggered', match: :one)
89
89
  end
90
90
  end
91
91
 
92
92
  context "#fill_in with { clear: :none } fill_options" do
93
93
  it 'should append to content in a field' do
94
94
  @session.visit('/form')
95
- @session.fill_in('form_first_name', :with => 'Harry',
95
+ @session.fill_in('form_first_name', with: 'Harry',
96
96
  fill_options: { clear: :none} )
97
97
  expect(@session.find(:fillable_field, 'form_first_name').value).to eq('JohnHarry')
98
98
  end
@@ -102,7 +102,7 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
102
102
  it 'should pass the array through to the element' do
103
103
  #this is mainly for use with [[:ctrl, 'a'], :backspace] - however since that is platform dependant I'm testing with something less useful
104
104
  @session.visit('/form')
105
- @session.fill_in('form_first_name', :with => 'Harry',
105
+ @session.fill_in('form_first_name', with: 'Harry',
106
106
  fill_options: { clear: [[:shift, 'abc'], :backspace] } )
107
107
  expect(@session.find(:fillable_field, 'form_first_name').value).to eq('JohnABHarry')
108
108
  end