Skip to content

Commit

Permalink
Add Faker::App.semantic_version (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
PuZZleDucK authored and stympy committed Dec 8, 2017
1 parent 2a5c591 commit 08a7a03
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ GEM
i18n (0.9.1)
concurrent-ruby (~> 1.0)
minitest (5.10.3)
power_assert (1.0.2)
rake (12.0.0)
test-unit (3.2.5)
power_assert (1.1.1)
rake (12.3.0)
test-unit (3.2.6)
power_assert
timecop (0.9.1)

Expand Down
8 changes: 8 additions & 0 deletions doc/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ Faker::App.name #=> "Treeflex"
Faker::App.version #=> "0.7.9"

Faker::App.author #=> "Daphne Swift"

Faker::App.semantic_version #=> "3.2.5"

Faker::App.semantic_version(major: 42) #=> "42.5.2"

Faker::App.semantic_version(minor: 100..101) #=> "42.100.4"

Faker::App.semantic_version(patch: 5..6) #=> "7.2.6"
```
5 changes: 5 additions & 0 deletions lib/faker/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def version
def author
parse('app.author')
end

def semantic_version(major: 0..9, minor: 0..9, patch: 1..9)
[ major, minor, patch ].map {|chunk| Array(chunk).sample }.join('.')
end

end
end
end
49 changes: 49 additions & 0 deletions test/test_faker_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,53 @@ def test_name
assert @tester.author.match(/(\w+\.? ?){2,3}/)
end

def test_basic_semantic_version
10.times do |digits|
test_sem_vers = @tester.semantic_version().split(".")
assert test_sem_vers[0].match(/[0-9]{1}/)
assert test_sem_vers[1].match(/[0-9]{1}/)
assert test_sem_vers[2].match(/[1-9]{1}/)
end
end

def test_major_semantic_version
10.times do |digits|
test_sem_vers = @tester.semantic_version(major: (1000..9999)).split(".")
assert test_sem_vers[0].match(/[0-9]{4}/)
assert test_sem_vers[1].match(/[0-9]{1}/)
assert test_sem_vers[2].match(/[1-9]{1}/)
end
end

def test_minor_semantic_version
10.times do |digits|
test_sem_vers = @tester.semantic_version(minor: (1000..9999)).split(".")
assert test_sem_vers[0].match(/[0-9]{1}/)
assert test_sem_vers[1].match(/[0-9]{4}/)
assert test_sem_vers[2].match(/[1-9]{1}/)
end
end

def test_patch_semantic_version
10.times do |digits|
test_sem_vers = @tester.semantic_version(patch: (1000..9999)).split(".")
assert test_sem_vers[0].match(/[0-9]{1}/)
assert test_sem_vers[1].match(/[0-9]{1}/)
assert test_sem_vers[2].match(/[0-9]{4}/)
end
end

def test_all_semantic_version
10.times do |digits|
test_sem_vers = @tester.semantic_version(major: (1000..9999), minor: (1000..9999), patch: (1000..9999)).split(".")
assert test_sem_vers[0].match(/[0-9]{4}/)
assert test_sem_vers[1].match(/[0-9]{4}/)
assert test_sem_vers[2].match(/[0-9]{4}/)
end
end

def test_specific_major_version
assert @tester.semantic_version(major: 42).match(/42\.[0-9]\.[0-9]/)
end

end

0 comments on commit 08a7a03

Please sign in to comment.