Skip to content

Commit

Permalink
Merge pull request #45 from stympy/master
Browse files Browse the repository at this point in the history
 Add Faker::File.dir (stympy#1361)
  • Loading branch information
sanikkenway committed Jun 24, 2019
2 parents 211b147 + f03d4ee commit 457610b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,14 @@
Issue#
------

Example:

https://github.com/stympy/faker/issues/XXX

OR

`No-Story`

Description:
------
*Describe what this PR does in a few lines. If you are adding a new faker generator, please tell us how you're going to use this object. Use cases are important because we need to make sure that our faker generators are useful. After adding the description, please delete this line.*
8 changes: 7 additions & 1 deletion doc/default/file.md
Expand Up @@ -11,5 +11,11 @@ Faker::File.mime_type #=> "application/pdf"
Faker::File.file_name('path/to') #=> "path/to/something_random.jpg"
Faker::File.file_name('foo/bar', 'baz') #=> "foo/bar/baz.zip"
Faker::File.file_name('foo/bar', 'baz', 'doc') #=> "foo/bar/baz.doc"
Faker::File.file_name('foo/bar', 'baz', 'mp3', '\') #=> "foo\bar\baz.mp3"
Faker::File.file_name('foo/bar', 'baz', 'mp3', '\\') #=> "foo\bar\baz.mp3"

# Optional arguments: segment_count, root, directory_separator
Faker::File.dir #=> "path/to/something_random"
Faker::File.dir(2) #=> "foo/bar"
Faker::File.dir(3, '/') #=> "/foo/bar/baz"
Faker::File.dir(3, nil, '\\') #=> "foo\bar\baz"
```
8 changes: 7 additions & 1 deletion doc/unreleased/default/file.md
Expand Up @@ -11,5 +11,11 @@ Faker::File.mime_type #=> "application/pdf"
Faker::File.file_name('path/to') #=> "path/to/something_random.jpg"
Faker::File.file_name('foo/bar', 'baz') #=> "foo/bar/baz.zip"
Faker::File.file_name('foo/bar', 'baz', 'doc') #=> "foo/bar/baz.doc"
Faker::File.file_name('foo/bar', 'baz', 'mp3', '\') #=> "foo\bar\baz.mp3"
Faker::File.file_name('foo/bar', 'baz', 'mp3', '\\') #=> "foo\bar\baz.mp3"

# Optional arguments: segment_count, root, directory_separator
Faker::File.dir #=> "path/to/something_random"
Faker::File.dir(2) #=> "foo/bar"
Faker::File.dir(3, '/') #=> "/foo/bar/baz"
Faker::File.dir(3, nil, '\\') #=> "foo\bar\baz"
```
11 changes: 10 additions & 1 deletion lib/faker/default/file.rb
Expand Up @@ -3,6 +3,15 @@
module Faker
class File < Base
class << self
def dir(segment_count = 3, root = nil, directory_separator = '/')
Array
.new(segment_count) { Faker::Internet.slug }
.unshift(root)
.compact
.join(directory_separator)
.squeeze(directory_separator)
end

def extension
fetch('file.extension')
end
Expand All @@ -12,7 +21,7 @@ def mime_type
end

def file_name(dir = nil, name = nil, ext = nil, directory_separator = '/')
dir ||= Faker::Internet.slug
dir ||= dir(1)
name ||= Faker::Lorem.word.downcase
ext ||= extension

Expand Down
5 changes: 5 additions & 0 deletions lib/faker/default/number.rb
Expand Up @@ -3,6 +3,8 @@
module Faker
class Number < Base
class << self
extend Gem::Deprecate

def number(digits = 10)
num = ''

Expand Down Expand Up @@ -92,6 +94,9 @@ def should_be(number, method_to_compare)
number * -1
end
end

deprecate :decimal_part, nil, 2019, 06
deprecate :leading_zero_number, nil, 2019, 06
end
end
end
14 changes: 13 additions & 1 deletion test/faker/default/test_faker_file.rb
Expand Up @@ -16,6 +16,18 @@ def test_mime_type_format
end

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

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

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

0 comments on commit 457610b

Please sign in to comment.