Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing tests after adding Coveralls #1213

Merged
merged 7 commits into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions doc/measurement.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,49 @@ Faker::Measurement.height #=> "6 inches"

Faker::Measurement.height(1.4) #=> "1.4 inches"

Faker::Measurement.height("none") #=> "inch"
Faker::Measurement.height_none #=> "inch"

Faker::Measurement.height("all") #=> "inches"
Faker::Measurement.height_all #=> "inches"

Faker::Measurement.length #=> "1 yard"

Faker::Measurement.length_none #=> "yard"

Faker::Measurement.length_all #=> "yards"

Faker::Measurement.volume #=> "10 cups"

Faker::Measurement.volume_none #=> "cup"

Faker::Measurement.volume_all #=> "cups"

Faker::Measurement.weight #=> "3 pounds"

Faker::Measurement.weight_none #=> "pound"

Faker::Measurement.weight_all #=> "pounds"

Faker::Measurement.metric_height #=> "2 meters"

Faker::Measurement.metric_height_none #=> "meter"

Faker::Measurement.metric_height_all #=> "meters"

Faker::Measurement.metric_length #=> "0 decimeters"

Faker::Measurement.metric_length_none #=> "decimeter"

Faker::Measurement.metric_length_all #=> "decimeters"

Faker::Measurement.metric_volume #=> "1 liter"

Faker::Measurement.metric_volume_none #=> "liter"

Faker::Measurement.metric_volume_all #=> "liters"

Faker::Measurement.metric_weight #=> "8 grams"

Faker::Measurement.metric_weight_none #=> "gram"

Faker::Measurement.metric_weight_all #=> "grams"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reverted the measurement object changes in this commit. They were incorrect.

```
4 changes: 0 additions & 4 deletions lib/faker/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ def domain_name
with_locale(:en) { [Char.prepare(domain_word), domain_suffix].join('.') }
end

def fix_umlauts(string = '')
Char.fix_umlauts(string)
end

def domain_word
with_locale(:en) { Char.prepare(Company.name.split(' ').first) }
end
Expand Down
141 changes: 81 additions & 60 deletions lib/faker/measurement.rb
Original file line number Diff line number Diff line change
@@ -1,101 +1,122 @@
module Faker
class Measurement < Base
class << self
ALL = 'all'.freeze
NONE = 'none'.freeze

def height(amount = rand(10))
ensure_valid_amount(amount)
if amount == ALL
make_plural(fetch('measurement.height'))
elsif amount == NONE
fetch('measurement.height')
else
"#{amount} #{check_for_plural(fetch('measurement.height'), amount)}"
end

"#{amount} #{check_for_plural(fetch('measurement.height'), amount)}"
end

def height_all
make_plural(fetch('measurement.height'))
end

def height_none
fetch('measurement.height')
end

def length(amount = rand(10))
ensure_valid_amount(amount)
if amount == ALL
make_plural(fetch('measurement.length'))
elsif amount == NONE
fetch('measurement.length')
else
"#{amount} #{check_for_plural(fetch('measurement.length'), amount)}"
end

"#{amount} #{check_for_plural(fetch('measurement.length'), amount)}"
end

def length_all
make_plural(fetch('measurement.length'))
end

def length_none
fetch('measurement.length')
end

def volume(amount = rand(10))
ensure_valid_amount(amount)
if amount == ALL
make_plural(fetch('measurement.volume'))
elsif amount == NONE
fetch('measurement.volume')
else
"#{amount} #{check_for_plural(fetch('measurement.volume'), amount)}"
end

"#{amount} #{check_for_plural(fetch('measurement.volume'), amount)}"
end

def volume_all
make_plural(fetch('measurement.volume'))
end

def volume_none
fetch('measurement.volume')
end

def weight(amount = rand(10))
ensure_valid_amount(amount)
if amount == ALL
make_plural(fetch('measurement.weight'))
elsif amount == NONE
fetch('measurement.weight')
else
"#{amount} #{check_for_plural(fetch('measurement.weight'), amount)}"
end

"#{amount} #{check_for_plural(fetch('measurement.weight'), amount)}"
end

def weight_all
make_plural(fetch('measurement.weight'))
end

def weight_none
fetch('measurement.weight')
end

def metric_height(amount = rand(10))
ensure_valid_amount(amount)
if amount == ALL
make_plural(fetch('measurement.height'))
elsif amount == NONE
fetch('measurement.height')
else
"#{amount} #{check_for_plural(fetch('measurement.height'), amount)}"
end

"#{amount} #{check_for_plural(fetch('measurement.metric_height'), amount)}"
end

def metric_height_all
make_plural(fetch('measurement.metric_height'))
end

def metric_height_none
fetch('measurement.metric_height')
end

def metric_length(amount = rand(10))
ensure_valid_amount(amount)
if amount == ALL
make_plural(fetch('measurement.length'))
elsif amount == NONE
fetch('measurement.length')
else
"#{amount} #{check_for_plural(fetch('measurement.length'), amount)}"
end

"#{amount} #{check_for_plural(fetch('measurement.metric_length'), amount)}"
end

def metric_length_all
make_plural(fetch('measurement.metric_length'))
end

def metric_length_none
fetch('measurement.metric_length')
end

def metric_volume(amount = rand(10))
ensure_valid_amount(amount)
if amount == ALL
make_plural(fetch('measurement.volume'))
elsif amount == NONE
fetch('measurement.volume')
else
"#{amount} #{check_for_plural(fetch('measurement.volume'), amount)}"
end

"#{amount} #{check_for_plural(fetch('measurement.metric_volume'), amount)}"
end

def metric_volume_all
make_plural(fetch('measurement.metric_volume'))
end

def metric_volume_none
fetch('measurement.metric_volume')
end

def metric_weight(amount = rand(10))
ensure_valid_amount(amount)
if amount == ALL
make_plural(fetch('measurement.weight'))
elsif amount == NONE
fetch('measurement.weight')
else
"#{amount} #{check_for_plural(fetch('measurement.weight'), amount)}"
end

"#{amount} #{check_for_plural(fetch('measurement.metric_weight'), amount)}"
end

def metric_weight_all
make_plural(fetch('measurement.metric_weight'))
end

def metric_weight_none
fetch('measurement.metric_weight')
end

private

def ensure_valid_amount(amount)
raise ArgumentError, 'invalid amount' unless amount == NONE || amount == ALL || amount.is_a?(Integer) || amount.is_a?(Float)
raise ArgumentError, 'invalid amount' unless amount.is_a?(Integer) || amount.is_a?(Float)
end

def check_for_plural(text, number)
Expand Down
2 changes: 0 additions & 2 deletions lib/faker/phone_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def exchange_code
# Since extensions can be of variable length, this method taks a length parameter
def subscriber_number(length = 4)
rand.to_s[2..(1 + length)]
rescue I18n::MissingTranslationData
nil
end

alias extension subscriber_number
Expand Down
6 changes: 5 additions & 1 deletion test/test_faker_demographic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ def test_sex
assert %w[Male Female].include?(@tester.sex)
end

def test_height
def test_height_imperial
assert @tester.height(:imperial).match(/\w+/)
end

def test_height_metric
assert @tester.height.match(/\w+/)
end
end
1 change: 1 addition & 0 deletions test/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_safe_email
end

def test_user_name
assert @tester.user_name(0..3).match(/[a-z]+((_|\.)[a-z]+)?/)
assert @tester.user_name.match(/[a-z]+((_|\.)[a-z]+)?/)
end

Expand Down
74 changes: 68 additions & 6 deletions test/test_faker_measurement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,105 @@ def setup

def height
assert @tester.height.match(/\d\s[a-z]/)
assert @tester.height(1).match(/\d\s[a-z]/)
end

def height_all
assert @tester.height_all.match(/\d\s[a-z]/)
end

def height_none
assert @tester.height_none.match(/\d\s[a-z]/)
end

def length
assert @tester.length(0).match(/\d\s[a-z]/)
assert @tester.length.match(/\d\s[a-z]/)
end

def length_all
assert @tester.length_all.match(/\d\s[a-z]/)
end

def length_none
assert @tester.length_none.match(/\d\s[a-z]/)
end

def volume
singular_unit = @tester.volume('none')
plural_unit = @tester.volume('all')
custom_amount_float = @tester.volume(1.5)
custom_amount_integer = @tester.volume(276)

assert singular_unit.match(/\A\D+[^s]\z/)
assert plural_unit.match(/\A\D+[s]\z/)
assert @tester.volume.match(/\d\s[a-z]/)
assert custom_amount_float.match(/\d\s[a-z]+[s]\z/)
assert custom_amount_integer.match(/\d\s[a-z]+[s]\z/)
assert @tester.volume.match(/\d\s[a-z]/)
end

def volume_all
assert @tester.volume_all.match(/\A\D+[^s]\z/)
end

def volume_none
assert @tester.volume_none.match(/\A\D+[^s]\z/)
end

def weight
assert @tester.weight.match(/\d\s[a-z]/)
end

def weight_none
assert @tester.weight_none.match(/\d\s[a-z]/)
end

def weight_all
assert @tester.weight_all.match(/\d\s[a-z]/)
end

def metric_height
assert @tester.metric_height.match(/\d\s[a-z]/)
end

def metric_height_all
assert @tester.metric_height_all.match(/\d\s[a-z]/)
end

def metric_height_none
assert @tester.metric_height_none.match(/\d\s[a-z]/)
end

def metric_length
assert @tester.metric_length.match(/\d\s[a-z]/)
end

def metric_length_all
assert @tester.metric_length_all.match(/\d\s[a-z]/)
end

def metric_length_none
assert @tester.metric_length_none.match(/\d\s[a-z]/)
end

def metric_volume
assert @tester.metric_volume.match(/\d\s[a-z]/)
end

def metric_volume_all
assert @tester.metric_volume_all.match(/\d\s[a-z]/)
end

def metric_volume_none
assert @tester.metric_volume_none.match(/\d\s[a-z]/)
end

def metric_weight
assert @tester.metric_weight.match(/\d\s[a-z]/)
assert @tester.metric_weight(1).match(/\d\s[a-z]/)
end

def metric_weight_all
assert @tester.metric_weight_all.match(/\d\s[a-z]/)
end

def metric_weight_none
assert @tester.metric_weight_none.match(/\d\s[a-z]/)
end

def test_invalid_amount_error
Expand Down
Loading