require 'spec_helper'

describe Upcoming::LastDayOfMonthGenerator do
  Given(:subject) { Upcoming::LastDayOfMonthGenerator.new }
  When(:valid) { subject.valid?(date) }

  context 'start of the month is invalid' do
    Given(:date) { Date.parse('2014-06-01') }
    Then { !valid }
  end

  context 'middle of the month is invalid' do
    Given(:date) { Date.parse('2014-06-15') }
    Then { !valid }
  end

  context 'last day of the month is valid' do
    Given(:date) { Date.parse('2014-05-31') }
    Then { valid }
  end

  context 'last day of February in a leap year is valid' do
    Given(:date) { Date.parse('2012-02-29') }
    Then { valid }
  end
end

require 'spec_helper'

describe Upcoming::LastDayOfMonthGenerator do
  Given(:subject) { Upcoming::LastDayOfMonthGenerator.new }
  When(:valid) { subject.valid?(Date.parse(date)) }

  context 'start of the month is invalid' do
    Given(:date) { '2014-06-01' }
    Then { !valid }
  end

  context 'middle of the month is invalid' do
    Given(:date) { '2014-06-15' }
    Then { !valid }
  end

  context 'last day of the month is valid' do
    Given(:date) { '2014-05-31' }
    Then { valid }
  end

  context 'last day of February in a leap year is valid' do
    Given(:date) { '2012-02-29' }
    Then { valid }
  end
end

Reduce repetition in last day of the month generator
Reduce repetition in last day of the month generator

`Date.parse` was used every time a date needed to be set. This has now
moved up to the top level.
