Skip to content

Instantly share code, notes, and snippets.

@ziaulrehman40
Created August 3, 2019 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziaulrehman40/5318e8df4f9d99f894079e182ed046a1 to your computer and use it in GitHub Desktop.
Save ziaulrehman40/5318e8df4f9d99f894079e182ed046a1 to your computer and use it in GitHub Desktop.
Specs for date range splitter
require "rails_helper"
RSpec.describe DateRangeSplitter, type: :service do
describe "#generate_split_dates" do
it "#splits dates properly exclusive in ranges" do
from = DateTime.now
to = from + 53.days
splitter = DateRangeSplitter.new(from, to, 10, end_inclusive: false)
splitter.each do |from_d, to_d|
check_against = to_d == to ? 3 : 10
expect((to_d - from_d).to_i).to eql(check_against)
end
end
it "#splits dates properly inclusive in ranges" do
from = DateTime.now
to = from + 53.days
splitter = DateRangeSplitter.new(from, to, 10, end_inclusive: true)
splitter.each do |from_d, to_d|
check_against = to_d == to ? 3 : 9
expect((to_d - from_d).to_i).to eql(check_against)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment