Skip to content

Commit

Permalink
Merge pull request #26 from ppeble/issue-7
Browse files Browse the repository at this point in the history
issue-7: modify all tests to be in pure YAML rather than raw ruby
  • Loading branch information
ppeble authored Jul 25, 2017
2 parents 3664e81 + 6abf933 commit aac7cae
Show file tree
Hide file tree
Showing 70 changed files with 8,309 additions and 2,120 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.ruby-version
coverage/
Gemfile.lock
tmp/
59 changes: 43 additions & 16 deletions SYNTAX.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,26 +328,53 @@ If a user does not specify `observed` when calling the gem then 1/1 will be the
## Tests
All definition files should have tests included. In the YAML file, tests are just a block of Ruby code:
All definition files should have tests included. At this time we do not enforce any rules on coverage or numbers of tests.
However, in general, PRs will not be accepted if they are devoid of tests that cover the changes in question.
The format is a straightforward 'given then expect'. Here is a simple example:
```yaml
- given:
date: '2018-1-1'
regions: ["ex"]
expect:
name: "Example Holiday"
```
tests: |
{Date.civil(2008,1,1) => 'New Year\'s Day',
Date.civil(2008,3,21) => 'Good Friday',
Date.civil(2008,3,24) => 'Easter Monday',
Date.civil(2008,9,1) => 'Labour Day',
Date.civil(2008,12,25) => 'Christmas Day',
Date.civil(2008,12,26) => 'Boxing Day'}.each do |date, name|
assert_equal name, (Holidays.on(date, :ca, :informal)[0] || {})[:name]
end

# Victoria Day
[Date.civil(2004,5,24), Date.civil(2005,5,23), Date.civil(2006,5,22),
Date.civil(2007,5,21), Date.civil(2008,5,19)].each do |date|
assert_equal 'Victoria Day', Holidays.on(date, :ca)[0][:name]
end
Here are format details:

* given (required)
* date (required) - all dates must be in 'YYYY-MM-DD' format. Either a single day or an array of dates can be used.
* regions (required) - an array of strings (NOT symbols). Multiple regions can be passed. Even a single region must be in an array.
* options (optional) - an array of options to use for this test. Can be either 'informal' or 'observed'. Must be an array of strings, e.g. `['informal', 'observed']`
* expect (required)
* name (optional) - the name of the holiday you are expecting. Must be a string.
* holiday (optional) - a boolean indicating whether the given values result in a holiday. Defaults to 'true' if not present. Must be true or false.

One or the other of the `expect` keys is required. If you do not specify a `name` then you should set `holiday: false`.

Here are some more examples. First example shows multiple dates, multiple regions, additional options, and an expectation that the result will be the named holiday.

```yaml
- given:
date: ['2018-1-1', '2019-3-5']
regions: ["ex", "ex2", "ex3"]
options: ["informal"]
expect:
name: "Example Holiday"
```
Second example shows multiple dates, a single region, multiple options, and an expectation that the given values will *not* result in a found holiday. No name is required because...no holiday is expected to be found.
```yaml
- given:
date: ['2022-12-1', '2019-4-1', '2046-8-8]
regions: ["ex"]
options: ["informal", "observed"]
expect:
holiday: false
```
These tests will be picked up by the `generate` process and written into actual Test::Unit tests that are run when a user executes the test suite.
These tests will be picked up by the `generate` process in the client repositories and written into actual tests in the given language that are run when a user executes the test suite.

Please please please include tests. Your PR won't be accepted if tests are not included with your changes.
123 changes: 103 additions & 20 deletions ar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,106 @@ months:
- name: Navidad
regions: [ar]
mday: 25
tests: |
{Date.civil(2016,1,1) => 'Año Nuevo',
Date.civil(2016,2,8) => 'Carnaval',
Date.civil(2016,2,9) => 'Carnaval',
Date.civil(2016,3,24) => 'Día Nacional de la Memoria por la Verdad y la Justicia',
Date.civil(2016,3,25) => 'Viernes Santo',
Date.civil(2016,4,2) => 'Día del Veterano y de los Caídos en la Guerra de Malvinas',
Date.civil(2016,5,1) => 'Día del Trabajador',
Date.civil(2016,5,25) => 'Día de la Revolución de Mayo',
Date.civil(2016,6,20) => 'Día de la Bandera',
Date.civil(2016,7,8) => 'Feriado puente turístico',
Date.civil(2016,7,9) => 'Día de la Independencia',
Date.civil(2016,8,15) => 'Paso a la Inmortalidad del General José de San Martín',
Date.civil(2016,10,12) => 'Día del Respeto a la Diversidad Cultural',
Date.civil(2016,11,20) => 'Día de la Soberanía Nacional',
Date.civil(2016,12,8) => 'Inmaculada Concepción de María',
Date.civil(2016,12,9) => 'Feriado puente turístico',
Date.civil(2016,12,25) => 'Navidad'}.each do |date, name|
assert_equal name, (Holidays.on(date, :ar, :informal)[0] || {})[:name]
end
tests:
- given:
date: '2016-01-01'
regions: ['ar']
options: 'informal'
expect:
name: 'Año Nuevo'
- given:
date: '2016-02-08'
regions: ['ar']
options: 'informal'
expect:
name: 'Carnaval'
- given:
date: '2016-02-09'
regions: ['ar']
options: 'informal'
expect:
name: 'Carnaval'
- given:
date: '2016-03-24'
regions: ['ar']
options: 'informal'
expect:
name: 'Día Nacional de la Memoria por la Verdad y la Justicia'
- given:
date: '2016-03-25'
regions: ['ar']
options: 'informal'
expect:
name: 'Viernes Santo'
- given:
date: '2016-04-02'
regions: ['ar']
options: 'informal'
expect:
name: 'Día del Veterano y de los Caídos en la Guerra de Malvinas'
- given:
date: '2016-05-01'
regions: ['ar']
options: 'informal'
expect:
name: 'Día del Trabajador'
- given:
date: '2016-05-25'
regions: ['ar']
options: 'informal'
expect:
name: 'Día de la Revolución de Mayo'
- given:
date: '2016-06-20'
regions: ['ar']
options: 'informal'
expect:
name: 'Día de la Bandera'
- given:
date: '2016-07-08'
regions: ['ar']
options: 'informal'
expect:
name: 'Feriado puente turístico'
- given:
date: '2016-07-09'
regions: ['ar']
options: 'informal'
expect:
name: 'Día de la Independencia'
- given:
date: '2016-08-15'
regions: ['ar']
options: 'informal'
expect:
name: 'Paso a la Inmortalidad del General José de San Martín'
- given:
date: '2016-10-12'
regions: ['ar']
options: 'informal'
expect:
name: 'Día del Respeto a la Diversidad Cultural'
- given:
date: '2016-11-20'
regions: ['ar']
options: 'informal'
expect:
name: 'Día de la Soberanía Nacional'
- given:
date: '2016-12-08'
regions: ['ar']
options: 'informal'
expect:
name: 'Inmaculada Concepción de María'
- given:
date: '2016-12-09'
regions: ['ar']
options: 'informal'
expect:
name: 'Feriado puente turístico'
- given:
date: '2016-12-25'
regions: ['ar']
options: 'informal'
expect:
name: 'Navidad'
61 changes: 48 additions & 13 deletions at.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,51 @@ months:
- name: 2. Weihnachtstag
regions: [at]
mday: 26
tests: |
{Date.civil(2009,1,1) => 'Neujahrstag',
Date.civil(2009,4,13) => 'Ostermontag',
Date.civil(2009,5,1) => 'Staatsfeiertag',
Date.civil(2009,5,21) => 'Christi Himmelfahrt',
Date.civil(2009,6,1) => 'Pfingstmontag',
Date.civil(2009,10,26) => 'Nationalfeiertag',
Date.civil(2009,12,25) => '1. Weihnachtstag',
Date.civil(2009,12,26) => '2. Weihnachtstag'}.each do |date, name|
assert_equal name, (Holidays.on(date, :at, :informal)[0] || {})[:name]
end
assert_equal [], Holidays.on(Date.civil(2010,5,8), :at), '2010-05-08 is not a holiday in Austria'
tests:
- given:
date: '2009-01-01'
regions: ['at']
options: 'informal'
expect:
name: 'Neujahrstag'
- given:
date: '2009-04-13'
regions: ['at']
options: 'informal'
expect:
name: 'Ostermontag'
- given:
date: '2009-05-21'
regions: ['at']
options: 'informal'
expect:
name: 'Christi Himmelfahrt'
- given:
date: '2009-06-01'
regions: ['at']
options: 'informal'
expect:
name: 'Pfingstmontag'
- given:
date: '2009-10-26'
regions: ['at']
options: 'informal'
expect:
name: 'Nationalfeiertag'
- given:
date: '2009-12-25'
regions: ['at']
options: 'informal'
expect:
name: '1. Weihnachtstag'
- given:
date: '2009-12-26'
regions: ['at']
options: 'informal'
expect:
name: '2. Weihnachtstag'
- given:
date: '2010-05-08'
regions: ['at']
expect:
holiday: false
Loading

0 comments on commit aac7cae

Please sign in to comment.