Skip to content

Instantly share code, notes, and snippets.

@ppeble
Created April 2, 2016 21:04
Show Gist options
  • Save ppeble/463485b5e6b8ac7ee112079c0c137147 to your computer and use it in GitHub Desktop.
Save ppeble/463485b5e6b8ac7ee112079c0c137147 to your computer and use it in GitHub Desktop.
Testing for issue 144
# Here is a custom 'on the fly' definition file:
months:
0:
- name: Good Friday
regions: [custom_single_file]
function: easter(year)
function_modifier: -2
- name: Custom Holiday
regions: [custom_single_file]
function: custom_method(year)
function_modifier: 5
6:
- name: Company Founding
regions: [custom_single_file]
mday: 20
methods:
custom_method:
arguments: year
source: |
d = Date.civil(year, 12, 1)
d + 1
tests: |
{Date.civil(2013,6,20) => 'Company Founding'}.each do |date, name|
assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {})[:name]
end
{Date.civil(2015, 1, 1) => 'Custom Holiday'}.each do |date, name|
assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {}[:name]
end
# Here are the tests I ran:
Holidays.load_custom('/home/vagrant/dev/holidays/test_custom.yaml')
Holidays.on(Date.civil(2016, 3, 25), :custom_single_file) # Good Friday (i.e. global function)
Holidays.on(Date.civil(2016, 12, 2), :custom_single_file) # Special custom holiday
Holidays.on(Date.civil(2016, 6, 20), :custom_single_file) # Normal holiday in custom on the fly loaded def
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment