capybara 2.0.0.beta2 → 2.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +30 -1
  2. data/README.md +52 -31
  3. data/lib/capybara.rb +1 -0
  4. data/lib/capybara/driver/base.rb +1 -1
  5. data/lib/capybara/driver/node.rb +1 -0
  6. data/lib/capybara/dsl.rb +12 -5
  7. data/lib/capybara/helpers.rb +33 -0
  8. data/lib/capybara/node/actions.rb +4 -2
  9. data/lib/capybara/node/base.rb +52 -1
  10. data/lib/capybara/node/element.rb +0 -12
  11. data/lib/capybara/node/finders.rb +1 -1
  12. data/lib/capybara/node/matchers.rb +57 -47
  13. data/lib/capybara/node/simple.rb +4 -0
  14. data/lib/capybara/query.rb +11 -11
  15. data/lib/capybara/rack_test/browser.rb +14 -15
  16. data/lib/capybara/rack_test/driver.rb +2 -2
  17. data/lib/capybara/rack_test/node.rb +15 -2
  18. data/lib/capybara/result.rb +7 -19
  19. data/lib/capybara/rspec.rb +7 -4
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +8 -3
  22. data/lib/capybara/selector.rb +1 -2
  23. data/lib/capybara/selenium/driver.rb +2 -2
  24. data/lib/capybara/selenium/node.rb +9 -7
  25. data/lib/capybara/session.rb +47 -31
  26. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  27. data/lib/capybara/spec/public/test.js +1 -1
  28. data/lib/capybara/spec/session/all_spec.rb +60 -62
  29. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  30. data/lib/capybara/spec/session/attach_file_spec.rb +72 -58
  31. data/lib/capybara/spec/session/body_spec.rb +21 -0
  32. data/lib/capybara/spec/session/check_spec.rb +67 -50
  33. data/lib/capybara/spec/session/choose_spec.rb +32 -21
  34. data/lib/capybara/spec/session/click_button_spec.rb +261 -221
  35. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -30
  36. data/lib/capybara/spec/session/click_link_spec.rb +95 -81
  37. data/lib/capybara/spec/session/current_url_spec.rb +70 -60
  38. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  39. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  40. data/lib/capybara/spec/session/fill_in_spec.rb +118 -92
  41. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  42. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  43. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  44. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  45. data/lib/capybara/spec/session/find_spec.rb +96 -91
  46. data/lib/capybara/spec/session/first_spec.rb +53 -55
  47. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  48. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  49. data/lib/capybara/spec/session/has_field_spec.rb +167 -169
  50. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  51. data/lib/capybara/spec/session/has_select_spec.rb +175 -176
  52. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  53. data/lib/capybara/spec/session/has_table_spec.rb +22 -26
  54. data/lib/capybara/spec/session/has_text_spec.rb +159 -132
  55. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  56. data/lib/capybara/spec/session/headers.rb +4 -17
  57. data/lib/capybara/spec/session/html_spec.rb +15 -0
  58. data/lib/capybara/spec/session/node_spec.rb +172 -82
  59. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  60. data/lib/capybara/spec/session/response_code.rb +4 -17
  61. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  62. data/lib/capybara/spec/session/screenshot.rb +8 -24
  63. data/lib/capybara/spec/session/select_spec.rb +100 -89
  64. data/lib/capybara/spec/session/source_spec.rb +12 -0
  65. data/lib/capybara/spec/session/text_spec.rb +15 -17
  66. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  67. data/lib/capybara/spec/session/unselect_spec.rb +57 -52
  68. data/lib/capybara/spec/session/visit_spec.rb +58 -60
  69. data/lib/capybara/spec/session/within_frame_spec.rb +24 -26
  70. data/lib/capybara/spec/session/within_spec.rb +119 -121
  71. data/lib/capybara/spec/session/within_window_spec.rb +29 -31
  72. data/lib/capybara/spec/spec_helper.rb +84 -0
  73. data/lib/capybara/spec/test_app.rb +5 -3
  74. data/lib/capybara/spec/views/form.erb +1 -0
  75. data/lib/capybara/spec/views/with_html.erb +6 -1
  76. data/lib/capybara/spec/views/with_js.erb +1 -0
  77. data/lib/capybara/version.rb +1 -1
  78. data/spec/basic_node_spec.rb +2 -2
  79. data/spec/capybara_spec.rb +9 -0
  80. data/spec/dsl_spec.rb +22 -10
  81. data/spec/rack_test_spec.rb +28 -23
  82. data/spec/result_spec.rb +51 -0
  83. data/spec/rspec/features_spec.rb +19 -0
  84. data/spec/rspec/matchers_spec.rb +6 -0
  85. data/spec/rspec_spec.rb +1 -1
  86. data/spec/selenium_spec.rb +11 -25
  87. data/spec/server_spec.rb +2 -2
  88. data/spec/spec_helper.rb +1 -46
  89. metadata +41 -98
  90. data/lib/capybara/spec/session.rb +0 -183
  91. data/lib/capybara/spec/session/javascript.rb +0 -290
  92. data/lib/capybara/util/save_and_open_page.rb +0 -45
  93. data/spec/save_and_open_page_spec.rb +0 -155
@@ -1,37 +1,47 @@
1
- shared_examples_for "click_link_or_button" do
2
- describe '#click' do
3
- it "should click on a link" do
4
- @session.visit('/with_html')
5
- @session.click_link_or_button('labore')
6
- @session.body.should include('Bar')
7
- end
1
+ Capybara::SpecHelper.spec '#click_link_or_button' do
2
+ it "should click on a link" do
3
+ @session.visit('/with_html')
4
+ @session.click_link_or_button('labore')
5
+ @session.should have_content('Bar')
6
+ end
8
7
 
9
- it "should click on a button" do
10
- @session.visit('/form')
11
- @session.click_link_or_button('awe123')
12
- extract_results(@session)['first_name'].should == 'John'
13
- end
8
+ it "should click on a button" do
9
+ @session.visit('/form')
10
+ @session.click_link_or_button('awe123')
11
+ extract_results(@session)['first_name'].should == 'John'
12
+ end
14
13
 
15
- it "should click on a button with no type attribute" do
16
- @session.visit('/form')
17
- @session.click_link_or_button('no_type')
18
- extract_results(@session)['first_name'].should == 'John'
19
- end
14
+ it "should click on a button with no type attribute" do
15
+ @session.visit('/form')
16
+ @session.click_link_or_button('no_type')
17
+ extract_results(@session)['first_name'].should == 'John'
18
+ end
20
19
 
21
- it "should be aliased as click_on" do
22
- @session.visit('/form')
23
- @session.click_on('awe123')
24
- extract_results(@session)['first_name'].should == 'John'
25
- end
20
+ it "should be aliased as click_on" do
21
+ @session.visit('/form')
22
+ @session.click_on('awe123')
23
+ extract_results(@session)['first_name'].should == 'John'
24
+ end
25
+
26
+ it "should wait for asynchronous load", :requires => [:js] do
27
+ @session.visit('/with_js')
28
+ @session.click_link('Click me')
29
+ @session.click_link_or_button('Has been clicked')
30
+ end
26
31
 
27
- context "with a locator that doesn't exist" do
28
- it "should raise an error" do
29
- @session.visit('/with_html')
30
- msg = "Unable to find link or button \"does not exist\""
31
- running do
32
- @session.click_link_or_button('does not exist')
33
- end.should raise_error(Capybara::ElementNotFound, msg)
34
- end
32
+ it "casts to string" do
33
+ @session.visit('/form')
34
+ @session.click_link_or_button(:'awe123')
35
+ extract_results(@session)['first_name'].should == 'John'
36
+ end
37
+
38
+ context "with a locator that doesn't exist" do
39
+ it "should raise an error" do
40
+ @session.visit('/with_html')
41
+ msg = "Unable to find link or button \"does not exist\""
42
+ expect do
43
+ @session.click_link_or_button('does not exist')
44
+ end.to raise_error(Capybara::ElementNotFound, msg)
35
45
  end
36
46
  end
37
47
  end
@@ -1,105 +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
12
+ it "casts to string" do
13
+ @session.click_link(:'foo')
14
+ @session.should have_content('Another World')
15
+ end
19
16
 
20
- it "should accept partial matches" do
21
- @session.click_link('abo')
22
- @session.body.should include('Bar')
23
- 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')
24
21
  end
22
+ end
25
23
 
26
- context "with title given" do
27
- it "should take user to the linked page" do
28
- @session.click_link('awesome title')
29
- @session.body.should include('Bar')
30
- end
31
-
32
- it "should accept partial matches" do
33
- @session.click_link('some tit')
34
- @session.body.should include('Bar')
35
- 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')
36
28
  end
37
29
 
38
- context "with alternative text given to a contained image" do
39
- it "should take user to the linked page" do
40
- @session.click_link('awesome image')
41
- @session.body.should include('Bar')
42
- end
43
-
44
- it "should take user to the linked page" do
45
- @session.click_link('some imag')
46
- @session.body.should include('Bar')
47
- end
30
+ it "should accept partial matches" do
31
+ @session.click_link('abo')
32
+ @session.should have_content('Bar')
48
33
  end
34
+ end
49
35
 
50
- context "with a locator that doesn't exist" do
51
- it "should raise an error" do
52
- msg = "Unable to find link \"does not exist\""
53
- running do
54
- @session.click_link('does not exist')
55
- end.should raise_error(Capybara::ElementNotFound, msg)
56
- end
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')
57
40
  end
58
41
 
59
- it "should follow relative links" do
60
- @session.visit('/')
61
- @session.click_link('Relative')
62
- @session.body.should include('This is a test')
42
+ it "should accept partial matches" do
43
+ @session.click_link('some titl')
44
+ @session.should have_content('Bar')
63
45
  end
46
+ end
64
47
 
65
- it "should follow redirects" do
66
- @session.click_link('Redirect')
67
- @session.body.should include('You landed')
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')
68
52
  end
69
53
 
70
- it "should follow redirects" do
71
- @session.click_link('BackToMyself')
72
- @session.body.should include('This is a test')
54
+ it "should accept partial matches" do
55
+ @session.click_link('some imag')
56
+ @session.should have_content('Bar')
73
57
  end
58
+ end
74
59
 
75
- it "should add query string to current URL with naked query string" do
76
- @session.click_link('Naked Query String')
77
- @session.body.should include('Query String sent')
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)
78
66
  end
67
+ end
79
68
 
80
- it "should do nothing on anchor links" do
81
- @session.fill_in("test_field", :with => 'blah')
82
- @session.click_link('Normal Anchor')
83
- @session.find_field("test_field").value.should == 'blah'
84
- @session.click_link('Blank Anchor')
85
- @session.find_field("test_field").value.should == 'blah'
86
- 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
87
74
 
88
- it "should do nothing on URL+anchor links for the same page" do
89
- @session.fill_in("test_field", :with => 'blah')
90
- @session.click_link('Anchor on same page')
91
- @session.find_field("test_field").value.should == 'blah'
92
- end
75
+ it "should follow protocol relative links" do
76
+ @session.click_link('Protocol')
77
+ @session.should have_content('Another World')
78
+ end
93
79
 
94
- it "should follow link on URL+anchor links for a different page" do
95
- @session.click_link('Anchor on different page')
96
- @session.body.should include('Bar')
97
- end
80
+ it "should follow redirects" do
81
+ @session.click_link('Redirect')
82
+ @session.should have_content('You landed')
83
+ end
98
84
 
99
- it "raise an error with links with no href" do
100
- running do
101
- @session.click_link('No Href')
102
- end.should raise_error(Capybara::ElementNotFound)
103
- end
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)
104
118
  end
105
119
  end
@@ -1,4 +1,4 @@
1
- shared_examples_for "current_url" do
1
+ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
2
2
  before :all do
3
3
  @servers = 2.times.map { Capybara::Server.new(TestApp.clone).boot }
4
4
  # sanity check
@@ -10,74 +10,84 @@ shared_examples_for "current_url" do
10
10
  @servers.map { |s| "http://#{s.host}:#{s.port}" }
11
11
  end
12
12
 
13
- describe '#current_url, #current_path, #current_host' do
14
- def should_be_on server_index, path="/host", scheme="http"
15
- # Check that we are on /host on the given server
16
- s = @servers[server_index]
17
- @session.current_url.chomp('?').should == "#{scheme}://#{s.host}:#{s.port}#{path}"
18
- @session.current_host.should == "#{scheme}://#{s.host}" # no port
19
- @session.current_path.should == path
20
- if path == '/host'
21
- # Server should agree with us
22
- @session.body.should include("Current host is #{scheme}://#{s.host}:#{s.port}")
23
- end
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}")
24
22
  end
23
+ end
25
24
 
26
- def visit_host_links
27
- @session.visit("#{bases[0]}/host_links?absolute_host=#{bases[1]}")
28
- end
25
+ def visit_host_links
26
+ @session.visit("#{bases[0]}/host_links?absolute_host=#{bases[1]}")
27
+ end
29
28
 
30
- it "is affected by visiting a page directly" do
31
- @session.visit("#{bases[0]}/host")
32
- should_be_on 0
33
- end
29
+ it "is affected by visiting a page directly" do
30
+ @session.visit("#{bases[0]}/host")
31
+ should_be_on 0
32
+ end
34
33
 
35
- it "returns to the app host when visiting a relative url" do
36
- Capybara.app_host = bases[1]
37
- @session.visit("#{bases[0]}/host")
38
- should_be_on 0
39
- @session.visit('/host')
40
- should_be_on 1
41
- Capybara.app_host = nil
42
- end
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
43
42
 
44
- it "is affected by setting Capybara.app_host" do
45
- Capybara.app_host = bases[0]
46
- @session.visit("/host")
47
- should_be_on 0
48
- Capybara.app_host = bases[1]
49
- @session.visit("/host")
50
- should_be_on 1
51
- Capybara.app_host = nil
52
- end
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
53
52
 
54
- it "is unaffected by following a relative link" do
55
- visit_host_links
56
- @session.click_link("Relative Host")
57
- should_be_on 0
58
- end
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
59
58
 
60
- it "is affected by following an absolute link" do
61
- visit_host_links
62
- @session.click_link("Absolute Host")
63
- should_be_on 1
64
- end
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
65
64
 
66
- it "is unaffected by posting through a relative form" do
67
- visit_host_links
68
- @session.click_button("Relative Host")
69
- should_be_on 0
70
- end
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
71
70
 
72
- it "is affected by posting through an absolute form" do
73
- visit_host_links
74
- @session.click_button("Absolute Host")
75
- should_be_on 1
76
- end
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
77
76
 
78
- it "is affected by following a redirect" do
79
- @session.visit("#{bases[0]}/redirect")
80
- should_be_on 0, "/landed"
81
- end
77
+ it "is affected by following a redirect" do
78
+ @session.visit("#{bases[0]}/redirect")
79
+ should_be_on 0, "/landed"
82
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
83
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,115 +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('First Name', :with => 'Harry')
21
- @session.click_button('awesome')
22
- extract_results(@session)['first_name'].should == 'Harry'
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 fill in a textarea by id" do
32
- @session.fill_in('form_description', :with => 'Texty text')
33
- @session.click_button('awesome')
34
- extract_results(@session)['description'].should == 'Texty text'
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 label" do
38
- @session.fill_in('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 name" do
44
- @session.fill_in('form[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 password field by id" do
50
- @session.fill_in('form_password', :with => 'supasikrit')
51
- @session.click_button('awesome')
52
- extract_results(@session)['password'].should == 'supasikrit'
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 field with a custom type" do
56
- @session.fill_in('Schmooo', :with => 'Schmooo is the game')
57
- @session.click_button('awesome')
58
- extract_results(@session)['schmooo'].should == 'Schmooo is the game'
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 without a type" do
62
- @session.fill_in('Phone', :with => '+1 555 7022')
63
- @session.click_button('awesome')
64
- extract_results(@session)['phone'].should == '+1 555 7022'
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 text field respecting its maxlength attribute" do
68
- @session.fill_in('Zipcode', :with => '52071350')
69
- @session.click_button('awesome')
70
- extract_results(@session)['zipcode'].should == '52071'
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 password field by name" do
74
- @session.fill_in('form[password]', :with => 'supasikrit')
75
- @session.click_button('awesome')
76
- extract_results(@session)['password'].should == 'supasikrit'
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 label" do
80
- @session.fill_in('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
83
+
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
84
89
 
85
- it "should fill in a password field by name" do
86
- @session.fill_in('form[password]', :with => 'supasikrit')
87
- @session.click_button('awesome')
88
- extract_results(@session)['password'].should == 'supasikrit'
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'
89
111
  end
112
+ end
90
113
 
91
- it "should throw an exception if a hash containing 'with' is not provided" do
92
- lambda{@session.fill_in 'Name', 'ignu'}.should raise_error
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)
93
122
  end
123
+ end
94
124
 
95
- context "with ignore_hidden_fields" do
96
- before { Capybara.ignore_hidden_elements = true }
97
- after { Capybara.ignore_hidden_elements = false }
98
- it "should not find a hidden field" do
99
- msg = "Unable to find field \"Super Secret\""
100
- running do
101
- @session.fill_in('Super Secret', :with => '777')
102
- end.should raise_error(Capybara::ElementNotFound, msg)
103
- end
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)
104
131
  end
132
+ end
105
133
 
106
- context "with a locator that doesn't exist" do
107
- it "should raise an error" do
108
- msg = "Unable to find field \"does not exist\""
109
- running do
110
- @session.fill_in('does not exist', :with => 'Blah blah')
111
- end.should raise_error(Capybara::ElementNotFound, msg)
112
- 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)
113
139
  end
114
140
  end
115
141
  end