<commit_before>require 'spec_helper'

def uploaded_file(path, type)
  ActionDispatch::Http::UploadedFile.new(
    :filename => File.basename(path),
    :tempfile => File.open(path),
    :type => type
  )
end

describe 'Asciicast', :type => :feature, :js => true do

  def load_asciicast(id)
    FactoryGirl.create(
      :asciicast,
      :meta => uploaded_file(
        "spec/fixtures/asciicasts/#{id}/meta.json",
        'application/json'
      ),
      :stdout => fixture_file_upload(
        "spec/fixtures/asciicasts/#{id}/stdout",
        "application/octet-stream"
      ),
      :stdout_timing => fixture_file_upload(
        "spec/fixtures/asciicasts/#{id}/stdout.time",
        "application/octet-stream"
      )
    )
  end

  def visit_asciicast(id)
    asciicast = load_asciicast(id)
    visit "/a/#{asciicast.id}/raw?speed=2"
  end

  def inject_on_finished_callback
    page.execute_script(<<EOS)
      window.player.movie.on('finished', function() {
        $('body').append('<span class=\"finished\"></span>');
      })
EOS
  end

  Dir['spec/fixtures/asciicasts/*'].each do |dir|
    id = dir[/\d+/]

    describe "from fixture #{id}" do
      it "successfully plays to the end" do
        visit_asciicast(id)
        find(".play-button").find(".arrow").click
        inject_on_finished_callback
        page.should have_selector('body .finished')
      end
    end
  end

end<commit_msg>Use longer wait time for capybara in playback test<commit_after>require 'spec_helper'

def uploaded_file(path, type)
  ActionDispatch::Http::UploadedFile.new(
    :filename => File.basename(path),
    :tempfile => File.open(path),
    :type => type
  )
end

describe 'Asciicast playback', :type => :feature, :js => true do

  def load_asciicast(id)
    FactoryGirl.create(
      :asciicast,
      :meta => uploaded_file(
        "spec/fixtures/asciicasts/#{id}/meta.json",
        'application/json'
      ),
      :stdout => fixture_file_upload(
        "spec/fixtures/asciicasts/#{id}/stdout",
        "application/octet-stream"
      ),
      :stdout_timing => fixture_file_upload(
        "spec/fixtures/asciicasts/#{id}/stdout.time",
        "application/octet-stream"
      )
    )
  end

  def visit_asciicast(id)
    asciicast = load_asciicast(id)
    visit "/a/#{asciicast.id}/raw?speed=2"
  end

  def inject_on_finished_callback
    page.execute_script(<<EOS)
      window.player.movie.on('finished', function() {
        $('body').append('<span class=\"finished\"></span>');
      })
EOS
  end

  Dir['spec/fixtures/asciicasts/*'].each do |dir|
    id = dir[/\d+/]

    describe "from fixture #{id}" do
      before do
        @old_wait_time = Capybara.default_wait_time
        Capybara.default_wait_time = 120
      end

      after do
        Capybara.default_wait_time = @old_wait_time
      end

      it "is successful" do
        visit_asciicast(id)
        find(".play-button").find(".arrow").click
        inject_on_finished_callback
        page.should have_selector('body .finished')
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.14069690992767916, 'fraction_numerical': 0.001643655489809336, 'mean_word_length': 2.7246022031823744, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '6322995', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1026, 'n_words': 177}