<commit_before>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 == :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))<commit_msg>fix test for changed session mode<commit_after>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) && [:selenium, :selenium_focus].include?(@session.mode)
      @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))
{'fraction_non_alphanumeric': 0.11268057784911717, 'fraction_numerical': 0.002568218298555377, 'mean_word_length': 3.883228840125392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2970431', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1849, 'n_words': 470}