/usr/lib/ruby/vendor_ruby/capybara/spec/session/attach_file_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 | Capybara::SpecHelper.spec "#attach_file" do
before do
@test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
@another_test_file_path = File.expand_path('../fixtures/another_test_file.txt', File.dirname(__FILE__))
@test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
@session.visit('/form')
end
context "with normal form" do
it "should set a file path by id" do
@session.attach_file "form_image", __FILE__
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
it "should set a file path by label" do
@session.attach_file "Image", __FILE__
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
it "casts to string" do
@session.attach_file :"form_image", __FILE__
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
end
context "with multipart form" do
it "should set a file path by id" do
@session.attach_file "form_document", @test_file_path
@session.click_button('Upload Single')
@session.should have_content(File.read(@test_file_path))
end
it "should set a file path by label" do
@session.attach_file "Single Document", @test_file_path
@session.click_button('Upload Single')
@session.should have_content(File.read(@test_file_path))
end
it "should not break if no file is submitted" do
@session.click_button('Upload Single')
@session.should have_content('No file uploaded')
end
it "should send content type text/plain when uploading a text file" do
@session.attach_file "Single Document", @test_file_path
@session.click_button 'Upload Single'
@session.should have_content('text/plain')
end
it "should send content type image/jpeg when uploading an image" do
@session.attach_file "Single Document", @test_jpg_file_path
@session.click_button 'Upload Single'
@session.should have_content('image/jpeg')
end
it "should not break when using HTML5 multiple file input" do
@session.attach_file "Multiple Documents", @test_file_path
@session.click_button('Upload Multiple')
@session.body.should include("1 | ")#number of files
@session.should have_content(File.read(@test_file_path))
end
it "should not break when using HTML5 multiple file input uploading multiple files" do
pending "Selenium is buggy on this, see http://code.google.com/p/selenium/issues/detail?id=2239" if @session.respond_to?(:mode) && @session.mode.to_s =~ /^selenium/
@session.attach_file "Multiple Documents", [@test_file_path, @another_test_file_path]
@session.click_button('Upload Multiple')
@session.body.should include("2 | ")#number of files
@session.body.should include(File.read(@test_file_path))
@session.body.should include(File.read(@another_test_file_path))
end
it "should not send anything when attaching no files to a multiple upload field" do
@session.click_button('Upload Empty Multiple')
@session.body.should include("Successfully ignored empty file field")
end
end
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find file field \"does not exist\""
expect do
@session.attach_file('does not exist', @test_file_path)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
context "with a path that doesn't exist" do
it "should raise an error" do
expect { @session.attach_file('Image', '/no_such_file.png') }.to raise_error(Capybara::FileNotFound)
end
end
context "with :exact option" do
it "should set a file path by partial label when false" do
@session.attach_file "Imag", __FILE__, :exact => false
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
it "not allow partial matches when true" do
expect do
@session.attach_file "Imag", __FILE__, :exact => true
end.to raise_error(Capybara::ElementNotFound)
end
end
end
|