frankfurter/spec/day_spec.rb

34 lines
948 B
Ruby
Raw Normal View History

# frozen_string_literal: true
require_relative 'helper'
require 'day'
describe Day do
describe '.latest' do
it 'returns latest rates before given date' do
date = Date.parse('2010-01-01')
data = Day.latest(date)
2020-05-02 18:08:47 +02:00
_(data.first.date).must_be :<=, date
end
it 'returns nothing if there are no rates before given date' do
2020-05-02 18:08:47 +02:00
_(Day.latest(Date.parse('1998-01-01'))).must_be_empty
end
end
describe '.between' do
it 'returns rates between given dates' do
start_date = Date.parse('2010-01-01')
end_date = Date.parse('2010-01-31')
dates = Day.between((start_date..end_date)).map(:date).sort
2020-05-02 18:08:47 +02:00
_(dates.first).must_be :>=, start_date
_(dates.last).must_be :<=, end_date
end
it 'returns nothing if there are no rates between given dates' do
interval = (Date.parse('1998-01-01')..Date.parse('1998-01-31'))
2020-05-02 18:08:47 +02:00
_(Day.between(interval)).must_be_empty
end
end
end