capybara 1.1.4 → 2.0.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 (111) hide show
  1. data/{History.txt → History.md} +138 -0
  2. data/License.txt +22 -0
  3. data/README.md +850 -0
  4. data/lib/capybara/cucumber.rb +2 -5
  5. data/lib/capybara/driver/base.rb +6 -6
  6. data/lib/capybara/driver/node.rb +3 -2
  7. data/lib/capybara/dsl.rb +13 -124
  8. data/lib/capybara/helpers.rb +33 -0
  9. data/lib/capybara/node/actions.rb +16 -30
  10. data/lib/capybara/node/base.rb +56 -13
  11. data/lib/capybara/node/element.rb +18 -30
  12. data/lib/capybara/node/finders.rb +28 -90
  13. data/lib/capybara/node/matchers.rb +121 -73
  14. data/lib/capybara/node/simple.rb +13 -11
  15. data/lib/capybara/query.rb +78 -0
  16. data/lib/capybara/rack_test/browser.rb +27 -39
  17. data/lib/capybara/rack_test/driver.rb +13 -3
  18. data/lib/capybara/rack_test/node.rb +31 -2
  19. data/lib/capybara/result.rb +72 -0
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +33 -63
  22. data/lib/capybara/rspec.rb +7 -4
  23. data/lib/capybara/selector.rb +97 -34
  24. data/lib/capybara/selenium/driver.rb +15 -62
  25. data/lib/capybara/selenium/node.rb +14 -21
  26. data/lib/capybara/server.rb +32 -27
  27. data/lib/capybara/session.rb +90 -50
  28. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  29. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  30. data/lib/capybara/spec/public/jquery.js +9046 -0
  31. data/lib/capybara/spec/public/test.js +3 -0
  32. data/lib/capybara/spec/session/all_spec.rb +61 -59
  33. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  34. data/lib/capybara/spec/session/attach_file_spec.rb +72 -55
  35. data/lib/capybara/spec/session/body_spec.rb +21 -0
  36. data/lib/capybara/spec/session/check_spec.rb +68 -48
  37. data/lib/capybara/spec/session/choose_spec.rb +32 -18
  38. data/lib/capybara/spec/session/click_button_spec.rb +263 -232
  39. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -29
  40. data/lib/capybara/spec/session/click_link_spec.rb +96 -96
  41. data/lib/capybara/spec/session/current_url_spec.rb +88 -10
  42. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  43. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  44. data/lib/capybara/spec/session/fill_in_spec.rb +119 -103
  45. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  46. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  47. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  48. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  49. data/lib/capybara/spec/session/find_spec.rb +93 -115
  50. data/lib/capybara/spec/session/first_spec.rb +51 -85
  51. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  52. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  53. data/lib/capybara/spec/session/has_field_spec.rb +170 -144
  54. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  55. data/lib/capybara/spec/session/has_select_spec.rb +161 -109
  56. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  57. data/lib/capybara/spec/session/has_table_spec.rb +22 -88
  58. data/lib/capybara/spec/session/has_text_spec.rb +195 -0
  59. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  60. data/lib/capybara/spec/session/headers.rb +4 -17
  61. data/lib/capybara/spec/session/html_spec.rb +15 -0
  62. data/lib/capybara/spec/session/node_spec.rb +205 -0
  63. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  64. data/lib/capybara/spec/session/response_code.rb +4 -17
  65. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  66. data/lib/capybara/spec/session/screenshot.rb +13 -0
  67. data/lib/capybara/spec/session/select_spec.rb +99 -88
  68. data/lib/capybara/spec/session/source_spec.rb +12 -0
  69. data/lib/capybara/spec/session/text_spec.rb +15 -12
  70. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  71. data/lib/capybara/spec/session/unselect_spec.rb +69 -58
  72. data/lib/capybara/spec/session/visit_spec.rb +74 -0
  73. data/lib/capybara/spec/session/within_frame_spec.rb +31 -0
  74. data/lib/capybara/spec/session/within_spec.rb +118 -131
  75. data/lib/capybara/spec/session/within_window_spec.rb +38 -0
  76. data/lib/capybara/spec/spec_helper.rb +84 -0
  77. data/lib/capybara/spec/test_app.rb +32 -6
  78. data/lib/capybara/spec/views/form.erb +12 -10
  79. data/lib/capybara/spec/views/host_links.erb +2 -2
  80. data/lib/capybara/spec/views/tables.erb +6 -66
  81. data/lib/capybara/spec/views/with_html.erb +9 -4
  82. data/lib/capybara/spec/views/with_js.erb +11 -7
  83. data/lib/capybara/version.rb +1 -1
  84. data/lib/capybara.rb +125 -6
  85. data/spec/basic_node_spec.rb +17 -5
  86. data/spec/capybara_spec.rb +9 -0
  87. data/spec/dsl_spec.rb +31 -17
  88. data/spec/rack_test_spec.rb +157 -0
  89. data/spec/result_spec.rb +51 -0
  90. data/spec/rspec/features_spec.rb +19 -2
  91. data/spec/rspec/matchers_spec.rb +170 -89
  92. data/spec/rspec_spec.rb +1 -3
  93. data/spec/selenium_spec.rb +53 -0
  94. data/spec/server_spec.rb +37 -25
  95. data/spec/spec_helper.rb +1 -30
  96. metadata +39 -31
  97. data/README.rdoc +0 -722
  98. data/lib/capybara/spec/driver.rb +0 -301
  99. data/lib/capybara/spec/session/current_host_spec.rb +0 -68
  100. data/lib/capybara/spec/session/has_content_spec.rb +0 -106
  101. data/lib/capybara/spec/session/javascript.rb +0 -306
  102. data/lib/capybara/spec/session.rb +0 -154
  103. data/lib/capybara/util/save_and_open_page.rb +0 -44
  104. data/lib/capybara/util/timeout.rb +0 -27
  105. data/spec/driver/rack_test_driver_spec.rb +0 -89
  106. data/spec/driver/selenium_driver_spec.rb +0 -37
  107. data/spec/save_and_open_page_spec.rb +0 -155
  108. data/spec/session/rack_test_session_spec.rb +0 -55
  109. data/spec/session/selenium_session_spec.rb +0 -26
  110. data/spec/string_spec.rb +0 -77
  111. data/spec/timeout_spec.rb +0 -28
@@ -1,119 +1,119 @@
1
- shared_examples_for "click_link" do
2
- describe '#click_link' do
3
- before do
4
- @session.visit('/with_html')
5
- end
1
+ Capybara::SpecHelper.spec '#click_link' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
6
5
 
7
- context "with id given" do
8
- it "should take user to the linked page" do
9
- @session.click_link('foo')
10
- @session.body.should include('Another World')
11
- end
12
- end
6
+ it "should wait for asynchronous load", :requires => [:js] do
7
+ @session.visit('/with_js')
8
+ @session.click_link('Click me')
9
+ @session.click_link('Has been clicked')
10
+ end
13
11
 
14
- context "with text given" do
15
- it "should take user to the linked page" do
16
- @session.click_link('labore')
17
- @session.body.should include('Bar')
18
- end
19
-
20
- it "should accept partial matches" do
21
- @session.click_link('abo')
22
- @session.body.should include('Bar')
23
- end
24
-
25
- it "should prefer exact matches over partial matches" do
26
- @session.click_link('A link')
27
- @session.body.should include('Bar')
28
- end
29
- end
12
+ it "casts to string" do
13
+ @session.click_link(:'foo')
14
+ @session.should have_content('Another World')
15
+ end
30
16
 
31
- context "with title given" do
32
- it "should take user to the linked page" do
33
- @session.click_link('awesome title')
34
- @session.body.should include('Bar')
35
- end
36
-
37
- it "should accept partial matches" do
38
- @session.click_link('some tit')
39
- @session.body.should include('Bar')
40
- end
41
-
42
- it "should prefer exact matches over partial matches" do
43
- @session.click_link('a fine link')
44
- @session.body.should include('Bar')
45
- end
17
+ context "with id given" do
18
+ it "should take user to the linked page" do
19
+ @session.click_link('foo')
20
+ @session.should have_content('Another World')
46
21
  end
22
+ end
47
23
 
48
- context "with alternative text given to a contained image" do
49
- it "should take user to the linked page" do
50
- @session.click_link('awesome image')
51
- @session.body.should include('Bar')
52
- end
53
-
54
- it "should take user to the linked page" do
55
- @session.click_link('some imag')
56
- @session.body.should include('Bar')
57
- end
58
-
59
- it "should prefer exact matches over partial matches" do
60
- @session.click_link('fine image')
61
- @session.body.should include('Bar')
62
- end
24
+ context "with text given" do
25
+ it "should take user to the linked page" do
26
+ @session.click_link('labore')
27
+ @session.should have_content('Bar')
63
28
  end
64
29
 
65
- context "with a locator that doesn't exist" do
66
- it "should raise an error" do
67
- running do
68
- @session.click_link('does not exist')
69
- end.should raise_error(Capybara::ElementNotFound)
70
- end
30
+ it "should accept partial matches" do
31
+ @session.click_link('abo')
32
+ @session.should have_content('Bar')
71
33
  end
34
+ end
72
35
 
73
- it "should follow relative links" do
74
- @session.visit('/')
75
- @session.click_link('Relative')
76
- @session.body.should include('This is a test')
36
+ context "with title given" do
37
+ it "should take user to the linked page" do
38
+ @session.click_link('awesome title')
39
+ @session.should have_content('Bar')
77
40
  end
78
41
 
79
- it "should follow redirects" do
80
- @session.click_link('Redirect')
81
- @session.body.should include('You landed')
42
+ it "should accept partial matches" do
43
+ @session.click_link('some titl')
44
+ @session.should have_content('Bar')
82
45
  end
46
+ end
83
47
 
84
- it "should follow redirects" do
85
- @session.click_link('BackToMyself')
86
- @session.body.should include('This is a test')
48
+ context "with alternative text given to a contained image" do
49
+ it "should take user to the linked page" do
50
+ @session.click_link('awesome image')
51
+ @session.should have_content('Bar')
87
52
  end
88
53
 
89
- it "should add query string to current URL with naked query string" do
90
- @session.click_link('Naked Query String')
91
- @session.body.should include('Query String sent')
54
+ it "should accept partial matches" do
55
+ @session.click_link('some imag')
56
+ @session.should have_content('Bar')
92
57
  end
58
+ end
93
59
 
94
- it "should do nothing on anchor links" do
95
- @session.fill_in("test_field", :with => 'blah')
96
- @session.click_link('Anchor')
97
- @session.find_field("test_field").value.should == 'blah'
98
- @session.click_link('Blank Anchor')
99
- @session.find_field("test_field").value.should == 'blah'
60
+ context "with a locator that doesn't exist" do
61
+ it "should raise an error" do
62
+ msg = "Unable to find link \"does not exist\""
63
+ expect do
64
+ @session.click_link('does not exist')
65
+ end.to raise_error(Capybara::ElementNotFound, msg)
100
66
  end
67
+ end
101
68
 
102
- it "should do nothing on URL+anchor links for the same page" do
103
- @session.fill_in("test_field", :with => 'blah')
104
- @session.click_link('Anchor on same page')
105
- @session.find_field("test_field").value.should == 'blah'
106
- end
69
+ it "should follow relative links" do
70
+ @session.visit('/')
71
+ @session.click_link('Relative')
72
+ @session.should have_content('This is a test')
73
+ end
107
74
 
108
- it "should follow link on URL+anchor links for a different page" do
109
- @session.click_link('Anchor on different page')
110
- @session.body.should include('Bar')
111
- end
75
+ it "should follow protocol relative links" do
76
+ @session.click_link('Protocol')
77
+ @session.should have_content('Another World')
78
+ end
112
79
 
113
- it "raise an error with links with no href" do
114
- running do
115
- @session.click_link('No Href')
116
- end.should raise_error(Capybara::ElementNotFound)
117
- end
80
+ it "should follow redirects" do
81
+ @session.click_link('Redirect')
82
+ @session.should have_content('You landed')
83
+ end
84
+
85
+ it "should follow redirects" do
86
+ @session.click_link('BackToMyself')
87
+ @session.should have_content('This is a test')
88
+ end
89
+
90
+ it "should add query string to current URL with naked query string" do
91
+ @session.click_link('Naked Query String')
92
+ @session.should have_content('Query String sent')
93
+ end
94
+
95
+ it "should do nothing on anchor links" do
96
+ @session.fill_in("test_field", :with => 'blah')
97
+ @session.click_link('Normal Anchor')
98
+ @session.find_field("test_field").value.should == 'blah'
99
+ @session.click_link('Blank Anchor')
100
+ @session.find_field("test_field").value.should == 'blah'
101
+ end
102
+
103
+ it "should do nothing on URL+anchor links for the same page" do
104
+ @session.fill_in("test_field", :with => 'blah')
105
+ @session.click_link('Anchor on same page')
106
+ @session.find_field("test_field").value.should == 'blah'
107
+ end
108
+
109
+ it "should follow link on URL+anchor links for a different page" do
110
+ @session.click_link('Anchor on different page')
111
+ @session.should have_content('Bar')
112
+ end
113
+
114
+ it "raise an error with links with no href" do
115
+ expect do
116
+ @session.click_link('No Href')
117
+ end.to raise_error(Capybara::ElementNotFound)
118
118
  end
119
119
  end
@@ -1,15 +1,93 @@
1
- shared_examples_for "current_url" do
2
- describe '#current_url' do
3
- it "should return the current url" do
4
- @session.visit('/form')
5
- @session.current_url.should =~ %r(http://[^/]+/form)
6
- end
1
+ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
2
+ before :all do
3
+ @servers = 2.times.map { Capybara::Server.new(TestApp.clone).boot }
4
+ # sanity check
5
+ @servers[0].port.should_not == @servers[1].port
6
+ @servers.map { |s| s.port }.should_not include 80
7
+ end
8
+
9
+ def bases
10
+ @servers.map { |s| "http://#{s.host}:#{s.port}" }
7
11
  end
8
12
 
9
- describe '#current_path' do
10
- it 'should show the correct location' do
11
- @session.visit('/foo')
12
- @session.current_path.should == '/foo'
13
+ def should_be_on server_index, path="/host", scheme="http"
14
+ # Check that we are on /host on the given server
15
+ s = @servers[server_index]
16
+ @session.current_url.chomp('?').should == "#{scheme}://#{s.host}:#{s.port}#{path}"
17
+ @session.current_host.should == "#{scheme}://#{s.host}" # no port
18
+ @session.current_path.should == path
19
+ if path == '/host'
20
+ # Server should agree with us
21
+ @session.should have_content("Current host is #{scheme}://#{s.host}:#{s.port}")
13
22
  end
14
23
  end
24
+
25
+ def visit_host_links
26
+ @session.visit("#{bases[0]}/host_links?absolute_host=#{bases[1]}")
27
+ end
28
+
29
+ it "is affected by visiting a page directly" do
30
+ @session.visit("#{bases[0]}/host")
31
+ should_be_on 0
32
+ end
33
+
34
+ it "returns to the app host when visiting a relative url" do
35
+ Capybara.app_host = bases[1]
36
+ @session.visit("#{bases[0]}/host")
37
+ should_be_on 0
38
+ @session.visit('/host')
39
+ should_be_on 1
40
+ Capybara.app_host = nil
41
+ end
42
+
43
+ it "is affected by setting Capybara.app_host" do
44
+ Capybara.app_host = bases[0]
45
+ @session.visit("/host")
46
+ should_be_on 0
47
+ Capybara.app_host = bases[1]
48
+ @session.visit("/host")
49
+ should_be_on 1
50
+ Capybara.app_host = nil
51
+ end
52
+
53
+ it "is unaffected by following a relative link" do
54
+ visit_host_links
55
+ @session.click_link("Relative Host")
56
+ should_be_on 0
57
+ end
58
+
59
+ it "is affected by following an absolute link" do
60
+ visit_host_links
61
+ @session.click_link("Absolute Host")
62
+ should_be_on 1
63
+ end
64
+
65
+ it "is unaffected by posting through a relative form" do
66
+ visit_host_links
67
+ @session.click_button("Relative Host")
68
+ should_be_on 0
69
+ end
70
+
71
+ it "is affected by posting through an absolute form" do
72
+ visit_host_links
73
+ @session.click_button("Absolute Host")
74
+ should_be_on 1
75
+ end
76
+
77
+ it "is affected by following a redirect" do
78
+ @session.visit("#{bases[0]}/redirect")
79
+ should_be_on 0, "/landed"
80
+ end
81
+
82
+ it "is affected by pushState", :requires => [:js] do
83
+ @session.visit("/with_js")
84
+ @session.execute_script("window.history.pushState({}, '', '/pushed')")
85
+ @session.current_path.should == "/pushed"
86
+ end
87
+
88
+ it "is affected by replaceState", :requires => [:js] do
89
+ @session.visit("/with_js")
90
+ @session.execute_script("window.history.replaceState({}, '', '/replaced')")
91
+ @session.current_path.should == "/replaced"
92
+ end
15
93
  end
@@ -0,0 +1,6 @@
1
+ Capybara::SpecHelper.spec "#evaluate_script", :requires => [:js] do
2
+ it "should evaluate the given script and return whatever it produces" do
3
+ @session.visit('/with_js')
4
+ @session.evaluate_script("1+3").should == 4
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ Capybara::SpecHelper.spec "#execute_script", :requires => [:js] do
2
+ it "should execute the given script and return nothing" do
3
+ @session.visit('/with_js')
4
+ @session.execute_script("$('#change').text('Funky Doodle')").should be_nil
5
+ @session.should have_css('#change', :text => 'Funky Doodle')
6
+ end
7
+ end
@@ -1,125 +1,141 @@
1
- shared_examples_for "fill_in" do
2
- describe "#fill_in" do
3
- before do
4
- @session.visit('/form')
5
- end
1
+ Capybara::SpecHelper.spec "#fill_in" do
2
+ before do
3
+ @session.visit('/form')
4
+ end
6
5
 
7
- it "should fill in a text field by id" do
8
- @session.fill_in('form_first_name', :with => 'Harry')
9
- @session.click_button('awesome')
10
- extract_results(@session)['first_name'].should == 'Harry'
11
- end
6
+ it "should fill in a text field by id" do
7
+ @session.fill_in('form_first_name', :with => 'Harry')
8
+ @session.click_button('awesome')
9
+ extract_results(@session)['first_name'].should == 'Harry'
10
+ end
12
11
 
13
- it "should fill in a text field by name" do
14
- @session.fill_in('form[last_name]', :with => 'Green')
15
- @session.click_button('awesome')
16
- extract_results(@session)['last_name'].should == 'Green'
17
- end
12
+ it "should fill in a text field by name" do
13
+ @session.fill_in('form[last_name]', :with => 'Green')
14
+ @session.click_button('awesome')
15
+ extract_results(@session)['last_name'].should == 'Green'
16
+ end
18
17
 
19
- it "should fill in a text field by label without for" do
20
- @session.fill_in('Street', :with => 'Avenue Q')
21
- @session.click_button('awesome')
22
- extract_results(@session)['street'].should == 'Avenue Q'
23
- end
18
+ it "should fill in a text field by label without for" do
19
+ @session.fill_in('First Name', :with => 'Harry')
20
+ @session.click_button('awesome')
21
+ extract_results(@session)['first_name'].should == 'Harry'
22
+ end
24
23
 
25
- it "should fill in a url field by label without for" do
26
- @session.fill_in('Html5 Url', :with => 'http://www.avenueq.com')
27
- @session.click_button('html5_submit')
28
- extract_results(@session)['html5_url'].should == 'http://www.avenueq.com'
29
- end
24
+ it "should fill in a url field by label without for" do
25
+ @session.fill_in('Html5 Url', :with => 'http://www.avenueq.com')
26
+ @session.click_button('html5_submit')
27
+ extract_results(@session)['html5_url'].should == 'http://www.avenueq.com'
28
+ end
30
29
 
31
- it "should favour exact label matches over partial matches" do
32
- @session.fill_in('Name', :with => 'Harry Jones')
33
- @session.click_button('awesome')
34
- extract_results(@session)['name'].should == 'Harry Jones'
35
- end
30
+ it "should fill in a textarea by id" do
31
+ @session.fill_in('form_description', :with => 'Texty text')
32
+ @session.click_button('awesome')
33
+ extract_results(@session)['description'].should == 'Texty text'
34
+ end
36
35
 
37
- it "should fill in a textarea by id" do
38
- @session.fill_in('form_description', :with => 'Texty text')
39
- @session.click_button('awesome')
40
- extract_results(@session)['description'].should == 'Texty text'
41
- end
36
+ it "should fill in a textarea by label" do
37
+ @session.fill_in('Description', :with => 'Texty text')
38
+ @session.click_button('awesome')
39
+ extract_results(@session)['description'].should == 'Texty text'
40
+ end
42
41
 
43
- it "should fill in a textarea by label" do
44
- @session.fill_in('Description', :with => 'Texty text')
45
- @session.click_button('awesome')
46
- extract_results(@session)['description'].should == 'Texty text'
47
- end
42
+ it "should fill in a textarea by name" do
43
+ @session.fill_in('form[description]', :with => 'Texty text')
44
+ @session.click_button('awesome')
45
+ extract_results(@session)['description'].should == 'Texty text'
46
+ end
48
47
 
49
- it "should fill in a textarea by name" do
50
- @session.fill_in('form[description]', :with => 'Texty text')
51
- @session.click_button('awesome')
52
- extract_results(@session)['description'].should == 'Texty text'
53
- end
48
+ it "should fill in a password field by id" do
49
+ @session.fill_in('form_password', :with => 'supasikrit')
50
+ @session.click_button('awesome')
51
+ extract_results(@session)['password'].should == 'supasikrit'
52
+ end
54
53
 
55
- it "should fill in a password field by id" do
56
- @session.fill_in('form_password', :with => 'supasikrit')
57
- @session.click_button('awesome')
58
- extract_results(@session)['password'].should == 'supasikrit'
59
- end
54
+ it "should fill in a field with a custom type" do
55
+ @session.fill_in('Schmooo', :with => 'Schmooo is the game')
56
+ @session.click_button('awesome')
57
+ extract_results(@session)['schmooo'].should == 'Schmooo is the game'
58
+ end
60
59
 
61
- it "should fill in a field with a custom type" do
62
- @session.fill_in('Schmooo', :with => 'Schmooo is the game')
63
- @session.click_button('awesome')
64
- extract_results(@session)['schmooo'].should == 'Schmooo is the game'
65
- end
60
+ it "should fill in a field without a type" do
61
+ @session.fill_in('Phone', :with => '+1 555 7022')
62
+ @session.click_button('awesome')
63
+ extract_results(@session)['phone'].should == '+1 555 7022'
64
+ end
66
65
 
67
- it "should fill in a field without a type" do
68
- @session.fill_in('Phone', :with => '+1 555 7022')
69
- @session.click_button('awesome')
70
- extract_results(@session)['phone'].should == '+1 555 7022'
71
- end
66
+ it "should fill in a text field respecting its maxlength attribute" do
67
+ @session.fill_in('Zipcode', :with => '52071350')
68
+ @session.click_button('awesome')
69
+ extract_results(@session)['zipcode'].should == '52071'
70
+ end
72
71
 
73
- it "should fill in a text field respecting its maxlength attribute" do
74
- @session.fill_in('Zipcode', :with => '52071350')
75
- @session.click_button('awesome')
76
- extract_results(@session)['zipcode'].should == '52071'
77
- end
72
+ it "should fill in a password field by name" do
73
+ @session.fill_in('form[password]', :with => 'supasikrit')
74
+ @session.click_button('awesome')
75
+ extract_results(@session)['password'].should == 'supasikrit'
76
+ end
78
77
 
79
- it "should fill in a password field by name" do
80
- @session.fill_in('form[password]', :with => 'supasikrit')
81
- @session.click_button('awesome')
82
- extract_results(@session)['password'].should == 'supasikrit'
83
- end
78
+ it "should fill in a password field by label" do
79
+ @session.fill_in('Password', :with => 'supasikrit')
80
+ @session.click_button('awesome')
81
+ extract_results(@session)['password'].should == 'supasikrit'
82
+ end
84
83
 
85
- it "should fill in a password field by label" do
86
- @session.fill_in('Password', :with => 'supasikrit')
87
- @session.click_button('awesome')
88
- extract_results(@session)['password'].should == 'supasikrit'
89
- end
84
+ it "should fill in a password field by name" do
85
+ @session.fill_in('form[password]', :with => 'supasikrit')
86
+ @session.click_button('awesome')
87
+ extract_results(@session)['password'].should == 'supasikrit'
88
+ end
90
89
 
91
- it "should fill in a password field by name" do
92
- @session.fill_in('form[password]', :with => 'supasikrit')
93
- @session.click_button('awesome')
94
- extract_results(@session)['password'].should == 'supasikrit'
95
- end
96
-
97
- it "should prefer exact matches over partial matches" do
98
- @session.fill_in('Name', :with => 'Ford Prefect')
99
- @session.click_button('awesome')
100
- extract_results(@session)['name'].should == 'Ford Prefect'
90
+ it "should throw an exception if a hash containing 'with' is not provided" do
91
+ lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
92
+ end
93
+
94
+ it "should wait for asynchronous load", :requires => [:js] do
95
+ @session.visit('/with_js')
96
+ @session.click_link('Click me')
97
+ @session.fill_in('new_field', :with => 'Testing...')
98
+ end
99
+
100
+ it "casts to string" do
101
+ @session.fill_in(:'form_first_name', :with => :'Harry')
102
+ @session.click_button('awesome')
103
+ extract_results(@session)['first_name'].should == 'Harry'
104
+ end
105
+
106
+ context 'on a pre-populated textfield with a reformatting onchange', :requires => [:js] do
107
+ it 'should only trigger onchange once' do
108
+ @session.visit('/with_js')
109
+ @session.fill_in('with_change_event', :with => 'some value')
110
+ @session.find(:css, '#with_change_event').value.should == 'some value'
101
111
  end
102
-
103
- it "should throw an exception if a hash containing 'with' is not provided" do
104
- lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
112
+ end
113
+
114
+ context "with ignore_hidden_fields" do
115
+ before { Capybara.ignore_hidden_elements = true }
116
+ after { Capybara.ignore_hidden_elements = false }
117
+ it "should not find a hidden field" do
118
+ msg = "Unable to find field \"Super Secret\""
119
+ expect do
120
+ @session.fill_in('Super Secret', :with => '777')
121
+ end.to raise_error(Capybara::ElementNotFound, msg)
105
122
  end
106
-
107
- context "with ignore_hidden_fields" do
108
- before { Capybara.ignore_hidden_elements = true }
109
- after { Capybara.ignore_hidden_elements = false }
110
- it "should not find a hidden field" do
111
- running do
112
- @session.fill_in('Super Secret', :with => '777')
113
- end.should raise_error(Capybara::ElementNotFound)
114
- end
123
+ end
124
+
125
+ context "with a locator that doesn't exist" do
126
+ it "should raise an error" do
127
+ msg = "Unable to find field \"does not exist\""
128
+ expect do
129
+ @session.fill_in('does not exist', :with => 'Blah blah')
130
+ end.to raise_error(Capybara::ElementNotFound, msg)
115
131
  end
132
+ end
116
133
 
117
- context "with a locator that doesn't exist" do
118
- it "should raise an error" do
119
- running do
120
- @session.fill_in('does not exist', :with => 'Blah blah')
121
- end.should raise_error(Capybara::ElementNotFound)
122
- end
134
+ context "on a disabled field" do
135
+ it "should raise an error" do
136
+ expect do
137
+ @session.fill_in('Disabled Text Field', :with => 'Blah blah')
138
+ end.to raise_error(Capybara::ElementNotFound)
123
139
  end
124
140
  end
125
141
  end
@@ -1,18 +1,20 @@
1
- shared_examples_for "find_button" do
2
- describe '#find_button' do
3
- before do
4
- @session.visit('/form')
5
- end
1
+ Capybara::SpecHelper.spec '#find_button' do
2
+ before do
3
+ @session.visit('/form')
4
+ end
5
+
6
+ it "should find any button" do
7
+ @session.find_button('med')[:id].should == "mediocre"
8
+ @session.find_button('crap321').value.should == "crappy"
9
+ end
6
10
 
7
- it "should find any field" do
8
- @session.find_button('med')[:id].should == "mediocre"
9
- @session.find_button('crap321').value.should == "crappy"
10
- end
11
+ it "casts to string" do
12
+ @session.find_button(:'med')[:id].should == "mediocre"
13
+ end
11
14
 
12
- it "should raise error if the field doesn't exist" do
13
- running do
14
- @session.find_button('Does not exist')
15
- end.should raise_error(Capybara::ElementNotFound)
16
- end
15
+ it "should raise error if the button doesn't exist" do
16
+ expect do
17
+ @session.find_button('Does not exist')
18
+ end.to raise_error(Capybara::ElementNotFound)
17
19
  end
18
20
  end