capybara 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.yard/templates_custom/default/class/html/selectors.erb +38 -0
  3. data/.yard/templates_custom/default/class/html/setup.rb +17 -0
  4. data/.yard/yard_extensions.rb +78 -0
  5. data/.yardopts +1 -0
  6. data/History.md +20 -1
  7. data/README.md +1 -1
  8. data/lib/capybara/helpers.rb +0 -59
  9. data/lib/capybara/node/actions.rb +17 -11
  10. data/lib/capybara/node/finders.rb +10 -1
  11. data/lib/capybara/node/matchers.rb +54 -15
  12. data/lib/capybara/queries/base_query.rb +59 -3
  13. data/lib/capybara/queries/selector_query.rb +22 -16
  14. data/lib/capybara/queries/text_query.rb +12 -11
  15. data/lib/capybara/rack_test/form.rb +2 -1
  16. data/lib/capybara/result.rb +25 -10
  17. data/lib/capybara/rspec/features.rb +3 -2
  18. data/lib/capybara/rspec/matchers.rb +1 -1
  19. data/lib/capybara/selector/filter_set.rb +3 -1
  20. data/lib/capybara/selector/selector.rb +227 -0
  21. data/lib/capybara/selector.rb +277 -175
  22. data/lib/capybara/session.rb +2 -2
  23. data/lib/capybara/spec/session/assert_text.rb +7 -0
  24. data/lib/capybara/spec/session/element/matches_selector_spec.rb +29 -1
  25. data/lib/capybara/spec/session/find_spec.rb +10 -4
  26. data/lib/capybara/spec/session/selectors_spec.rb +12 -0
  27. data/lib/capybara/spec/views/form.erb +11 -0
  28. data/lib/capybara/version.rb +1 -1
  29. data/spec/fixtures/capybara.csv +1 -0
  30. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
  31. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  32. data/spec/rack_test_spec.rb +8 -0
  33. data/spec/result_spec.rb +3 -0
  34. data/spec/selenium_firefox_spec.rb +44 -0
  35. data/spec/selenium_spec_chrome.rb +5 -2
  36. data/spec/{selenium_spec.rb → shared_selenium_session.rb} +9 -43
  37. metadata +10 -3
@@ -1,4 +1,4 @@
1
- Capybara::SpecHelper.spec '#match_xpath?' do
1
+ Capybara::SpecHelper.spec '#match_selector?' do
2
2
  before do
3
3
  @session.visit('/with_html')
4
4
  @element = @session.find('//span', text: '42')
@@ -28,6 +28,20 @@ Capybara::SpecHelper.spec '#match_xpath?' do
28
28
  expect(@element).not_to match_selector("//span", :text => "Doesnotexist")
29
29
  end
30
30
  end
31
+
32
+ it "should have css sugar" do
33
+ expect(@element.matches_css?('span.number')).to be true
34
+ expect(@element.matches_css?('span.not_a_number')).to be false
35
+ expect(@element.matches_css?('span.number', text: "42")).to be true
36
+ expect(@element.matches_css?('span.number', text: "Nope")).to be false
37
+ end
38
+
39
+ it "should have xpath sugar" do
40
+ expect(@element.matches_xpath?("//span")).to be true
41
+ expect(@element.matches_xpath?("//div")).to be false
42
+ expect(@element.matches_xpath?("//span", text: '42')).to be true
43
+ expect(@element.matches_xpath?("//span", text: 'Nope')).to be false
44
+ end
31
45
  end
32
46
 
33
47
  Capybara::SpecHelper.spec '#not_matches_selector?' do
@@ -60,4 +74,18 @@ Capybara::SpecHelper.spec '#not_matches_selector?' do
60
74
  expect(@element).to not_match_selector(:css, "span.number", :text => "Doesnotexist")
61
75
  end
62
76
  end
77
+
78
+ it "should have CSS sugar" do
79
+ expect(@element.not_matches_css?("span.number")).to be false
80
+ expect(@element.not_matches_css?("p a#doesnotexist")).to be true
81
+ expect(@element.not_matches_css?("span.number", :text => "42")).to be false
82
+ expect(@element.not_matches_css?("span.number", :text => "Doesnotexist")).to be true
83
+ end
84
+
85
+ it "should have xpath sugar" do
86
+ expect(@element.not_matches_xpath?("//span")).to be false
87
+ expect(@element.not_matches_xpath?("//div")).to be true
88
+ expect(@element.not_matches_xpath?("//span", :text => "42")).to be false
89
+ expect(@element.not_matches_xpath?("//span", :text => "Doesnotexist")).to be true
90
+ end
63
91
  end if Gem::Version.new(RSpec::Expectations::Version::STRING) >= Gem::Version.new('3.1')
@@ -235,6 +235,12 @@ Capybara::SpecHelper.spec '#find' do
235
235
  Capybara.exact = false
236
236
  @session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")])
237
237
  end
238
+
239
+ it "warns when the option has no effect" do
240
+ expect_any_instance_of(Kernel).to receive(:warn).
241
+ with('The :exact option only has an effect on queries using the XPath#is method. Using it with the query "#test_field" has no effect.')
242
+ @session.find(:css, '#test_field', exact: true)
243
+ end
238
244
  end
239
245
 
240
246
  context "with :match option" do
@@ -292,7 +298,7 @@ Capybara::SpecHelper.spec '#find' do
292
298
  end
293
299
  it "raises an error if there is no match" do
294
300
  expect do
295
- @session.find(:css, ".does-not-exist", :match => :smart, :exact => false)
301
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :smart, :exact => false)
296
302
  end.to raise_error(Capybara::ElementNotFound)
297
303
  end
298
304
  end
@@ -319,7 +325,7 @@ Capybara::SpecHelper.spec '#find' do
319
325
  end
320
326
  it "raises an error if there is no match" do
321
327
  expect do
322
- @session.find(:css, ".does-not-exist", :match => :smart, :exact => true)
328
+ @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :smart, :exact => true)
323
329
  end.to raise_error(Capybara::ElementNotFound)
324
330
  end
325
331
  end
@@ -345,7 +351,7 @@ Capybara::SpecHelper.spec '#find' do
345
351
  end
346
352
  it "raises an error if there is no match" do
347
353
  expect do
348
- @session.find(:css, ".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)
349
355
  end.to raise_error(Capybara::ElementNotFound)
350
356
  end
351
357
  end
@@ -371,7 +377,7 @@ Capybara::SpecHelper.spec '#find' do
371
377
  end
372
378
  it "raises an error if there is no match" do
373
379
  expect do
374
- @session.find(:css, ".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)
375
381
  end.to raise_error(Capybara::ElementNotFound)
376
382
  end
377
383
  end
@@ -45,5 +45,17 @@ Capybara::SpecHelper.spec Capybara::Selector do
45
45
  it "can find specifically by placeholder" do
46
46
  expect(@session.find(:field, placeholder: 'FirstName')['id']).to eq "form_first_name"
47
47
  end
48
+
49
+ it "can find by type" do
50
+ expect(@session.find(:field, 'Confusion', type: 'checkbox')['id']).to eq 'confusion_checkbox'
51
+ expect(@session.find(:field, 'Confusion', type: 'text')['id']).to eq 'confusion_text'
52
+ expect(@session.find(:field, 'Confusion', type: 'textarea')['id']).to eq 'confusion_textarea'
53
+ end
54
+
55
+ it "can find by class" do
56
+ expect(@session.find(:field, class: 'confusion-checkbox')['id']).to eq 'confusion_checkbox'
57
+ expect(@session).to have_selector(:field, class: 'confusion', count: 3)
58
+ expect(@session.find(:field, class: ['confusion','confusion-textarea'])['id']).to eq 'confusion_textarea'
59
+ end
48
60
  end
49
61
  end
@@ -526,4 +526,15 @@ New line after and before textarea tag
526
526
  </p>
527
527
  </form>
528
528
 
529
+ <label>Confusion
530
+ <input type="checkbox" id="confusion_checkbox" class="confusion-checkbox confusion"/>
531
+ </label>
532
+
533
+ <label>Confusion
534
+ <input type="text" id="confusion_text" class="confusion-text confusion"/>
535
+ </label>
536
+
537
+ <label>Confusion
538
+ <textarea id="confusion_textarea" class="confusion confusion-textarea"/>
539
+ </label>
529
540
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Capybara
3
- VERSION = '2.8.0'
3
+ VERSION = '2.9.0'
4
4
  end
@@ -0,0 +1 @@
1
+ test, mime-type, file
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  RSpec.describe Capybara::Selenium::Driver do
5
5
  it "should exit with a non-zero exit status" do
6
- browser = Capybara::Selenium::Driver.new(TestApp).browser
6
+ browser = Capybara::Selenium::Driver.new(TestApp, browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym).browser
7
7
  expect(true).to eq(false)
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  RSpec.describe Capybara::Selenium::Driver do
5
5
  it "should exit with a zero exit status" do
6
- browser = Capybara::Selenium::Driver.new(TestApp).browser
6
+ browser = Capybara::Selenium::Driver.new(TestApp, browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym).browser
7
7
  expect(true).to eq(true)
8
8
  end
9
9
  end
@@ -79,6 +79,14 @@ RSpec.describe Capybara::Session do
79
79
  expect(@session.html).to include('Successfully ignored empty file field.')
80
80
  end
81
81
  end
82
+
83
+ it "should not submit an obsolete mime type" do
84
+ @test_jpg_file_path = File.expand_path('fixtures/capybara.csv', File.dirname(__FILE__))
85
+ @session.visit("/form")
86
+ @session.attach_file "form_document", @test_jpg_file_path
87
+ @session.click_button('Upload Single')
88
+ expect(@session).to have_content("Content-type: text/csv")
89
+ end
82
90
  end
83
91
 
84
92
  describe "#click" do
data/spec/result_spec.rb CHANGED
@@ -81,6 +81,9 @@ RSpec.describe Capybara::Result do
81
81
  expect(result.instance_variable_get('@result_cache').size).to be 1
82
82
 
83
83
  #works for indexed access
84
+ result[0]
85
+ expect(result.instance_variable_get('@result_cache').size).to be 1
86
+
84
87
  result[2]
85
88
  expect(result.instance_variable_get('@result_cache').size).to be 3
86
89
 
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+ require "selenium-webdriver"
4
+ require 'shared_selenium_session'
5
+
6
+ Capybara.register_driver :selenium_focus do |app|
7
+ # profile = Selenium::WebDriver::Firefox::Profile.new
8
+ # profile["focusmanager.testmode"] = true
9
+ # Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile)
10
+ Capybara::Selenium::Driver.new(app, browser: :firefox)
11
+ end
12
+
13
+ module TestSessions
14
+ Selenium = Capybara::Session.new(:selenium_focus, TestApp)
15
+ end
16
+
17
+ skipped_tests = [
18
+ :response_headers,
19
+ :status_code,
20
+ :trigger
21
+ ]
22
+ skipped_tests << :windows if ENV['TRAVIS'] && !ENV['WINDOW_TEST']
23
+
24
+ Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => skipped_tests
25
+
26
+ RSpec.describe "Capybara::Session with firefox" do
27
+ include_examples "Capybara::Session", TestSessions::Selenium, :selenium_focus
28
+ end
29
+
30
+ RSpec.describe Capybara::Selenium::Driver do
31
+ before do
32
+ @driver = Capybara::Selenium::Driver.new(TestApp, browser: :firefox)
33
+ end
34
+
35
+ describe '#quit' do
36
+ it "should reset browser when quit" do
37
+ expect(@driver.browser).to be
38
+ @driver.quit
39
+ #access instance variable directly so we don't create a new browser instance
40
+ expect(@driver.instance_variable_get(:@browser)).to be_nil
41
+ end
42
+ end
43
+ end
44
+
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'spec_helper'
3
3
  require 'selenium-webdriver'
4
-
5
- Selenium::WebDriver::Chrome.driver_path = '/home/travis/chromedriver' if ENV['TRAVIS']
4
+ require 'shared_selenium_session'
6
5
 
7
6
  Capybara.register_driver :selenium_chrome do |app|
8
7
  args = ENV['TRAVIS'] ? ['no-sandbox' ] : []
@@ -18,3 +17,7 @@ Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", :capybar
18
17
  :status_code,
19
18
  :trigger
20
19
  ] unless ENV['TRAVIS'] && (RUBY_PLATFORM == 'java')
20
+
21
+ RSpec.describe "Capybara::Session with chrome" do
22
+ include_examples "Capybara::Session", TestSessions::Chrome, :selenium_chrome
23
+ end
@@ -2,32 +2,12 @@
2
2
  require 'spec_helper'
3
3
  require "selenium-webdriver"
4
4
 
5
- Selenium::WebDriver::Firefox.driver_path = '/home/travis/geckodriver' if ENV['TRAVIS'] && ENV['GECKODRIVER']
5
+ RSpec.shared_examples "Capybara::Session" do |session, mode|
6
+ let(:session) {session}
6
7
 
7
- Capybara.register_driver :selenium_focus do |app|
8
- # profile = Selenium::WebDriver::Firefox::Profile.new
9
- # profile["focusmanager.testmode"] = true
10
- # Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile)
11
- Capybara::Selenium::Driver.new(app, browser: :firefox)
12
- end
13
-
14
- module TestSessions
15
- Selenium = Capybara::Session.new(:selenium_focus, TestApp)
16
- end
17
-
18
- skipped_tests = [
19
- :response_headers,
20
- :status_code,
21
- :trigger
22
- ]
23
- skipped_tests << :windows if ENV['TRAVIS'] && !ENV['WINDOW_TEST']
24
-
25
- Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => skipped_tests
26
-
27
- RSpec.describe Capybara::Session do
28
8
  context 'with selenium driver' do
29
9
  before do
30
- @session = TestSessions::Selenium
10
+ @session = session
31
11
  end
32
12
 
33
13
  describe '#driver' do
@@ -38,7 +18,7 @@ RSpec.describe Capybara::Session do
38
18
 
39
19
  describe '#mode' do
40
20
  it "should remember the mode" do
41
- expect(@session.mode).to eq(:selenium_focus)
21
+ expect(@session.mode).to eq(mode)
42
22
  end
43
23
  end
44
24
 
@@ -61,13 +41,15 @@ RSpec.describe Capybara::Session do
61
41
  end
62
42
 
63
43
  it "should have return code 1 when running selenium_driver_rspec_failure.rb" do
44
+ ENV['SELENIUM_BROWSER'] = @session.driver.options[:browser].to_s
64
45
  `rspec spec/fixtures/selenium_driver_rspec_failure.rb`
65
- expect($?.exitstatus).to be 1
46
+ expect($?.exitstatus).to eq(1)
66
47
  end
67
48
 
68
49
  it "should have return code 0 when running selenium_driver_rspec_success.rb" do
50
+ ENV['SELENIUM_BROWSER'] = @session.driver.options[:browser].to_s
69
51
  `rspec spec/fixtures/selenium_driver_rspec_success.rb`
70
- expect($?.exitstatus).to be 0
52
+ expect($?.exitstatus).to eq(0)
71
53
  end
72
54
  end
73
55
 
@@ -76,7 +58,7 @@ RSpec.describe Capybara::Session do
76
58
  @session.visit('/with_js')
77
59
  @session.click_link('Open alert')
78
60
  @session.accept_alert
79
- expect{@session.driver.browser.switch_to.alert}.to raise_error("No alert is present")
61
+ expect{@session.driver.browser.switch_to.alert}.to raise_error(Selenium::WebDriver::Error::NoAlertPresentError)
80
62
  end
81
63
  end
82
64
 
@@ -136,19 +118,3 @@ RSpec.describe Capybara::Session do
136
118
  end
137
119
  end
138
120
  end
139
-
140
- RSpec.describe Capybara::Selenium::Driver do
141
- before do
142
- @driver = Capybara::Selenium::Driver.new(TestApp, browser: :firefox)
143
- end
144
-
145
- describe '#quit' do
146
- it "should reset browser when quit" do
147
- expect(@driver.browser).to be
148
- @driver.quit
149
- #access instance variable directly so we don't create a new browser instance
150
- expect(@driver.instance_variable_get(:@browser)).to be_nil
151
- end
152
- end
153
- end
154
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Walpole
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain:
12
12
  - gem-public_cert.pem
13
- date: 2016-08-16 00:00:00.000000000 Z
13
+ date: 2016-09-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -245,6 +245,10 @@ executables: []
245
245
  extensions: []
246
246
  extra_rdoc_files: []
247
247
  files:
248
+ - ".yard/templates_custom/default/class/html/selectors.erb"
249
+ - ".yard/templates_custom/default/class/html/setup.rb"
250
+ - ".yard/yard_extensions.rb"
251
+ - ".yardopts"
248
252
  - History.md
249
253
  - License.txt
250
254
  - README.md
@@ -282,6 +286,7 @@ files:
282
286
  - lib/capybara/selector.rb
283
287
  - lib/capybara/selector/filter.rb
284
288
  - lib/capybara/selector/filter_set.rb
289
+ - lib/capybara/selector/selector.rb
285
290
  - lib/capybara/selenium/driver.rb
286
291
  - lib/capybara/selenium/node.rb
287
292
  - lib/capybara/server.rb
@@ -400,6 +405,7 @@ files:
400
405
  - spec/basic_node_spec.rb
401
406
  - spec/capybara_spec.rb
402
407
  - spec/dsl_spec.rb
408
+ - spec/fixtures/capybara.csv
403
409
  - spec/fixtures/selenium_driver_rspec_failure.rb
404
410
  - spec/fixtures/selenium_driver_rspec_success.rb
405
411
  - spec/rack_test_spec.rb
@@ -410,9 +416,10 @@ files:
410
416
  - spec/rspec/views_spec.rb
411
417
  - spec/rspec_spec.rb
412
418
  - spec/selector_spec.rb
413
- - spec/selenium_spec.rb
419
+ - spec/selenium_firefox_spec.rb
414
420
  - spec/selenium_spec_chrome.rb
415
421
  - spec/server_spec.rb
422
+ - spec/shared_selenium_session.rb
416
423
  - spec/spec_helper.rb
417
424
  homepage: https://github.com/jnicklas/capybara
418
425
  licenses: