spec/lib/release_tools/update_paths/finish_notification_spec.rb (82 lines of code) (raw):

# frozen_string_literal: true require 'spec_helper' RSpec.describe ReleaseTools::UpdatePaths::FinishNotification do subject(:notifier) { described_class.new(previous_version: previous_version, version: version, status: status) } let(:previous_version) { '16.0.0' } let(:version) { '16.1.0' } let(:status) { :success } let(:notifier_double) { instance_double(ReleaseTools::Slack::ReleaseJobEndNotifier, send_notification: true) } before do allow(ReleaseTools::Slack::ReleaseJobEndNotifier).to receive(:new).and_return(notifier_double) end describe '#execute' do context 'with a monthly release version' do let(:version) { '16.0.0' } it 'sends a notification to Slack with monthly release type' do expect(ReleaseTools::Slack::ReleaseJobEndNotifier).to receive(:new) .with( job_type: "Update paths QA from #{previous_version} to #{version}", status: status, release_type: :monthly ) .and_return(notifier_double) expect(notifier_double).to receive(:send_notification) without_dry_run do notifier.execute end end end context 'with a patch release version' do let(:version) { '16.0.1' } it 'sends a notification to Slack with patch release type' do expect(ReleaseTools::Slack::ReleaseJobEndNotifier).to receive(:new) .with( job_type: "Update paths QA from #{previous_version} to #{version}", status: status, release_type: :patch ) .and_return(notifier_double) expect(notifier_double).to receive(:send_notification) without_dry_run do notifier.execute end end end context 'with a success status' do it 'sends a notification to Slack with success status' do expect(ReleaseTools::Slack::ReleaseJobEndNotifier).to receive(:new) .with( job_type: "Update paths QA from #{previous_version} to #{version}", status: :success, release_type: :monthly ) .and_return(notifier_double) expect(notifier_double).to receive(:send_notification) without_dry_run do notifier.execute end end end context 'with a failed status' do let(:status) { :failed } it 'sends a notification to Slack with failed status' do expect(ReleaseTools::Slack::ReleaseJobEndNotifier).to receive(:new) .with( job_type: "Update paths QA from #{previous_version} to #{version}", status: status, release_type: :monthly ) .and_return(notifier_double) expect(notifier_double).to receive(:send_notification) without_dry_run do notifier.execute end end end context 'when in dry run mode' do it 'does not send a notification' do expect(notifier_double).not_to receive(:send_notification) notifier.execute end end end end