/usr/lib/ruby/vendor_ruby/capybara/spec/session/click_button_spec.rb is in ruby-capybara 2.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | Capybara::SpecHelper.spec '#click_button' do
before do
@session.visit('/form')
end
it "should wait for asynchronous load", :requires => [:js] do
@session.visit('/with_js')
@session.click_link('Click me')
@session.click_button('New Here')
end
it "casts to string" do
@session.click_button(:'Relative Action')
@session.current_path.should == '/relative'
extract_results(@session)['relative'].should == 'Relative Action'
end
context "with multiple values with the same name" do
it "should use the latest given value" do
@session.check('Terms of Use')
@session.click_button('awesome')
extract_results(@session)['terms_of_use'].should == '1'
end
end
context "with a form that has a relative url as an action" do
it "should post to the correct url" do
@session.click_button('Relative Action')
@session.current_path.should == '/relative'
extract_results(@session)['relative'].should == 'Relative Action'
end
end
context "with a form that has no action specified" do
it "should post to the correct url" do
@session.click_button('No Action')
@session.current_path.should == '/form'
extract_results(@session)['no_action'].should == 'No Action'
end
end
context "with value given on a submit button" do
context "on a form with HTML5 fields" do
before do
@session.click_button('html5_submit')
@results = extract_results(@session)
end
it "should serialise and submit search fields" do
@results['html5_search'].should == 'what are you looking for'
end
it "should serialise and submit email fields" do
@results['html5_email'].should == 'person@email.com'
end
it "should serialise and submit url fields" do
@results['html5_url'].should == 'http://www.example.com'
end
it "should serialise and submit tel fields" do
@results['html5_tel'].should == '911'
end
it "should serialise and submit color fields" do
@results['html5_color'].upcase.should == '#FFFFFF'
end
end
context "on an HTML4 form" do
before do
@session.click_button('awesome')
@results = extract_results(@session)
end
it "should serialize and submit text fields" do
@results['first_name'].should == 'John'
end
it "should escape fields when submitting" do
@results['phone'].should == '+1 555 7021'
end
it "should serialize and submit password fields" do
@results['password'].should == 'seeekrit'
end
it "should serialize and submit hidden fields" do
@results['token'].should == '12345'
end
it "should not serialize fields from other forms" do
@results['middle_name'].should be_nil
end
it "should submit the button that was clicked, but not other buttons" do
@results['awesome'].should == 'awesome'
@results['crappy'].should be_nil
end
it "should serialize radio buttons" do
@results['gender'].should == 'female'
end
it "should default radio value to 'on' if none specified" do
@results['valueless_radio'].should == 'on'
end
it "should serialize check boxes" do
@results['pets'].should include('dog', 'hamster')
@results['pets'].should_not include('cat')
end
it "should default checkbox value to 'on' if none specififed" do
@results['valueless_checkbox'].should == 'on'
end
it "should serialize text areas" do
@results['description'].should == 'Descriptive text goes here'
end
it "should serialize select tag with values" do
@results['locale'].should == 'en'
end
it "should serialize select tag without values" do
@results['region'].should == 'Norway'
end
it "should serialize first option for select tag with no selection" do
@results['city'].should == 'London'
end
it "should not serialize a select tag without options" do
@results['tendency'].should be_nil
end
it "should convert lf to cr/lf in submitted textareas" do
@results['newline'].should == "\r\nNew line after and before textarea tag\r\n"
end
it "should not submit disabled fields" do
@results['disabled_text_field'].should be_nil
@results['disabled_textarea'].should be_nil
@results['disabled_checkbox'].should be_nil
@results['disabled_radio'].should be_nil
@results['disabled_select'].should be_nil
@results['disabled_file'].should be_nil
end
end
end
context "with id given on a submit button" do
it "should submit the associated form" do
@session.click_button('awe123')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('Go')
@session.should have_content('You landed')
end
end
context "with title given on a submit button" do
it "should submit the associated form" do
@session.click_button('What an Awesome Button')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('What an Awesome')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with fields associated with the form using the form attribute" do
before do
@session.click_button('submit_form1')
@results = extract_results(@session)
end
it "should serialize and submit text fields" do
@results['outside_input'].should == 'outside_input'
end
it "should serialize text areas" do
@results['outside_textarea'].should == 'Some text here'
end
it "should serialize select tags" do
@results['outside_select'].should == 'Ruby'
end
it "should not serliaze fields associated with a different form" do
@results['for_form2'].should be_nil
end
end
context "with submit button outside the form defined by <button> tag" do
before do
@session.click_button('outside_button')
@results = extract_results(@session)
end
it "should submit the associated form" do
@results['which_form'].should == 'form2'
end
it "should submit the button that was clicked, but not other buttons" do
@results['outside_button'].should == 'outside_button'
@results['unused'].should be_nil
end
end
context "with submit button outside the form defined by <input type='submit'> tag" do
before do
@session.click_button('outside_submit')
@results = extract_results(@session)
end
it "should submit the associated form" do
@results['which_form'].should == 'form1'
end
it "should submit the button that was clicked, but not other buttons" do
@results['outside_submit'].should == 'outside_submit'
@results['submit_form1'].should be_nil
end
end
context "with submit button for form1 located within form2" do
it "should submit the form associated with the button" do
@session.click_button('other_form_button')
extract_results(@session)['which_form'].should == "form1"
end
end
context "with submit button not associated with any form" do
it "should not error when clicked" do
lambda { @session.click_button('no_form_button') }.should_not raise_error
end
end
context "with alt given on an image button" do
it "should submit the associated form" do
@session.click_button('oh hai thar')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('hai')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with value given on an image button" do
it "should submit the associated form" do
@session.click_button('okay')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('kay')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with id given on an image button" do
it "should submit the associated form" do
@session.click_button('okay556')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with title given on an image button" do
it "should submit the associated form" do
@session.click_button('Okay 556 Image')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('Okay 556')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with text given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('Click me')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('Click')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with id given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('click_me_123')
extract_results(@session)['first_name'].should == 'John'
end
it "should serialize and send GET forms" do
@session.visit('/form')
@session.click_button('med')
@results = extract_results(@session)
@results['middle_name'].should == 'Darren'
@results['foo'].should be_nil
end
end
context "with value given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('click_me')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('ck_me')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with title given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('Click Title button')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('Click Title')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find button \"does not exist\""
expect do
@session.click_button('does not exist')
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
it "should serialize and send valueless buttons that were clicked" do
@session.click_button('No Value!')
@results = extract_results(@session)
@results['no_value'].should_not be_nil
end
it "should not send image buttons that were not clicked" do
@session.click_button('Click me!')
@results = extract_results(@session)
@results['okay'].should be_nil
end
it "should serialize and send GET forms" do
@session.visit('/form')
@session.click_button('med')
@results = extract_results(@session)
@results['middle_name'].should == 'Darren'
@results['foo'].should be_nil
end
it "should follow redirects" do
@session.click_button('Go FAR')
@session.current_url.should match(%r{/landed$})
@session.should have_content('You landed')
end
it "should post pack to the same URL when no action given" do
@session.visit('/postback')
@session.click_button('With no action')
@session.should have_content('Postback')
end
it "should post pack to the same URL when blank action given" do
@session.visit('/postback')
@session.click_button('With blank action')
@session.should have_content('Postback')
end
it "ignores disabled buttons" do
expect do
@session.click_button('Disabled button')
end.to raise_error(Capybara::ElementNotFound)
end
it "should encode complex field names, like array[][value]" do
@session.visit('/form')
@session.fill_in('address1_city', :with =>'Paris')
@session.fill_in('address1_street', :with =>'CDG')
@session.fill_in('address1_street', :with =>'CDG')
@session.select("France", :from => 'address1_country')
@session.fill_in('address2_city', :with => 'Mikolaiv')
@session.fill_in('address2_street', :with => 'PGS')
@session.select("Ukraine", :from => 'address2_country')
@session.click_button "awesome"
addresses=extract_results(@session)["addresses"]
addresses.should have(2).addresses
addresses[0]["street"].should == 'CDG'
addresses[0]["city"].should == 'Paris'
addresses[0]["country"].should == 'France'
addresses[1]["street"].should == 'PGS'
addresses[1]["city"].should == 'Mikolaiv'
addresses[1]["country"].should == 'Ukraine'
end
context "with :exact option" do
it "should accept partial matches when false" do
@session.click_button('What an Awesome', :exact => false)
extract_results(@session)['first_name'].should == 'John'
end
it "should not accept partial matches when true" do
expect do
@session.click_button('What an Awesome', :exact => true)
end.to raise_error(Capybara::ElementNotFound)
end
end
end
|