Skip to content

Commit

Permalink
More measurement spec fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrazo committed May 17, 2018
1 parent 4a8be38 commit c534011
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 13 additions & 16 deletions lib/faker/measurement.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module Faker
class Measurement < Base
class << self
ALL = 'all'.freeze
NONE = 'none'.freeze

def height(amount = rand(10))
ensure_valid_amount(amount)

Expand Down Expand Up @@ -63,63 +60,63 @@ def weight_none
def metric_height(amount = rand(10))
ensure_valid_amount(amount)

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

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

def metric_height_none
fetch('measurement.height')
fetch('measurement.metric_height')
end

def metric_length(amount = rand(10))
ensure_valid_amount(amount)

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

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

def metric_length_none
fetch('measurement.height')
fetch('measurement.metric_length')
end

def metric_volume(amount = rand(10))
ensure_valid_amount(amount)

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

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

def metric_volume_none
fetch('measurement.volume')
fetch('measurement.metric_volume')
end

def metric_weight(amount = rand(10))
ensure_valid_amount(amount)

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

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

def metric_weight_none
fetch('measurement.weight')
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: 2 additions & 0 deletions test/test_faker_measurement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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
Expand Down Expand Up @@ -90,6 +91,7 @@ def metric_volume_none

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
Expand Down

0 comments on commit c534011

Please sign in to comment.