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,68 +1,85 @@
1
- shared_examples_for "check" do
1
+ Capybara::SpecHelper.spec "#check" do
2
+ before do
3
+ @session.visit('/form')
4
+ end
2
5
 
3
- describe "#check" do
4
- before do
5
- @session.visit('/form')
6
+ describe "'checked' attribute" do
7
+ it "should be true if checked" do
8
+ @session.check("Terms of Use")
9
+ @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
6
10
  end
7
11
 
8
- describe "'checked' attribute" do
9
- it "should be true if checked" do
10
- @session.check("Terms of Use")
11
- @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
12
- end
13
-
14
- it "should be false if unchecked" do
15
- @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
16
- end
12
+ it "should be false if unchecked" do
13
+ @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
17
14
  end
15
+ end
18
16
 
19
- describe "checking" do
20
- it "should not change an already checked checkbox" do
21
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
22
- @session.check('form_pets_dog')
23
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
24
- end
17
+ it "should trigger associated events", :requires => [:js] do
18
+ @session.visit('/with_js')
19
+ @session.check('checkbox_with_event')
20
+ @session.should have_css('#checkbox_event_triggered');
21
+ end
25
22
 
26
- it "should check an unchecked checkbox" do
27
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
28
- @session.check('form_pets_cat')
29
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true
30
- end
23
+ describe "checking" do
24
+ it "should not change an already checked checkbox" do
25
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
26
+ @session.check('form_pets_dog')
27
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
31
28
  end
32
29
 
33
- describe "unchecking" do
34
- it "should not change an already unchecked checkbox" do
35
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
36
- @session.uncheck('form_pets_cat')
37
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
38
- end
30
+ it "should check an unchecked checkbox" do
31
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
32
+ @session.check('form_pets_cat')
33
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true
34
+ end
35
+ end
39
36
 
40
- it "should uncheck a checked checkbox" do
41
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
42
- @session.uncheck('form_pets_dog')
43
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false
44
- end
37
+ describe "unchecking" do
38
+ it "should not change an already unchecked checkbox" do
39
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
40
+ @session.uncheck('form_pets_cat')
41
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
45
42
  end
46
43
 
47
- it "should check a checkbox by id" do
48
- @session.check("form_pets_cat")
49
- @session.click_button('awesome')
50
- extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
44
+ it "should uncheck a checked checkbox" do
45
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
46
+ @session.uncheck('form_pets_dog')
47
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false
51
48
  end
49
+ end
52
50
 
53
- it "should check a checkbox by label" do
54
- @session.check("Cat")
55
- @session.click_button('awesome')
56
- extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
51
+ it "should check a checkbox by id" do
52
+ @session.check("form_pets_cat")
53
+ @session.click_button('awesome')
54
+ extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
55
+ end
56
+
57
+ it "should check a checkbox by label" do
58
+ @session.check("Cat")
59
+ @session.click_button('awesome')
60
+ extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
61
+ end
62
+
63
+ it "casts to string" do
64
+ @session.check(:"form_pets_cat")
65
+ @session.click_button('awesome')
66
+ extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
67
+ end
68
+
69
+ context "with a locator that doesn't exist" do
70
+ it "should raise an error" do
71
+ msg = "Unable to find checkbox \"does not exist\""
72
+ expect do
73
+ @session.check('does not exist')
74
+ end.to raise_error(Capybara::ElementNotFound, msg)
57
75
  end
76
+ end
58
77
 
59
- context "with a locator that doesn't exist" do
60
- it "should raise an error" do
61
- msg = "Unable to find checkbox \"does not exist\""
62
- running do
63
- @session.check('does not exist')
64
- end.should raise_error(Capybara::ElementNotFound, msg)
65
- end
78
+ context "with a disabled checkbox" do
79
+ it "should raise an error" do
80
+ expect do
81
+ @session.check('Disabled Checkbox')
82
+ end.to raise_error(Capybara::ElementNotFound)
66
83
  end
67
84
  end
68
85
  end
@@ -1,29 +1,40 @@
1
- shared_examples_for "choose" do
1
+ Capybara::SpecHelper.spec "#choose" do
2
+ before do
3
+ @session.visit('/form')
4
+ end
2
5
 
3
- describe "#choose" do
4
- before do
5
- @session.visit('/form')
6
- end
6
+ it "should choose a radio button by id" do
7
+ @session.choose("gender_male")
8
+ @session.click_button('awesome')
9
+ extract_results(@session)['gender'].should == 'male'
10
+ end
7
11
 
8
- it "should choose a radio button by id" do
9
- @session.choose("gender_male")
10
- @session.click_button('awesome')
11
- extract_results(@session)['gender'].should == 'male'
12
- end
12
+ it "should choose a radio button by label" do
13
+ @session.choose("Both")
14
+ @session.click_button('awesome')
15
+ extract_results(@session)['gender'].should == 'both'
16
+ end
17
+
18
+ it "casts to string" do
19
+ @session.choose("Both")
20
+ @session.click_button(:'awesome')
21
+ extract_results(@session)['gender'].should == 'both'
22
+ end
13
23
 
14
- it "should choose a radio button by label" do
15
- @session.choose("Both")
16
- @session.click_button('awesome')
17
- extract_results(@session)['gender'].should == 'both'
24
+ context "with a locator that doesn't exist" do
25
+ it "should raise an error" do
26
+ msg = "Unable to find radio button \"does not exist\""
27
+ expect do
28
+ @session.choose('does not exist')
29
+ end.to raise_error(Capybara::ElementNotFound, msg)
18
30
  end
31
+ end
19
32
 
20
- context "with a locator that doesn't exist" do
21
- it "should raise an error" do
22
- msg = "Unable to find radio button \"does not exist\""
23
- running do
24
- @session.choose('does not exist')
25
- end.should raise_error(Capybara::ElementNotFound, msg)
26
- end
33
+ context "with a disabled radio button" do
34
+ it "should raise an error" do
35
+ expect do
36
+ @session.choose('Disabled Radio')
37
+ end.to raise_error(Capybara::ElementNotFound)
27
38
  end
28
39
  end
29
40
  end
@@ -1,268 +1,226 @@
1
- shared_examples_for "click_button" do
2
- describe '#click_button' do
3
- before do
4
- @session.visit('/form')
5
- end
1
+ Capybara::SpecHelper.spec '#click_button' do
2
+ before do
3
+ @session.visit('/form')
4
+ end
6
5
 
7
- context "with multiple values with the same name" do
8
- it "should use the latest given value" do
9
- @session.check('Terms of Use')
10
- @session.click_button('awesome')
11
- extract_results(@session)['terms_of_use'].should == '1'
12
- end
13
- 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_button('New Here')
10
+ end
14
11
 
15
- context "with a form that has a relative url as an action" do
16
- it "should post to the correct url" do
17
- @session.click_button('Relative Action')
18
- @session.current_path.should == '/relative'
19
- extract_results(@session)['relative'].should == 'Relative Action'
20
- end
12
+ it "casts to string" do
13
+ @session.click_button(:'Relative Action')
14
+ @session.current_path.should == '/relative'
15
+ extract_results(@session)['relative'].should == 'Relative Action'
16
+ end
17
+
18
+ context "with multiple values with the same name" do
19
+ it "should use the latest given value" do
20
+ @session.check('Terms of Use')
21
+ @session.click_button('awesome')
22
+ extract_results(@session)['terms_of_use'].should == '1'
21
23
  end
24
+ end
22
25
 
23
- context "with a form that has no action specified" do
24
- it "should post to the correct url" do
25
- @session.click_button('No Action')
26
- @session.current_path.should == '/form'
27
- extract_results(@session)['no_action'].should == 'No Action'
28
- end
26
+ context "with a form that has a relative url as an action" do
27
+ it "should post to the correct url" do
28
+ @session.click_button('Relative Action')
29
+ @session.current_path.should == '/relative'
30
+ extract_results(@session)['relative'].should == 'Relative Action'
29
31
  end
32
+ end
30
33
 
31
- context "with value given on a submit button" do
32
- context "on a form with HTML5 fields" do
33
- before do
34
- @session.click_button('html5_submit')
35
- @results = extract_results(@session)
36
- end
34
+ context "with a form that has no action specified" do
35
+ it "should post to the correct url" do
36
+ @session.click_button('No Action')
37
+ @session.current_path.should == '/form'
38
+ extract_results(@session)['no_action'].should == 'No Action'
39
+ end
40
+ end
37
41
 
38
- it "should serialise and submit search fields" do
39
- @results['html5_search'].should == 'what are you looking for'
40
- end
42
+ context "with value given on a submit button" do
43
+ context "on a form with HTML5 fields" do
44
+ before do
45
+ @session.click_button('html5_submit')
46
+ @results = extract_results(@session)
47
+ end
41
48
 
42
- it "should serialise and submit email fields" do
43
- @results['html5_email'].should == 'person@email.com'
44
- end
49
+ it "should serialise and submit search fields" do
50
+ @results['html5_search'].should == 'what are you looking for'
51
+ end
45
52
 
46
- it "should serialise and submit url fields" do
47
- @results['html5_url'].should == 'http://www.example.com'
48
- end
53
+ it "should serialise and submit email fields" do
54
+ @results['html5_email'].should == 'person@email.com'
55
+ end
49
56
 
50
- it "should serialise and submit tel fields" do
51
- @results['html5_tel'].should == '911'
52
- end
57
+ it "should serialise and submit url fields" do
58
+ @results['html5_url'].should == 'http://www.example.com'
59
+ end
53
60
 
54
- it "should serialise and submit color fields" do
55
- @results['html5_color'].should == '#FFFFFF'
56
- end
61
+ it "should serialise and submit tel fields" do
62
+ @results['html5_tel'].should == '911'
57
63
  end
58
64
 
59
- context "on an HTML4 form" do
60
- before do
61
- @session.click_button('awesome')
62
- @results = extract_results(@session)
63
- end
64
-
65
- it "should serialize and submit text fields" do
66
- @results['first_name'].should == 'John'
67
- end
68
-
69
- it "should escape fields when submitting" do
70
- @results['phone'].should == '+1 555 7021'
71
- end
72
-
73
- it "should serialize and submit password fields" do
74
- @results['password'].should == 'seeekrit'
75
- end
76
-
77
- it "should serialize and submit hidden fields" do
78
- @results['token'].should == '12345'
79
- end
80
-
81
- it "should not serialize fields from other forms" do
82
- @results['middle_name'].should be_nil
83
- end
84
-
85
- it "should submit the button that was clicked, but not other buttons" do
86
- @results['awesome'].should == 'awesome'
87
- @results['crappy'].should be_nil
88
- end
89
-
90
- it "should serialize radio buttons" do
91
- @results['gender'].should == 'female'
92
- end
93
-
94
- it "should serialize check boxes" do
95
- @results['pets'].should include('dog', 'hamster')
96
- @results['pets'].should_not include('cat')
97
- end
98
-
99
- it "should serialize text areas" do
100
- @results['description'].should == 'Descriptive text goes here'
101
- end
102
-
103
- it "should serialize select tag with values" do
104
- @results['locale'].should == 'en'
105
- end
106
-
107
- it "should serialize select tag without values" do
108
- @results['region'].should == 'Norway'
109
- end
110
-
111
- it "should serialize first option for select tag with no selection" do
112
- @results['city'].should == 'London'
113
- end
114
-
115
- it "should not serialize a select tag without options" do
116
- @results['tendency'].should be_nil
117
- end
118
-
119
- it "should not submit disabled fields" do
120
- @results['disabled_text_field'].should be_nil
121
- @results['disabled_textarea'].should be_nil
122
- @results['disabled_checkbox'].should be_nil
123
- @results['disabled_radio'].should be_nil
124
- @results['disabled_select'].should be_nil
125
- @results['disabled_file'].should be_nil
126
- end
65
+ it "should serialise and submit color fields" do
66
+ @results['html5_color'].should == '#FFFFFF'
127
67
  end
128
68
  end
129
69
 
130
- context "with id given on a submit button" do
131
- it "should submit the associated form" do
132
- @session.click_button('awe123')
133
- extract_results(@session)['first_name'].should == 'John'
70
+ context "on an HTML4 form" do
71
+ before do
72
+ @session.click_button('awesome')
73
+ @results = extract_results(@session)
134
74
  end
135
75
 
136
- it "should work with partial matches" do
137
- @session.click_button('Go')
138
- @session.body.should include('You landed')
76
+ it "should serialize and submit text fields" do
77
+ @results['first_name'].should == 'John'
139
78
  end
140
- end
141
79
 
142
- context "with title given on a submit button" do
143
- it "should submit the associated form" do
144
- @session.click_button('What an Awesome Button')
145
- extract_results(@session)['first_name'].should == 'John'
80
+ it "should escape fields when submitting" do
81
+ @results['phone'].should == '+1 555 7021'
146
82
  end
147
83
 
148
- it "should work with partial matches" do
149
- @session.click_button('What an Awesome')
150
- extract_results(@session)['first_name'].should == 'John'
84
+ it "should serialize and submit password fields" do
85
+ @results['password'].should == 'seeekrit'
151
86
  end
152
- end
153
87
 
154
- context "with alt given on an image button" do
155
- it "should submit the associated form" do
156
- @session.click_button('oh hai thar')
157
- extract_results(@session)['first_name'].should == 'John'
88
+ it "should serialize and submit hidden fields" do
89
+ @results['token'].should == '12345'
158
90
  end
159
91
 
160
- it "should work with partial matches" do
161
- @session.click_button('hai')
162
- extract_results(@session)['first_name'].should == 'John'
92
+ it "should not serialize fields from other forms" do
93
+ @results['middle_name'].should be_nil
163
94
  end
164
- end
165
95
 
166
- context "with value given on an image button" do
167
- it "should submit the associated form" do
168
- @session.click_button('okay')
169
- extract_results(@session)['first_name'].should == 'John'
96
+ it "should submit the button that was clicked, but not other buttons" do
97
+ @results['awesome'].should == 'awesome'
98
+ @results['crappy'].should be_nil
170
99
  end
171
100
 
172
- it "should work with partial matches" do
173
- @session.click_button('kay')
174
- extract_results(@session)['first_name'].should == 'John'
101
+ it "should serialize radio buttons" do
102
+ @results['gender'].should == 'female'
175
103
  end
176
- end
177
104
 
178
- context "with id given on an image button" do
179
- it "should submit the associated form" do
180
- @session.click_button('okay556')
181
- extract_results(@session)['first_name'].should == 'John'
105
+ it "should serialize check boxes" do
106
+ @results['pets'].should include('dog', 'hamster')
107
+ @results['pets'].should_not include('cat')
182
108
  end
183
- end
184
109
 
185
- context "with title given on an image button" do
186
- it "should submit the associated form" do
187
- @session.click_button('Okay 556 Image')
188
- extract_results(@session)['first_name'].should == 'John'
110
+ it "should serialize text areas" do
111
+ @results['description'].should == 'Descriptive text goes here'
189
112
  end
190
113
 
191
- it "should work with partial matches" do
192
- @session.click_button('Okay 556')
193
- extract_results(@session)['first_name'].should == 'John'
114
+ it "should serialize select tag with values" do
115
+ @results['locale'].should == 'en'
194
116
  end
195
- end
196
117
 
197
- context "with text given on a button defined by <button> tag" do
198
- it "should submit the associated form" do
199
- @session.click_button('Click me')
200
- extract_results(@session)['first_name'].should == 'John'
118
+ it "should serialize select tag without values" do
119
+ @results['region'].should == 'Norway'
201
120
  end
202
121
 
203
- it "should work with partial matches" do
204
- @session.click_button('Click')
205
- extract_results(@session)['first_name'].should == 'John'
122
+ it "should serialize first option for select tag with no selection" do
123
+ @results['city'].should == 'London'
206
124
  end
207
- end
208
125
 
209
- context "with id given on a button defined by <button> tag" do
210
- it "should submit the associated form" do
211
- @session.click_button('click_me_123')
212
- extract_results(@session)['first_name'].should == 'John'
126
+ it "should not serialize a select tag without options" do
127
+ @results['tendency'].should be_nil
213
128
  end
214
129
 
215
- it "should serialize and send GET forms" do
216
- @session.visit('/form')
217
- @session.click_button('med')
218
- @results = extract_results(@session)
219
- @results['middle_name'].should == 'Darren'
220
- @results['foo'].should be_nil
130
+ it "should not submit disabled fields" do
131
+ @results['disabled_text_field'].should be_nil
132
+ @results['disabled_textarea'].should be_nil
133
+ @results['disabled_checkbox'].should be_nil
134
+ @results['disabled_radio'].should be_nil
135
+ @results['disabled_select'].should be_nil
136
+ @results['disabled_file'].should be_nil
221
137
  end
222
138
  end
139
+ end
223
140
 
224
- context "with value given on a button defined by <button> tag" do
225
- it "should submit the associated form" do
226
- @session.click_button('click_me')
227
- extract_results(@session)['first_name'].should == 'John'
228
- end
141
+ context "with id given on a submit button" do
142
+ it "should submit the associated form" do
143
+ @session.click_button('awe123')
144
+ extract_results(@session)['first_name'].should == 'John'
145
+ end
229
146
 
230
- it "should work with partial matches" do
231
- @session.click_button('ck_me')
232
- extract_results(@session)['first_name'].should == 'John'
233
- end
147
+ it "should work with partial matches" do
148
+ @session.click_button('Go')
149
+ @session.should have_content('You landed')
234
150
  end
151
+ end
235
152
 
236
- context "with title given on a button defined by <button> tag" do
237
- it "should submit the associated form" do
238
- @session.click_button('Click Title button')
239
- extract_results(@session)['first_name'].should == 'John'
240
- end
153
+ context "with title given on a submit button" do
154
+ it "should submit the associated form" do
155
+ @session.click_button('What an Awesome Button')
156
+ extract_results(@session)['first_name'].should == 'John'
157
+ end
241
158
 
242
- it "should work with partial matches" do
243
- @session.click_button('Click Title')
244
- extract_results(@session)['first_name'].should == 'John'
245
- end
159
+ it "should work with partial matches" do
160
+ @session.click_button('What an Awesome')
161
+ extract_results(@session)['first_name'].should == 'John'
246
162
  end
247
- context "with a locator that doesn't exist" do
248
- it "should raise an error" do
249
- msg = "Unable to find button \"does not exist\""
250
- running do
251
- @session.click_button('does not exist')
252
- end.should raise_error(Capybara::ElementNotFound, msg)
253
- end
163
+ end
164
+
165
+ context "with alt given on an image button" do
166
+ it "should submit the associated form" do
167
+ @session.click_button('oh hai thar')
168
+ extract_results(@session)['first_name'].should == 'John'
254
169
  end
255
170
 
256
- it "should serialize and send valueless buttons that were clicked" do
257
- @session.click_button('No Value!')
258
- @results = extract_results(@session)
259
- @results['no_value'].should_not be_nil
171
+ it "should work with partial matches" do
172
+ @session.click_button('hai')
173
+ extract_results(@session)['first_name'].should == 'John'
260
174
  end
175
+ end
261
176
 
262
- it "should not send image buttons that were not clicked" do
263
- @session.click_button('Click me!')
264
- @results = extract_results(@session)
265
- @results['okay'].should be_nil
177
+ context "with value given on an image button" do
178
+ it "should submit the associated form" do
179
+ @session.click_button('okay')
180
+ extract_results(@session)['first_name'].should == 'John'
181
+ end
182
+
183
+ it "should work with partial matches" do
184
+ @session.click_button('kay')
185
+ extract_results(@session)['first_name'].should == 'John'
186
+ end
187
+ end
188
+
189
+ context "with id given on an image button" do
190
+ it "should submit the associated form" do
191
+ @session.click_button('okay556')
192
+ extract_results(@session)['first_name'].should == 'John'
193
+ end
194
+ end
195
+
196
+ context "with title given on an image button" do
197
+ it "should submit the associated form" do
198
+ @session.click_button('Okay 556 Image')
199
+ extract_results(@session)['first_name'].should == 'John'
200
+ end
201
+
202
+ it "should work with partial matches" do
203
+ @session.click_button('Okay 556')
204
+ extract_results(@session)['first_name'].should == 'John'
205
+ end
206
+ end
207
+
208
+ context "with text given on a button defined by <button> tag" do
209
+ it "should submit the associated form" do
210
+ @session.click_button('Click me')
211
+ extract_results(@session)['first_name'].should == 'John'
212
+ end
213
+
214
+ it "should work with partial matches" do
215
+ @session.click_button('Click')
216
+ extract_results(@session)['first_name'].should == 'John'
217
+ end
218
+ end
219
+
220
+ context "with id given on a button defined by <button> tag" do
221
+ it "should submit the associated form" do
222
+ @session.click_button('click_me_123')
223
+ extract_results(@session)['first_name'].should == 'John'
266
224
  end
267
225
 
268
226
  it "should serialize and send GET forms" do
@@ -272,24 +230,106 @@ shared_examples_for "click_button" do
272
230
  @results['middle_name'].should == 'Darren'
273
231
  @results['foo'].should be_nil
274
232
  end
233
+ end
275
234
 
276
- it "should follow redirects" do
277
- @session.click_button('Go FAR')
278
- @session.current_url.should match(%r{/landed$})
279
- @session.body.should include('You landed')
235
+ context "with value given on a button defined by <button> tag" do
236
+ it "should submit the associated form" do
237
+ @session.click_button('click_me')
238
+ extract_results(@session)['first_name'].should == 'John'
280
239
  end
281
240
 
282
- it "should post pack to the same URL when no action given" do
283
- @session.visit('/postback')
284
- @session.click_button('With no action')
285
- @session.body.should include('Postback')
241
+ it "should work with partial matches" do
242
+ @session.click_button('ck_me')
243
+ extract_results(@session)['first_name'].should == 'John'
244
+ end
245
+ end
246
+
247
+ context "with title given on a button defined by <button> tag" do
248
+ it "should submit the associated form" do
249
+ @session.click_button('Click Title button')
250
+ extract_results(@session)['first_name'].should == 'John'
286
251
  end
287
252
 
288
- it "should post pack to the same URL when blank action given" do
289
- @session.visit('/postback')
290
- @session.click_button('With blank action')
291
- @session.body.should include('Postback')
253
+ it "should work with partial matches" do
254
+ @session.click_button('Click Title')
255
+ extract_results(@session)['first_name'].should == 'John'
292
256
  end
293
257
  end
258
+ context "with a locator that doesn't exist" do
259
+ it "should raise an error" do
260
+ msg = "Unable to find button \"does not exist\""
261
+ expect do
262
+ @session.click_button('does not exist')
263
+ end.to raise_error(Capybara::ElementNotFound, msg)
264
+ end
265
+ end
266
+
267
+ it "should serialize and send valueless buttons that were clicked" do
268
+ @session.click_button('No Value!')
269
+ @results = extract_results(@session)
270
+ @results['no_value'].should_not be_nil
271
+ end
272
+
273
+ it "should not send image buttons that were not clicked" do
274
+ @session.click_button('Click me!')
275
+ @results = extract_results(@session)
276
+ @results['okay'].should be_nil
277
+ end
278
+
279
+ it "should serialize and send GET forms" do
280
+ @session.visit('/form')
281
+ @session.click_button('med')
282
+ @results = extract_results(@session)
283
+ @results['middle_name'].should == 'Darren'
284
+ @results['foo'].should be_nil
285
+ end
286
+
287
+ it "should follow redirects" do
288
+ @session.click_button('Go FAR')
289
+ @session.current_url.should match(%r{/landed$})
290
+ @session.should have_content('You landed')
291
+ end
292
+
293
+ it "should post pack to the same URL when no action given" do
294
+ @session.visit('/postback')
295
+ @session.click_button('With no action')
296
+ @session.should have_content('Postback')
297
+ end
298
+
299
+ it "should post pack to the same URL when blank action given" do
300
+ @session.visit('/postback')
301
+ @session.click_button('With blank action')
302
+ @session.should have_content('Postback')
303
+ end
304
+
305
+ it "ignores disabled buttons" do
306
+ expect do
307
+ @session.click_button('Disabled button')
308
+ end.to raise_error(Capybara::ElementNotFound)
309
+ end
310
+
311
+ it "should encode complex field names, like array[][value]" do
312
+ @session.visit('/form')
313
+ @session.fill_in('address1_city', :with =>'Paris')
314
+ @session.fill_in('address1_street', :with =>'CDG')
315
+ @session.fill_in('address1_street', :with =>'CDG')
316
+ @session.select("France", :from => 'address1_country')
294
317
 
318
+ @session.fill_in('address2_city', :with => 'Mikolaiv')
319
+ @session.fill_in('address2_street', :with => 'PGS')
320
+ @session.select("Ukraine", :from => 'address2_country')
321
+
322
+ @session.click_button "awesome"
323
+
324
+ addresses=extract_results(@session)["addresses"]
325
+ addresses.should have(2).addresses
326
+
327
+ addresses[0]["street"].should == 'CDG'
328
+ addresses[0]["city"].should == 'Paris'
329
+ addresses[0]["country"].should == 'France'
330
+
331
+ addresses[1]["street"].should == 'PGS'
332
+ addresses[1]["city"].should == 'Mikolaiv'
333
+ addresses[1]["country"].should == 'Ukraine'
334
+ end
295
335
  end