File: test_faker_file.rb

package info (click to toggle)
ruby-faker 3.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,596 kB
  • sloc: ruby: 20,656; sh: 6; makefile: 6
file content (37 lines) | stat: -rw-r--r-- 1,046 bytes parent folder | download
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
# frozen_string_literal: true

require_relative '../../test_helper'

class TestFakerFile < Test::Unit::TestCase
  def setup
    @tester = Faker::File
  end

  def test_extension
    assert_match(/(flac|mp3|wav|bmp|gif|jpeg|jpg|png|tiff|css|csv|html|js|json|txt|mp4|avi|mov|webm|doc|docx|xls|xlsx|ppt|pptx|odt|ods|odp|pages|numbers|key|pdf)/, @tester.extension)
  end

  def test_mime_type_format
    assert_match %r{(.*)/(.*)+}, @tester.mime_type
  end

  def test_mime_type_format_with_media_type
    media_type = Faker::Base.translate('faker.file.mime_type').keys.sample

    assert_match %r{#{media_type}/(.*)+}, @tester.mime_type(media_type: media_type)
  end

  def test_file_name
    assert_match %r{^([a-z\-_.]+)(\\|/)([a-z\-_]+)\.([a-z0-9]+)$}, @tester
      .file_name
  end

  def test_dir
    assert_match %r{^(([a-z\-_.]+)(\\|/)){2}([a-z\-_.]+)$}, @tester.dir
  end

  def test_dir_with_args
    assert_match %r{^\\root(\\([a-z\-_.]+)){2}$}, @tester
      .dir(segment_count: 2, root: '\\root\\', directory_separator: '\\')
  end
end