-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Faker::Coffee | ||
|
||
```ruby | ||
Faker::Coffee.blend_name #=> "Summer Solstice" | ||
|
||
Faker::Coffee.origin #=> "Antigua, Guatemala" | ||
|
||
Faker::Coffee.variety #=> "Pacas" | ||
|
||
Faker::Coffee.notes #=> "balanced, silky, marzipan, orange-creamsicle, bergamot" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Faker | ||
class Coffee < Base | ||
class << self | ||
def blend_name | ||
parse('coffee.blend_name') | ||
end | ||
|
||
def origin | ||
country = fetch('coffee.country') | ||
region = fetch("coffee.regions.#{search_format(country)}") | ||
"#{region}, #{country}" | ||
end | ||
|
||
def variety | ||
fetch('coffee.variety') | ||
end | ||
|
||
def notes | ||
parse('coffee.notes') | ||
end | ||
|
||
private | ||
|
||
def search_format(key) | ||
key.split.length > 1 ? key.split.join('_').downcase : key.downcase | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb') | ||
|
||
class TestFakerCoffee < Test::Unit::TestCase | ||
def setup | ||
@tester = Faker::Coffee | ||
@countries = Faker::Base.fetch_all('coffee.country') | ||
@intensifiers = Faker::Base.fetch_all('coffee.intensifier') | ||
@body_descriptors = Faker::Base.fetch_all('coffee.body') | ||
@flavor_descriptors = Faker::Base.fetch_all('coffee.descriptor') | ||
@varieties = Faker::Base.fetch_all('coffee.variety') | ||
blend_name_words_one = Faker::Base.fetch_all('coffee.name_1') | ||
blend_name_words_two = Faker::Base.fetch_all('coffee.name_2') | ||
@name_words = blend_name_words_one.concat(blend_name_words_two) | ||
end | ||
|
||
def test_origin | ||
assert origin = @tester.origin.match(/\A(?<region>([[:alnum:]]+'?-?.?,?\s?){1,5}), (?<country>([[:alnum:]]+\s?){1,5})\z/) | ||
|
||
region, country = origin[:region], origin[:country] | ||
search_format_country = country.split.length > 1 ? country.downcase.split.join('_') : country.downcase | ||
regions = Faker::Base.fetch_all("coffee.regions.#{search_format_country}") | ||
|
||
assert @countries.include?(country) | ||
assert regions.include?(region) | ||
end | ||
|
||
def test_notes | ||
assert notes = @tester.notes | ||
.match(/\A(?<intensifier>[\s\w-]+), (?<body>[\s\w-]+), (?<f1>[!\s\w-]+), (?<f2>[!\s\w-]+), (?<f3>[!\s\w-]+)\z/) | ||
|
||
assert @intensifiers.include?(notes[:intensifier]) | ||
assert @body_descriptors.include?(notes[:body]) | ||
|
||
[notes[:f1], notes[:f2], notes[:f3]].each do |flavor| | ||
assert @flavor_descriptors.include?(flavor) | ||
end | ||
end | ||
|
||
def test_variety | ||
assert @tester.variety.match(/\w+\.?/) | ||
|
||
assert @varieties.include?(@tester.variety) | ||
end | ||
|
||
def test_blend_name | ||
assert blend = @tester.blend_name.match(/(([[:alnum:]]+(-?\w*)*('?\w+)?) ?){1,}/) | ||
|
||
blend[0].split.each do |word| | ||
assert @name_words.include?(word) | ||
end | ||
end | ||
end |