capybara 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +21 -0
  3. data/README.md +50 -12
  4. data/lib/capybara.rb +8 -1
  5. data/lib/capybara/driver/base.rb +28 -0
  6. data/lib/capybara/driver/node.rb +3 -2
  7. data/lib/capybara/helpers.rb +2 -3
  8. data/lib/capybara/node/actions.rb +5 -2
  9. data/lib/capybara/node/base.rb +10 -0
  10. data/lib/capybara/node/document.rb +2 -0
  11. data/lib/capybara/node/document_matchers.rb +68 -0
  12. data/lib/capybara/node/element.rb +17 -2
  13. data/lib/capybara/node/finders.rb +5 -20
  14. data/lib/capybara/node/matchers.rb +101 -71
  15. data/lib/capybara/node/simple.rb +9 -15
  16. data/lib/capybara/queries/base_query.rb +29 -0
  17. data/lib/capybara/queries/text_query.rb +56 -0
  18. data/lib/capybara/queries/title_query.rb +40 -0
  19. data/lib/capybara/query.rb +30 -20
  20. data/lib/capybara/rack_test/node.rb +11 -3
  21. data/lib/capybara/result.rb +1 -1
  22. data/lib/capybara/rspec/features.rb +38 -21
  23. data/lib/capybara/rspec/matchers.rb +53 -38
  24. data/lib/capybara/selector.rb +68 -14
  25. data/lib/capybara/selenium/driver.rb +54 -6
  26. data/lib/capybara/selenium/node.rb +4 -2
  27. data/lib/capybara/session.rb +109 -35
  28. data/lib/capybara/spec/public/test.js +34 -1
  29. data/lib/capybara/spec/session/accept_alert_spec.rb +57 -0
  30. data/lib/capybara/spec/session/accept_confirm_spec.rb +19 -0
  31. data/lib/capybara/spec/session/accept_prompt_spec.rb +49 -0
  32. data/lib/capybara/spec/session/assert_text.rb +195 -0
  33. data/lib/capybara/spec/session/assert_title.rb +69 -0
  34. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +35 -0
  35. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +19 -0
  36. data/lib/capybara/spec/session/find_field_spec.rb +6 -0
  37. data/lib/capybara/spec/session/has_text_spec.rb +1 -1
  38. data/lib/capybara/spec/session/node_spec.rb +16 -1
  39. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +1 -1
  40. data/lib/capybara/spec/session/visit_spec.rb +5 -0
  41. data/lib/capybara/spec/views/with_html.erb +4 -0
  42. data/lib/capybara/spec/views/with_js.erb +17 -0
  43. data/lib/capybara/version.rb +1 -1
  44. data/spec/dsl_spec.rb +3 -1
  45. data/spec/rack_test_spec.rb +12 -1
  46. data/spec/rspec/features_spec.rb +1 -1
  47. data/spec/rspec/matchers_spec.rb +113 -20
  48. data/spec/selenium_spec.rb +10 -1
  49. metadata +13 -2
@@ -7,11 +7,13 @@ end
7
7
 
8
8
  Capybara::SpecHelper.run_specs TestClass.new, "DSL", :capybara_skip => [
9
9
  :js,
10
+ :modals,
10
11
  :screenshot,
11
12
  :frames,
12
13
  :windows,
13
14
  :server,
14
- :hover
15
+ :hover,
16
+ :about_scheme,
15
17
  ]
16
18
 
17
19
  RSpec.describe Capybara::DSL do
@@ -6,11 +6,13 @@ end
6
6
 
7
7
  Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", :capybara_skip => [
8
8
  :js,
9
+ :modals,
9
10
  :screenshot,
10
11
  :frames,
11
12
  :windows,
12
13
  :server,
13
- :hover
14
+ :hover,
15
+ :about_scheme,
14
16
  ]
15
17
 
16
18
  RSpec.describe Capybara::Session do
@@ -57,6 +59,15 @@ RSpec.describe Capybara::Session do
57
59
  @session.driver.options[:respect_data_method] = false
58
60
  end
59
61
  end
62
+
63
+ describe "#fill_in" do
64
+ it "should warn that :fill_options are not supported" do
65
+ expect_any_instance_of(Capybara::Node::Element).to receive(:warn)
66
+ .with("Options passed to Capybara::Node#set but the driver doesn't support them")
67
+ @session.visit "/with_html"
68
+ @session.fill_in 'test_field', with: 'not_moneky', fill_options: { random: true }
69
+ end
70
+ end
60
71
 
61
72
  describe "#attach_file" do
62
73
  context "with multipart form" do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'capybara/rspec'
3
3
 
4
- RSpec.configuration.before(:each, :example_group => {:file_path => "./spec/rspec/features_spec.rb"}) do
4
+ RSpec.configuration.before(:each, { file_path: "./spec/rspec/features_spec.rb" } ) do
5
5
  @in_filtered_hook = true
6
6
  end
7
7
 
@@ -74,6 +74,11 @@ RSpec.describe Capybara::RSpecMatchers do
74
74
  end.to raise_error(/expected not to find css "h1"/)
75
75
  end
76
76
  end
77
+
78
+ it "supports compounding" do
79
+ expect("<h1>Text</h1><h2>Text</h2>").to have_css('h1').and have_css('h2')
80
+ expect("<h1>Text</h1><h2>Text</h2>").to have_css('h3').or have_css('h1')
81
+ end if RSpec::Version::STRING.to_f >= 3.0
77
82
  end
78
83
 
79
84
  context "on a page or node" do
@@ -136,6 +141,11 @@ RSpec.describe Capybara::RSpecMatchers do
136
141
  end.to raise_error(%r(expected not to find xpath "//h1"))
137
142
  end
138
143
  end
144
+
145
+ it "supports compounding" do
146
+ expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h1').and have_xpath('//h2')
147
+ expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h3').or have_xpath('//h1')
148
+ end if RSpec::Version::STRING.to_f >= 3.0
139
149
  end
140
150
 
141
151
  context "on a page or node" do
@@ -237,6 +247,11 @@ RSpec.describe Capybara::RSpecMatchers do
237
247
  end
238
248
  end
239
249
  end
250
+
251
+ it "supports compounding" do
252
+ expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h1').and have_selector('//h2')
253
+ expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h3').or have_selector('//h1')
254
+ end if RSpec::Version::STRING.to_f >= 3.0
240
255
  end
241
256
 
242
257
  describe "have_content matcher" do
@@ -321,6 +336,11 @@ RSpec.describe Capybara::RSpecMatchers do
321
336
  end
322
337
  end
323
338
  end
339
+
340
+ it "supports compounding" do
341
+ expect("<h1>Text</h1><h2>And</h2>").to have_content('Text').and have_content('And')
342
+ expect("<h1>Text</h1><h2>Or</h2>").to have_content('XYZ').or have_content('Or')
343
+ end if RSpec::Version::STRING.to_f >= 3.0
324
344
  end
325
345
 
326
346
  describe "have_text matcher" do
@@ -330,20 +350,26 @@ RSpec.describe Capybara::RSpecMatchers do
330
350
 
331
351
  context "on a string" do
332
352
  context "with should" do
333
- it "passes if has_text? returns true" do
353
+ it "passes if text contains given string" do
334
354
  expect("<h1>Text</h1>").to have_text('Text')
335
355
  end
336
356
 
337
- it "passes if has_text? returns true using regexp" do
357
+ it "passes if text matches given regexp" do
338
358
  expect("<h1>Text</h1>").to have_text(/ext/)
339
359
  end
340
360
 
341
- it "fails if has_text? returns false" do
361
+ it "fails if text doesn't contain given string" do
342
362
  expect do
343
363
  expect("<h1>Text</h1>").to have_text('No such Text')
344
364
  end.to raise_error(/expected to find text "No such Text" in "Text"/)
345
365
  end
346
366
 
367
+ it "fails if text doesn't match given regexp" do
368
+ expect do
369
+ expect("<h1>Text</h1>").to have_text(/No such Text/)
370
+ end.to raise_error('expected to find text matching /No such Text/ in "Text"')
371
+ end
372
+
347
373
  it "casts Fixnum to string" do
348
374
  expect do
349
375
  expect("<h1>Text</h1>").to have_text(3)
@@ -353,30 +379,30 @@ RSpec.describe Capybara::RSpecMatchers do
353
379
  it "fails if matched text count does not equal to expected count" do
354
380
  expect do
355
381
  expect("<h1>Text</h1>").to have_text('Text', count: 2)
356
- end.to raise_error(/expected to find text "Text" 2 times in "Text"/)
382
+ end.to raise_error('expected to find text "Text" 2 times but found 1 time in "Text"')
357
383
  end
358
384
 
359
385
  it "fails if matched text count is less than expected minimum count" do
360
386
  expect do
361
387
  expect("<h1>Text</h1>").to have_text('Lorem', minimum: 1)
362
- end.to raise_error(/expected to find text "Lorem" at least 1 time in "Text"/)
388
+ end.to raise_error('expected to find text "Lorem" at least 1 time but found 0 times in "Text"')
363
389
  end
364
390
 
365
391
  it "fails if matched text count is more than expected maximum count" do
366
392
  expect do
367
393
  expect("<h1>Text TextText</h1>").to have_text('Text', maximum: 2)
368
- end.to raise_error(/expected to find text "Text" at most 2 times in "Text TextText"/)
394
+ end.to raise_error('expected to find text "Text" at most 2 times but found 3 times in "Text TextText"')
369
395
  end
370
396
 
371
397
  it "fails if matched text count does not belong to expected range" do
372
398
  expect do
373
399
  expect("<h1>Text</h1>").to have_text('Text', between: 2..3)
374
- end.to raise_error(/expected to find text "Text" between 2 and 3 times in "Text"/)
400
+ end.to raise_error('expected to find text "Text" between 2 and 3 times but found 1 time in "Text"')
375
401
  end
376
402
  end
377
403
 
378
404
  context "with should_not" do
379
- it "passes if has_no_text? returns true" do
405
+ it "passes if text doesn't contain a string" do
380
406
  expect("<h1>Text</h1>").not_to have_text('No such Text')
381
407
  end
382
408
 
@@ -384,7 +410,7 @@ RSpec.describe Capybara::RSpecMatchers do
384
410
  expect("<h1>Text</h1>").not_to have_text('.')
385
411
  end
386
412
 
387
- it "fails if has_no_text? returns false" do
413
+ it "fails if text contains a string" do
388
414
  expect do
389
415
  expect("<h1>Text</h1>").not_to have_text('Text')
390
416
  end.to raise_error(/expected not to find text "Text" in "Text"/)
@@ -444,10 +470,15 @@ RSpec.describe Capybara::RSpecMatchers do
444
470
  end
445
471
  end
446
472
  end
473
+
474
+ it "supports compounding" do
475
+ expect("<h1>Text</h1><h2>And</h2>").to have_text('Text').and have_text('And')
476
+ expect("<h1>Text</h1><h2>Or</h2>").to have_text('Not here').or have_text('Or')
477
+ end if RSpec::Version::STRING.to_f >= 3.0
447
478
  end
448
479
 
449
480
  describe "have_link matcher" do
450
- let(:html) { '<a href="#">Just a link</a>' }
481
+ let(:html) { '<a href="#">Just a link</a><a href="#">Another link</a>' }
451
482
 
452
483
  it "gives proper description" do
453
484
  expect(have_link('Just a link').description).to eq("have link \"Just a link\"")
@@ -462,6 +493,11 @@ RSpec.describe Capybara::RSpecMatchers do
462
493
  expect(html).to have_link('No such Link')
463
494
  end.to raise_error(/expected to find link "No such Link"/)
464
495
  end
496
+
497
+ it "supports compounding" do
498
+ expect(html).to have_link('Just a link').and have_link('Another link')
499
+ expect(html).to have_link('Not a link').or have_link('Another link')
500
+ end if RSpec::Version::STRING.to_f >= 3.0
465
501
  end
466
502
 
467
503
  describe "have_title matcher" do
@@ -479,25 +515,54 @@ RSpec.describe Capybara::RSpecMatchers do
479
515
  it "fails if there is no such title" do
480
516
  expect do
481
517
  expect(html).to have_title('No such title')
482
- end.to raise_error(/expected there to be title "No such title"/)
518
+ end.to raise_error('expected "Just a title" to include "No such title"')
483
519
  end
484
- end
485
520
 
486
- context "on a page or node" do
487
- before do
488
- visit('/with_js')
521
+ it "fails if title doesn't match regexp" do
522
+ expect do
523
+ expect(html).to have_title(/[[:upper:]]+[[:lower:]]+l{2}o/)
524
+ end.to raise_error('expected "Just a title" to match /[[:upper:]]+[[:lower:]]+l{2}o/')
489
525
  end
526
+ end
490
527
 
528
+ context "on a page or node" do
491
529
  it "passes if there is such a title" do
530
+ visit('/with_js')
492
531
  expect(page).to have_title('with_js')
493
532
  end
494
533
 
495
534
  it "fails if there is no such title" do
535
+ visit('/with_js')
496
536
  expect do
497
537
  expect(page).to have_title('No such title')
498
- end.to raise_error(/expected there to be title "No such title"/)
538
+ end.to raise_error('expected "with_js" to include "No such title"')
539
+ end
540
+
541
+ context 'with wait' do
542
+ before(:each) do
543
+ @session = TestSessions::Selenium
544
+ @session.visit('/with_js')
545
+ end
546
+
547
+ it 'waits if wait time is more than timeout' do
548
+ @session.click_link("Change title")
549
+ using_wait_time 0 do
550
+ expect(@session).to have_title('changed title', wait: 0.5)
551
+ end
552
+ end
553
+
554
+ it "doesn't wait if wait time is less than timeout" do
555
+ @session.click_link("Change title")
556
+ using_wait_time 0 do
557
+ expect(@session).not_to have_title('changed title')
558
+ end
559
+ end
499
560
  end
500
561
  end
562
+
563
+ it "supports compounding" do
564
+ expect("<title>I compound</title>").to have_title('I dont compound').or have_title('I compound')
565
+ end if RSpec::Version::STRING.to_f >= 3.0
501
566
  end
502
567
 
503
568
  describe "have_button matcher" do
@@ -516,6 +581,10 @@ RSpec.describe Capybara::RSpecMatchers do
516
581
  expect(html).to have_button('No such Button')
517
582
  end.to raise_error(/expected to find button "No such Button"/)
518
583
  end
584
+
585
+ it "supports compounding" do
586
+ expect(html).to have_button('Not this button').or have_button('A button')
587
+ end if RSpec::Version::STRING.to_f >= 3.0
519
588
  end
520
589
 
521
590
  describe "have_field matcher" do
@@ -528,7 +597,7 @@ RSpec.describe Capybara::RSpecMatchers do
528
597
  it "gives proper description for a given value" do
529
598
  expect(have_field('Text field', with: 'some value').description).to eq("have field \"Text field\" with value \"some value\"")
530
599
  end
531
-
600
+
532
601
  it "passes if there is such a field" do
533
602
  expect(html).to have_field('Text field')
534
603
  end
@@ -557,6 +626,10 @@ RSpec.describe Capybara::RSpecMatchers do
557
626
  end
558
627
  expect(html).to have_field('Text field', with: Foo.new)
559
628
  end
629
+
630
+ it "supports compounding" do
631
+ expect(html).to have_field('Not this one').or have_field('Text field')
632
+ end if RSpec::Version::STRING.to_f >= 3.0
560
633
  end
561
634
 
562
635
  describe "have_checked_field matcher" do
@@ -566,9 +639,9 @@ RSpec.describe Capybara::RSpecMatchers do
566
639
  end
567
640
 
568
641
  it "gives proper description" do
569
- expect(have_checked_field('it is checked').description).to eq("have field \"it is checked\"")
642
+ expect(have_checked_field('it is checked').description).to eq("have field \"it is checked\" that is checked")
570
643
  end
571
-
644
+
572
645
  context "with should" do
573
646
  it "passes if there is such a field and it is checked" do
574
647
  expect(html).to have_checked_field('it is checked')
@@ -602,6 +675,10 @@ RSpec.describe Capybara::RSpecMatchers do
602
675
  expect(html).not_to have_checked_field('no such field')
603
676
  end
604
677
  end
678
+
679
+ it "supports compounding" do
680
+ expect(html).to have_checked_field('not this one').or have_checked_field('it is checked')
681
+ end if RSpec::Version::STRING.to_f >= 3.0
605
682
  end
606
683
 
607
684
  describe "have_unchecked_field matcher" do
@@ -611,7 +688,7 @@ RSpec.describe Capybara::RSpecMatchers do
611
688
  end
612
689
 
613
690
  it "gives proper description" do
614
- expect(have_unchecked_field('unchecked field').description).to eq("have field \"unchecked field\"")
691
+ expect(have_unchecked_field('unchecked field').description).to eq("have field \"unchecked field\" that is not checked")
615
692
  end
616
693
 
617
694
  context "with should" do
@@ -647,6 +724,10 @@ RSpec.describe Capybara::RSpecMatchers do
647
724
  expect(html).not_to have_unchecked_field('no such field')
648
725
  end
649
726
  end
727
+
728
+ it "supports compounding" do
729
+ expect(html).to have_unchecked_field('it is checked').or have_unchecked_field('unchecked field')
730
+ end if RSpec::Version::STRING.to_f >= 3.0
650
731
  end
651
732
 
652
733
  describe "have_select matcher" do
@@ -655,6 +736,10 @@ RSpec.describe Capybara::RSpecMatchers do
655
736
  it "gives proper description" do
656
737
  expect(have_select('Select Box').description).to eq("have select box \"Select Box\"")
657
738
  end
739
+
740
+ it "gives proper description for a given selected value" do
741
+ expect(have_select('Select Box', selected: 'some value').description).to eq("have select box \"Select Box\" with \"some value\" selected")
742
+ end
658
743
 
659
744
  it "passes if there is such a select" do
660
745
  expect(html).to have_select('Select Box')
@@ -665,6 +750,10 @@ RSpec.describe Capybara::RSpecMatchers do
665
750
  expect(html).to have_select('No such Select box')
666
751
  end.to raise_error(/expected to find select box "No such Select box"/)
667
752
  end
753
+
754
+ it "supports compounding" do
755
+ expect(html).to have_select('Not this one').or have_select('Select Box')
756
+ end if RSpec::Version::STRING.to_f >= 3.0
668
757
  end
669
758
 
670
759
  describe "have_table matcher" do
@@ -683,5 +772,9 @@ RSpec.describe Capybara::RSpecMatchers do
683
772
  expect(html).to have_table('No such Table')
684
773
  end.to raise_error(/expected to find table "No such Table"/)
685
774
  end
775
+
776
+ it "supports compounding" do
777
+ expect(html).to have_table('nope').or have_table('Lovely table')
778
+ end if RSpec::Version::STRING.to_f >= 3.0
686
779
  end
687
780
  end
@@ -63,6 +63,16 @@ RSpec.describe Capybara::Session do
63
63
  expect($?.exitstatus).to be 0
64
64
  end
65
65
  end
66
+
67
+ describe "#accept_alert" do
68
+ it "supports a blockless mode" do
69
+ @session.visit('/with_js')
70
+ @session.click_link('Open alert')
71
+ expect(@session.driver.browser.switch_to.alert).to be_kind_of Selenium::WebDriver::Alert
72
+ @session.accept_alert
73
+ expect{@session.driver.browser.switch_to.alert}.to raise_error("No alert is present")
74
+ end
75
+ end
66
76
  end
67
77
  end
68
78
 
@@ -81,4 +91,3 @@ RSpec.describe Capybara::Selenium::Driver do
81
91
  end
82
92
  end
83
93
 
84
-
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.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - gem-public_cert.pem
12
- date: 2014-06-02 00:00:00.000000000 Z
12
+ date: 2014-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -227,10 +227,14 @@ files:
227
227
  - lib/capybara/node/actions.rb
228
228
  - lib/capybara/node/base.rb
229
229
  - lib/capybara/node/document.rb
230
+ - lib/capybara/node/document_matchers.rb
230
231
  - lib/capybara/node/element.rb
231
232
  - lib/capybara/node/finders.rb
232
233
  - lib/capybara/node/matchers.rb
233
234
  - lib/capybara/node/simple.rb
235
+ - lib/capybara/queries/base_query.rb
236
+ - lib/capybara/queries/text_query.rb
237
+ - lib/capybara/queries/title_query.rb
234
238
  - lib/capybara/query.rb
235
239
  - lib/capybara/rack_test/browser.rb
236
240
  - lib/capybara/rack_test/css_handlers.rb
@@ -253,8 +257,13 @@ files:
253
257
  - lib/capybara/spec/public/jquery-ui.js
254
258
  - lib/capybara/spec/public/jquery.js
255
259
  - lib/capybara/spec/public/test.js
260
+ - lib/capybara/spec/session/accept_alert_spec.rb
261
+ - lib/capybara/spec/session/accept_confirm_spec.rb
262
+ - lib/capybara/spec/session/accept_prompt_spec.rb
256
263
  - lib/capybara/spec/session/all_spec.rb
257
264
  - lib/capybara/spec/session/assert_selector.rb
265
+ - lib/capybara/spec/session/assert_text.rb
266
+ - lib/capybara/spec/session/assert_title.rb
258
267
  - lib/capybara/spec/session/attach_file_spec.rb
259
268
  - lib/capybara/spec/session/body_spec.rb
260
269
  - lib/capybara/spec/session/check_spec.rb
@@ -264,6 +273,8 @@ files:
264
273
  - lib/capybara/spec/session/click_link_spec.rb
265
274
  - lib/capybara/spec/session/current_scope_spec.rb
266
275
  - lib/capybara/spec/session/current_url_spec.rb
276
+ - lib/capybara/spec/session/dismiss_confirm_spec.rb
277
+ - lib/capybara/spec/session/dismiss_prompt_spec.rb
267
278
  - lib/capybara/spec/session/evaluate_script_spec.rb
268
279
  - lib/capybara/spec/session/execute_script_spec.rb
269
280
  - lib/capybara/spec/session/fill_in_spec.rb