capybara 2.0.3 → 2.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.md +73 -0
  3. data/README.md +52 -5
  4. data/lib/capybara.rb +44 -62
  5. data/lib/capybara/cucumber.rb +4 -1
  6. data/lib/capybara/driver/base.rb +13 -9
  7. data/lib/capybara/driver/node.rb +18 -6
  8. data/lib/capybara/helpers.rb +111 -22
  9. data/lib/capybara/node/actions.rb +24 -19
  10. data/lib/capybara/node/base.rb +25 -32
  11. data/lib/capybara/node/document.rb +6 -2
  12. data/lib/capybara/node/element.rb +45 -7
  13. data/lib/capybara/node/finders.rb +48 -21
  14. data/lib/capybara/node/matchers.rb +38 -21
  15. data/lib/capybara/node/simple.rb +29 -7
  16. data/lib/capybara/query.rb +72 -26
  17. data/lib/capybara/rack_test/browser.rb +11 -3
  18. data/lib/capybara/rack_test/css_handlers.rb +8 -0
  19. data/lib/capybara/rack_test/driver.rb +11 -3
  20. data/lib/capybara/rack_test/form.rb +8 -1
  21. data/lib/capybara/rack_test/node.rb +92 -36
  22. data/lib/capybara/rails.rb +1 -2
  23. data/lib/capybara/result.rb +21 -37
  24. data/lib/capybara/rspec/matchers.rb +60 -31
  25. data/lib/capybara/selector.rb +46 -13
  26. data/lib/capybara/selenium/driver.rb +42 -6
  27. data/lib/capybara/selenium/node.rb +23 -5
  28. data/lib/capybara/session.rb +46 -11
  29. data/lib/capybara/spec/public/test.js +12 -0
  30. data/lib/capybara/spec/session/all_spec.rb +9 -8
  31. data/lib/capybara/spec/session/attach_file_spec.rb +14 -0
  32. data/lib/capybara/spec/session/check_spec.rb +14 -0
  33. data/lib/capybara/spec/session/choose_spec.rb +14 -0
  34. data/lib/capybara/spec/session/click_button_spec.rb +77 -1
  35. data/lib/capybara/spec/session/click_link_or_button_spec.rb +65 -0
  36. data/lib/capybara/spec/session/click_link_spec.rb +24 -0
  37. data/lib/capybara/spec/session/current_scope_spec.rb +29 -0
  38. data/lib/capybara/spec/session/fill_in_spec.rb +14 -0
  39. data/lib/capybara/spec/session/find_button_spec.rb +12 -0
  40. data/lib/capybara/spec/session/find_by_id_spec.rb +12 -1
  41. data/lib/capybara/spec/session/find_field_spec.rb +30 -0
  42. data/lib/capybara/spec/session/find_link_spec.rb +12 -0
  43. data/lib/capybara/spec/session/find_spec.rb +258 -16
  44. data/lib/capybara/spec/session/first_spec.rb +25 -8
  45. data/lib/capybara/spec/session/has_css_spec.rb +2 -2
  46. data/lib/capybara/spec/session/has_field_spec.rb +10 -2
  47. data/lib/capybara/spec/session/has_selector_spec.rb +9 -0
  48. data/lib/capybara/spec/session/has_text_spec.rb +96 -0
  49. data/lib/capybara/spec/session/has_title_spec.rb +47 -0
  50. data/lib/capybara/spec/session/node_spec.rb +43 -0
  51. data/lib/capybara/spec/session/reset_session_spec.rb +10 -2
  52. data/lib/capybara/spec/session/save_page_spec.rb +30 -0
  53. data/lib/capybara/spec/session/select_spec.rb +65 -0
  54. data/lib/capybara/spec/session/text_spec.rb +31 -0
  55. data/lib/capybara/spec/session/title_spec.rb +16 -0
  56. data/lib/capybara/spec/session/uncheck_spec.rb +14 -0
  57. data/lib/capybara/spec/session/unselect_spec.rb +42 -0
  58. data/lib/capybara/spec/session/visit_spec.rb +3 -3
  59. data/lib/capybara/spec/session/within_frame_spec.rb +14 -0
  60. data/lib/capybara/spec/session/within_spec.rb +3 -3
  61. data/lib/capybara/spec/spec_helper.rb +6 -1
  62. data/lib/capybara/spec/views/form.erb +39 -2
  63. data/lib/capybara/spec/views/frame_child.erb +9 -0
  64. data/lib/capybara/spec/views/frame_parent.erb +8 -0
  65. data/lib/capybara/spec/views/with_base_tag.erb +10 -0
  66. data/lib/capybara/spec/views/with_count.erb +7 -0
  67. data/lib/capybara/spec/views/with_hover.erb +17 -0
  68. data/lib/capybara/spec/views/with_html.erb +21 -2
  69. data/lib/capybara/spec/views/with_js.erb +5 -0
  70. data/lib/capybara/spec/views/with_scope.erb +6 -1
  71. data/lib/capybara/spec/views/with_title.erb +1 -0
  72. data/lib/capybara/spec/views/within_frames.erb +1 -0
  73. data/lib/capybara/version.rb +1 -1
  74. data/spec/basic_node_spec.rb +75 -24
  75. data/spec/dsl_spec.rb +2 -1
  76. data/spec/rack_test_spec.rb +4 -3
  77. data/spec/rspec/matchers_spec.rb +105 -17
  78. data/spec/server_spec.rb +8 -8
  79. data/spec/spec_helper.rb +2 -1
  80. metadata +83 -23
  81. metadata.gz.sig +0 -0
@@ -1,3 +1,3 @@
1
1
  module Capybara
2
- VERSION = '2.0.3'
2
+ VERSION = '2.1.0.beta1'
3
3
  end
@@ -4,26 +4,42 @@ describe Capybara do
4
4
  describe '.string' do
5
5
  let :string do
6
6
  Capybara.string <<-STRING
7
- <div id="page">
8
- <div id="content">
9
- <h1 data="fantastic">Totally awesome</h1>
10
- <p>Yes it is</p>
11
- </div>
12
-
13
- <div id="footer" style="display: none">
14
- <p>c2010</p>
15
- <p>Jonas Nicklas</p>
16
- <input type="text" name="foo" value="bar"/>
17
- <select name="animal">
18
- <option>Monkey</option>
19
- <option selected="selected">Capybara</option>
20
- </select>
21
- </div>
22
-
23
- <section>
24
- <div class="subsection"></div>
25
- </div>
26
- </div>
7
+ <html>
8
+ <head>
9
+ <title>simple_node</title>
10
+ </head>
11
+ <body>
12
+ <div id="page">
13
+ <div id="content">
14
+ <h1 data="fantastic">Totally awesome</h1>
15
+ <p>Yes it is</p>
16
+ </div>
17
+
18
+ <form>
19
+ <input type="text" name="bleh" disabled="disabled"/>
20
+ <input type="text" name="meh"/>
21
+ </form>
22
+
23
+ <div id="footer">
24
+ <p>c2010</p>
25
+ <p>Jonas Nicklas</p>
26
+ <input type="text" name="foo" value="bar"/>
27
+ <select name="animal">
28
+ <option>Monkey</option>
29
+ <option selected="selected">Capybara</option>
30
+ </select>
31
+ </div>
32
+
33
+ <div id="hidden" style="display: none">
34
+ <p id="secret">Secret</p>
35
+ </div>
36
+
37
+ <section>
38
+ <div class="subsection"></div>
39
+ </section>
40
+ </div>
41
+ </body>
42
+ </html>
27
43
  STRING
28
44
  end
29
45
 
@@ -56,8 +72,8 @@ describe Capybara do
56
72
  end
57
73
 
58
74
  it "allows finding only visible nodes" do
59
- string.all('//p', :text => 'c2010', :visible => true).should be_empty
60
- string.all('//p', :text => 'c2010', :visible => false).should have(1).element
75
+ string.all(:css, '#secret', :visible => true).should be_empty
76
+ string.all(:css, '#secret', :visible => false).should have(1).element
61
77
  end
62
78
 
63
79
  it "allows finding elements and extracting text from them" do
@@ -77,13 +93,48 @@ describe Capybara do
77
93
  end
78
94
 
79
95
  it "allows finding elements and extracting the path" do
80
- string.find('//input').value.should == 'bar'
96
+ string.find('//div/input').value.should == 'bar'
81
97
  string.find('//select').value.should == 'Capybara'
82
98
  end
83
99
 
84
100
  it "allows finding elements and checking if they are visible" do
85
101
  string.find('//h1').should be_visible
86
- string.find('//input').should_not be_visible
102
+ string.find(:css, "#secret", :visible => false).should_not be_visible
103
+ end
104
+
105
+ it "allows finding elements and checking if they are disabled" do
106
+ string.find('//form/input[@name="bleh"]').should be_disabled
107
+ string.find('//form/input[@name="meh"]').should_not be_disabled
108
+ end
109
+
110
+ describe "#title" do
111
+ it "returns the page title" do
112
+ string.title.should == "simple_node"
113
+ end
114
+ end
115
+
116
+ describe "#has_title?" do
117
+ it "returns whether the page has the given title" do
118
+ string.has_title?('simple_node').should be_true
119
+ string.has_title?('monkey').should be_false
120
+ end
121
+
122
+ it "allows regexp matches" do
123
+ string.has_title?(/s[a-z]+_node/).should be_true
124
+ string.has_title?(/monkey/).should be_false
125
+ end
126
+ end
127
+
128
+ describe '#has_no_title?' do
129
+ it "returns whether the page does not have the given title" do
130
+ string.has_no_title?('simple_node').should be_false
131
+ string.has_no_title?('monkey').should be_true
132
+ end
133
+
134
+ it "allows regexp matches" do
135
+ string.has_no_title?(/s[a-z]+_node/).should be_false
136
+ string.has_no_title?(/monkey/).should be_true
137
+ end
87
138
  end
88
139
  end
89
140
  end
@@ -10,7 +10,8 @@ Capybara::SpecHelper.run_specs TestClass.new, "DSL", :skip => [
10
10
  :screenshot,
11
11
  :frames,
12
12
  :windows,
13
- :server
13
+ :server,
14
+ :hover
14
15
  ]
15
16
 
16
17
  describe Capybara::DSL do
@@ -9,7 +9,8 @@ Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", :skip => [
9
9
  :screenshot,
10
10
  :frames,
11
11
  :windows,
12
- :server
12
+ :server,
13
+ :hover
13
14
  ]
14
15
 
15
16
  describe Capybara::Session do
@@ -84,14 +85,14 @@ describe Capybara::RackTest::Driver do
84
85
  it 'should keep headers on link clicks' do
85
86
  @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
86
87
  @driver.visit('/header_links')
87
- @driver.find('.//a').first.click
88
+ @driver.find_xpath('.//a').first.click
88
89
  @driver.html.should include('foobar')
89
90
  end
90
91
 
91
92
  it 'should keep headers on form submit' do
92
93
  @driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
93
94
  @driver.visit('/header_links')
94
- @driver.find('.//input').first.click
95
+ @driver.find_xpath('.//input').first.click
95
96
  @driver.html.should include('foobar')
96
97
  end
97
98
 
@@ -29,9 +29,28 @@ describe Capybara::RSpecMatchers do
29
29
 
30
30
  it "fails if matched node count does not equal expected count" do
31
31
  expect do
32
- "<h1>Text</h1>".should have_css('h1', :count => 2)
33
- end.to raise_error(/expected css "h1" to be found 2 times/)
32
+ "<h1>Text</h1>".should have_css('h1', count: 2)
33
+ end.to raise_error("expected to find css \"h1\" 2 times, found 1 match: \"Text\"")
34
34
  end
35
+
36
+ it "fails if matched node count is less than expected minimum count" do
37
+ expect do
38
+ "<h1>Text</h1>".should have_css('p', minimum: 1)
39
+ end.to raise_error("expected to find css \"p\" at least 1 time but there were no matches")
40
+ end
41
+
42
+ it "fails if matched node count is more than expected maximum count" do
43
+ expect do
44
+ "<h1>Text</h1><h1>Text</h1><h1>Text</h1>".should have_css('h1', maximum: 2)
45
+ end.to raise_error('expected to find css "h1" at most 2 times, found 3 matches: "Text", "Text", "Text"')
46
+ end
47
+
48
+ it "fails if matched node count does not belong to expected range" do
49
+ expect do
50
+ "<h1>Text</h1>".should have_css('h1', between: 2..3)
51
+ end.to raise_error("expected to find css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
52
+ end
53
+
35
54
  end
36
55
 
37
56
  context "with should_not" do
@@ -222,7 +241,7 @@ describe Capybara::RSpecMatchers do
222
241
 
223
242
  describe "have_content matcher" do
224
243
  it "gives proper description" do
225
- have_content('Text').description.should == "have text \"Text\""
244
+ have_content('Text').description.should == "text \"Text\""
226
245
  end
227
246
 
228
247
  context "on a string" do
@@ -238,7 +257,7 @@ describe Capybara::RSpecMatchers do
238
257
  it "fails if has_content? returns false" do
239
258
  expect do
240
259
  "<h1>Text</h1>".should have_content('No such Text')
241
- end.to raise_error(/expected there to be text "No such Text" in "Text"/)
260
+ end.to raise_error(/expected to find text "No such Text" in "Text"/)
242
261
  end
243
262
  end
244
263
 
@@ -254,7 +273,7 @@ describe Capybara::RSpecMatchers do
254
273
  it "fails if has_no_content? returns false" do
255
274
  expect do
256
275
  "<h1>Text</h1>".should_not have_content('Text')
257
- end.to raise_error(/expected there not to be text "Text" in "Text"/)
276
+ end.to raise_error(/expected not to find text "Text" in "Text"/)
258
277
  end
259
278
  end
260
279
  end
@@ -276,7 +295,7 @@ describe Capybara::RSpecMatchers do
276
295
  it "fails if has_content? returns false" do
277
296
  expect do
278
297
  page.should have_content('No such Text')
279
- end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
298
+ end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
280
299
  end
281
300
 
282
301
  context "with default selector CSS" do
@@ -284,7 +303,7 @@ describe Capybara::RSpecMatchers do
284
303
  it "fails if has_content? returns false" do
285
304
  expect do
286
305
  page.should have_content('No such Text')
287
- end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
306
+ end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
288
307
  end
289
308
  after { Capybara.default_selector = :xpath }
290
309
  end
@@ -298,7 +317,7 @@ describe Capybara::RSpecMatchers do
298
317
  it "fails if has_no_content? returns false" do
299
318
  expect do
300
319
  page.should_not have_content('This is a test')
301
- end.to raise_error(/expected there not to be text "This is a test"/)
320
+ end.to raise_error(/expected not to find text "This is a test"/)
302
321
  end
303
322
  end
304
323
  end
@@ -306,7 +325,7 @@ describe Capybara::RSpecMatchers do
306
325
 
307
326
  describe "have_text matcher" do
308
327
  it "gives proper description" do
309
- have_text('Text').description.should == "have text \"Text\""
328
+ have_text('Text').description.should == "text \"Text\""
310
329
  end
311
330
 
312
331
  context "on a string" do
@@ -322,13 +341,37 @@ describe Capybara::RSpecMatchers do
322
341
  it "fails if has_text? returns false" do
323
342
  expect do
324
343
  "<h1>Text</h1>".should have_text('No such Text')
325
- end.to raise_error(/expected there to be text "No such Text" in "Text"/)
344
+ end.to raise_error(/expected to find text "No such Text" in "Text"/)
345
+ end
346
+
347
+ it "casts Fixnum to string" do
348
+ expect do
349
+ "<h1>Text</h1>".should have_text(3)
350
+ end.to raise_error(/expected to find text "3" in "Text"/)
351
+ end
352
+
353
+ it "fails if matched text count does not equal to expected count" do
354
+ expect do
355
+ "<h1>Text</h1>".should have_text('Text', count: 2)
356
+ end.to raise_error(/expected to find text "Text" 2 times in "Text"/)
357
+ end
358
+
359
+ it "fails if matched text count is less than expected minimum count" do
360
+ expect do
361
+ "<h1>Text</h1>".should have_text('Lorem', minimum: 1)
362
+ end.to raise_error(/expected to find text "Lorem" at least 1 time in "Text"/)
363
+ end
364
+
365
+ it "fails if matched text count is more than expected maximum count" do
366
+ expect do
367
+ "<h1>Text TextText</h1>".should have_text('Text', maximum: 2)
368
+ end.to raise_error(/expected to find text "Text" at most 2 times in "Text TextText"/)
326
369
  end
327
370
 
328
- it "casts has_text? argument to string" do
371
+ it "fails if matched text count does not belong to expected range" do
329
372
  expect do
330
- "<h1>Text</h1>".should have_text(:cast_me)
331
- end.to raise_error(/expected there to be text "cast_me" in "Text"/)
373
+ "<h1>Text</h1>".should have_text('Text', between: 2..3)
374
+ end.to raise_error(/expected to find text "Text" between 2 and 3 times in "Text"/)
332
375
  end
333
376
  end
334
377
 
@@ -344,7 +387,7 @@ describe Capybara::RSpecMatchers do
344
387
  it "fails if has_no_text? returns false" do
345
388
  expect do
346
389
  "<h1>Text</h1>".should_not have_text('Text')
347
- end.to raise_error(/expected there not to be text "Text" in "Text"/)
390
+ end.to raise_error(/expected not to find text "Text" in "Text"/)
348
391
  end
349
392
  end
350
393
  end
@@ -363,10 +406,19 @@ describe Capybara::RSpecMatchers do
363
406
  page.should have_text(/test/)
364
407
  end
365
408
 
409
+ it "can check for all text" do
410
+ page.should have_text(:all, 'Some of this text is hidden!')
411
+ end
412
+
413
+ it "can check for visible text" do
414
+ page.should have_text(:visible, 'Some of this text is')
415
+ page.should_not have_text(:visible, 'Some of this text is hidden!')
416
+ end
417
+
366
418
  it "fails if has_text? returns false" do
367
419
  expect do
368
420
  page.should have_text('No such Text')
369
- end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
421
+ end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
370
422
  end
371
423
 
372
424
  context "with default selector CSS" do
@@ -374,7 +426,7 @@ describe Capybara::RSpecMatchers do
374
426
  it "fails if has_text? returns false" do
375
427
  expect do
376
428
  page.should have_text('No such Text')
377
- end.to raise_error(/expected there to be text "No such Text" in "(.*)This is a test(.*)"/)
429
+ end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
378
430
  end
379
431
  after { Capybara.default_selector = :xpath }
380
432
  end
@@ -388,7 +440,7 @@ describe Capybara::RSpecMatchers do
388
440
  it "fails if has_no_text? returns false" do
389
441
  expect do
390
442
  page.should_not have_text('This is a test')
391
- end.to raise_error(/expected there not to be text "This is a test"/)
443
+ end.to raise_error(/expected not to find text "This is a test"/)
392
444
  end
393
445
  end
394
446
  end
@@ -412,6 +464,42 @@ describe Capybara::RSpecMatchers do
412
464
  end
413
465
  end
414
466
 
467
+ describe "have_title matcher" do
468
+ it "gives proper description" do
469
+ have_title('Just a title').description.should == "have title \"Just a title\""
470
+ end
471
+
472
+ context "on a string" do
473
+ let(:html) { '<title>Just a title</title>' }
474
+
475
+ it "passes if there is such a title" do
476
+ html.should have_title('Just a title')
477
+ end
478
+
479
+ it "fails if there is no such title" do
480
+ expect do
481
+ html.should have_title('No such title')
482
+ end.to raise_error(/expected there to be title "No such title"/)
483
+ end
484
+ end
485
+
486
+ context "on a page or node" do
487
+ before do
488
+ visit('/with_js')
489
+ end
490
+
491
+ it "passes if there is such a title" do
492
+ page.should have_title('with_js')
493
+ end
494
+
495
+ it "fails if there is no such title" do
496
+ expect do
497
+ page.should have_title('No such title')
498
+ end.to raise_error(/expected there to be title "No such title"/)
499
+ end
500
+ end
501
+ end
502
+
415
503
  describe "have_button matcher" do
416
504
  let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
417
505
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Capybara::Server do
4
4
 
5
5
  it "should spool up a rack server" do
6
- @app = proc { |env| [200, {}, "Hello Server!"]}
6
+ @app = proc { |env| [200, {}, ["Hello Server!"]]}
7
7
  @server = Capybara::Server.new(@app).boot
8
8
 
9
9
  @res = Net::HTTP.start(@server.host, @server.port) { |http| http.get('/') }
@@ -20,7 +20,7 @@ describe Capybara::Server do
20
20
  it "should bind to the specified host" do
21
21
  Capybara.server_host = '0.0.0.0'
22
22
 
23
- app = proc { |env| [200, {}, "Hello Server!"]}
23
+ app = proc { |env| [200, {}, ["Hello Server!"]]}
24
24
  server = Capybara::Server.new(app).boot
25
25
  server.host.should == '0.0.0.0'
26
26
 
@@ -30,7 +30,7 @@ describe Capybara::Server do
30
30
  it "should use specified port" do
31
31
  Capybara.server_port = 22789
32
32
 
33
- @app = proc { |env| [200, {}, "Hello Server!"]}
33
+ @app = proc { |env| [200, {}, ["Hello Server!"]]}
34
34
  @server = Capybara::Server.new(@app).boot
35
35
 
36
36
  @res = Net::HTTP.start(@server.host, 22789) { |http| http.get('/') }
@@ -40,7 +40,7 @@ describe Capybara::Server do
40
40
  end
41
41
 
42
42
  it "should use given port" do
43
- @app = proc { |env| [200, {}, "Hello Server!"]}
43
+ @app = proc { |env| [200, {}, ["Hello Server!"]]}
44
44
  @server = Capybara::Server.new(@app, 22790).boot
45
45
 
46
46
  @res = Net::HTTP.start(@server.host, 22790) { |http| http.get('/') }
@@ -50,8 +50,8 @@ describe Capybara::Server do
50
50
  end
51
51
 
52
52
  it "should find an available port" do
53
- @app1 = proc { |env| [200, {}, "Hello Server!"]}
54
- @app2 = proc { |env| [200, {}, "Hello Second Server!"]}
53
+ @app1 = proc { |env| [200, {}, ["Hello Server!"]]}
54
+ @app2 = proc { |env| [200, {}, ["Hello Second Server!"]]}
55
55
 
56
56
  @server1 = Capybara::Server.new(@app1).boot
57
57
  @server2 = Capybara::Server.new(@app2).boot
@@ -64,8 +64,8 @@ describe Capybara::Server do
64
64
  end
65
65
 
66
66
  it "should use the server if it already running" do
67
- @app1 = proc { |env| [200, {}, "Hello Server!"]}
68
- @app2 = proc { |env| [200, {}, "Hello Second Server!"]}
67
+ @app1 = proc { |env| [200, {}, ["Hello Server!"]]}
68
+ @app2 = proc { |env| [200, {}, ["Hello Second Server!"]]}
69
69
 
70
70
  @server1a = Capybara::Server.new(@app1).boot
71
71
  @server1b = Capybara::Server.new(@app1).boot
@@ -1,4 +1,5 @@
1
- require 'capybara/spec/spec_helper'
1
+ require "capybara/spec/spec_helper"
2
+ require "pry"
2
3
 
3
4
  RSpec.configure do |config|
4
5
  Capybara::SpecHelper.configure(config)