Sha256: 427dc7598d94139907d5c5d46f17ec133fc0c984f3e803ff7e23307e9717e56d

Contents?: true

Size: 1.42 KB

Versions: 11

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'faker'
require 'titleize'

# rubocop:disable Metrics/BlockLength
shared_context 'media_shared' do
  let(:tmpdir) { File.join(MovieOrganizer.root, 'tmp') }
  let(:default_options) { { dry_run: true, verbose: true } }

  after(:each) do
    FileUtils.rm_rf(Dir.glob("#{tmpdir}/*"))
  end

  def random_season_episode_string
    season = (1..12).to_a.sample.to_s.rjust(2, '0')
    episode = (1..33).to_a.sample.to_s.rjust(2, '0')
    "S#{season}E#{episode}"
  end

  # The.Walking.Dead.S05E02.720p.HDTV.x264-KILLERS
  def fake_movie_name(extension, tvshow = true)
    if tvshow
      filename = "#{Faker::App.name}.#{random_season_episode_string}.#{extension}"
    else
      filename = "#{Faker::Hacker.verb.titleize} #{Faker::App.name}.#{extension}"
    end
    File.join(tmpdir, filename)
  end

  def create_test_file(options = {})
    tvshow    = options.fetch(:tvshow, true)
    count     = options.fetch(:count, 1)
    filename  = options.fetch(:filename, false)
    extension = options.fetch(:extension, 'mp4')
    files     = []

    if filename
      files = [File.join(tmpdir, "#{filename}.#{extension}")]
      File.open(files.last, 'w') { |f| f.write("Fake Media File\n") }
    else
      count.times do
        files << fake_movie_name(extension, tvshow)
        File.open(files.last, 'w') { |f| f.write("Fake Media File\n") }
      end
    end
    files
  end
end
# rubocop:enable Metrics/BlockLength

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
movie_organizer-0.1.10 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.9 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.8 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.7 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.6 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.5 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.4 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.3 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.2 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.1 spec/support/shared_contexts/media_shared.rb
movie_organizer-0.1.0 spec/support/shared_contexts/media_shared.rb