Sha256: 0a95c95fb607b6aeb1db0d3b871dc9e67db76d7b7ddf5c32c2a9f90e433ecd4c
Contents?: true
Size: 1.89 KB
Versions: 2
Compression:
Stored size: 1.89 KB
Contents
# frozen_string_literal: true require File.expand_path("spec_helper", __dir__) module Danger describe Danger::DangerGitlabCancelbot do it "should be a plugin" do expect(Danger::DangerGitlabCancelbot.new(nil)).to be_a Danger::Plugin end # # You should test your custom attributes and methods here # describe "with Dangerfile" do before do testing_env.each { |k, v| ENV[k] = v.to_s } @dangerfile = testing_dangerfile @plugin = @dangerfile.gitlab_cancelbot @client_mock = double(Gitlab::Client) allow(@dangerfile.gitlab).to receive(:api).and_return(@client_mock) end it "Cancel all running except the most recent one" do pipelines = [Gitlab::Pipeline.new(1, "running", DateTime.parse("2020-05-12T15:45:30.720Z")), Gitlab::Pipeline.new(2, "running", DateTime.now), Gitlab::Pipeline.new(3, "running", DateTime.parse("2020-05-11T15:45:30.720Z"))] expect(@client_mock).to receive(:running_pipelines_for_mr).with(346, 549).and_return(pipelines) expect(@client_mock).to receive(:cancel_pipeline).with(346, 1) expect(@client_mock).to receive(:cancel_pipeline).with(346, 3) @plugin.cancel_redundant_pipelines! end it "Doesn't cancel anything if there's nothing to cancel" do pipelines = [Gitlab::Pipeline.new(2, "running", DateTime.now)] expect(@client_mock).to receive(:running_pipelines_for_mr).with(346, 549).and_return(pipelines) expect(@client_mock).not_to receive(:cancel_pipeline) @plugin.cancel_redundant_pipelines! end ["CI_PROJECT_ID", "CI_MERGE_REQUEST_IID"].each do |var| it "Fails when required #{var} variables are not available" do ENV[var] = nil expect { @plugin.cancel_redundant_pipelines! }.to raise_error(RuntimeError) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
danger-gitlab_cancelbot-1.0.1 | spec/gitlab_cancelbot_spec.rb |
danger-gitlab_cancelbot-1.0.0 | spec/gitlab_cancelbot_spec.rb |