Sha256: 5501f0b8ad1e22a78080336abd0c97fa83eaa6dccb387ee5df42f1f9fcb52555

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

require "spec_helper"
require "daily_weekly_monthly/runner"

describe DailyWeeklyMonthly::Runner do
  let(:command) { double :command }
  let(:downloader) { double :downloader }
  let(:backup) { double :backup }
  let(:backups_dir) { double :backups_dir }
  let(:ext) { double :ext }
  let(:processor) { double :processor, call: true }
  let(:options) {
    {
      backups_dir: backups_dir,
      output_extension: ext,
    }
  }

  subject { described_class.new command, options }

  before do
    allow(DailyWeeklyMonthly::Downloader).to receive(:new).with(command) { downloader }
    allow(downloader).to receive(:call) { backup }
    allow(DailyWeeklyMonthly::Processor).to receive(:new).with(backup, backups_dir, ext) { processor }
  end

  context "when the day of the month is backup day" do
    subject { described_class.new command, options.merge(day_of_month: Date.today.day) }

    it "runs the monthly backup" do
      expect(processor).to receive(:call).with("monthly", keep: 12)
      subject.call
    end
  end

  context "when the weekday is the backup day" do
    subject { described_class.new command, options.merge(day_of_week: Date.today.wday) }

    it "runs the weekly backup" do
      expect(processor).to receive(:call).with("weekly", keep: 5)
      subject.call
    end
  end

  it "runs the daily backup" do
    expect(processor).to receive(:call).with("daily", keep: 7)
    subject.call
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
daily_weekly_monthly-0.0.4 spec/daily_weekly_monthly/runner_spec.rb
daily_weekly_monthly-0.0.3 spec/daily_weekly_monthly/runner_spec.rb
daily_weekly_monthly-0.0.2 spec/daily_weekly_monthly/runner_spec.rb