Skip to content

Commit

Permalink
Merge pull request faker-ruby#143 from myitcv/username_range_support_…
Browse files Browse the repository at this point in the history
…separators

Internet::user_name range to support separators
  • Loading branch information
stympy committed Nov 8, 2013
2 parents fbe6ab0 + ef28feb commit 35ae2b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/faker/internet.rb
Expand Up @@ -20,7 +20,7 @@ def user_name(specifier = nil, separators = %w(. _))
elsif specifier.kind_of? Integer
tries = 0 # Don't try forever in case we get something like 1_000_000.
begin
result = user_name
result = user_name nil, separators
tries += 1
end while result.length < specifier and tries < 7
until result.length >= specifier
Expand All @@ -30,7 +30,7 @@ def user_name(specifier = nil, separators = %w(. _))
elsif specifier.kind_of? Range
tries = 0
begin
result = user_name specifier.min
result = user_name specifier.min, separators
tries += 1
end while not specifier.include? result.length and tries < 7
return result[0...specifier.max]
Expand Down
9 changes: 9 additions & 0 deletions test/test_faker_internet.rb
Expand Up @@ -52,6 +52,15 @@ def test_user_name_with_open_range_arg
end
end

def test_user_name_with_range_and_separators
(1..32).each do |min_length|
(min_length+1..33).each do |max_length|
u = @tester.user_name((min_length...max_length), %w(=))
assert u.length.between? min_length, max_length-1
assert u.match(/\A[a-z]+((=)?[a-z]*)*\z/)
end
end
end

def test_password
assert @tester.password.match(/\w{3}/)
Expand Down

0 comments on commit 35ae2b9

Please sign in to comment.