Commit a6c9db61 authored by Dylan Griffith's avatar Dylan Griffith

More style improvements to spec/models/ci/runner_spec.rb

parent 1f7f29b7
...@@ -309,7 +309,9 @@ describe Ci::Runner do ...@@ -309,7 +309,9 @@ describe Ci::Runner do
describe '#can_pick?' do describe '#can_pick?' do
let(:pipeline) { create(:ci_pipeline) } let(:pipeline) { create(:ci_pipeline) }
let(:build) { create(:ci_build, pipeline: pipeline) } let(:build) { create(:ci_build, pipeline: pipeline) }
let(:runner) { create(:ci_runner) } let(:runner) { create(:ci_runner, tag_list: tag_list, run_untagged: run_untagged) }
let(:tag_list) { [] }
let(:run_untagged) { true }
subject { runner.can_pick?(build) } subject { runner.can_pick?(build) }
...@@ -319,7 +321,7 @@ describe Ci::Runner do ...@@ -319,7 +321,7 @@ describe Ci::Runner do
context 'a different runner' do context 'a different runner' do
it 'cannot handle builds' do it 'cannot handle builds' do
other_runner = create :ci_runner other_runner = create(:ci_runner)
expect(other_runner.can_pick?(build)).to be_falsey expect(other_runner.can_pick?(build)).to be_falsey
end end
end end
...@@ -337,9 +339,7 @@ describe Ci::Runner do ...@@ -337,9 +339,7 @@ describe Ci::Runner do
end end
context 'when runner has tags' do context 'when runner has tags' do
before do let(:tag_list) { %w(bb cc) }
runner.tag_list = %w(bb cc)
end
shared_examples 'tagged build picker' do shared_examples 'tagged build picker' do
it 'can handle build with matching tags' do it 'can handle build with matching tags' do
...@@ -364,9 +364,7 @@ describe Ci::Runner do ...@@ -364,9 +364,7 @@ describe Ci::Runner do
end end
context 'when runner cannot pick untagged jobs' do context 'when runner cannot pick untagged jobs' do
before do let(:run_untagged) { false }
runner.update_attributes!(run_untagged: false)
end
it 'cannot handle builds without tags' do it 'cannot handle builds without tags' do
expect(runner.can_pick?(build)).to be_falsey expect(runner.can_pick?(build)).to be_falsey
...@@ -377,8 +375,9 @@ describe Ci::Runner do ...@@ -377,8 +375,9 @@ describe Ci::Runner do
end end
context 'when runner is shared' do context 'when runner is shared' do
let(:runner) { create(:ci_runner, :shared) }
before do before do
runner.update_attributes!(is_shared: true)
build.project.runners = [] build.project.runners = []
end end
...@@ -387,9 +386,7 @@ describe Ci::Runner do ...@@ -387,9 +386,7 @@ describe Ci::Runner do
end end
context 'when runner is locked' do context 'when runner is locked' do
before do let(:runner) { create(:ci_runner, :shared, locked: true) }
runner.update_attributes!(locked: true)
end
it 'can handle builds' do it 'can handle builds' do
expect(runner.can_pick?(build)).to be_truthy expect(runner.can_pick?(build)).to be_truthy
...@@ -748,55 +745,57 @@ describe Ci::Runner do ...@@ -748,55 +745,57 @@ describe Ci::Runner do
end end
end end
describe 'assigned_to_group?' do describe '#assigned_to_group?' do
it 'returns false when the runner is a project runner' do subject { runner.assigned_to_group? }
project = create :project
runner = create :ci_runner, description: 'Project runner', projects: [project] context 'when project runner' do
let(:runner) { create(:ci_runner, description: 'Project runner', projects: [project]) }
let(:project) { create(:project) }
expect(runner.assigned_to_group?).to be false it { is_expected.to be_falsey }
end end
it 'returns false when the runner is a shared runner' do context 'when shared runner' do
runner = create :ci_runner, :shared, description: 'Shared runner' let(:runner) { create(:ci_runner, :shared, description: 'Shared runner') }
expect(runner.assigned_to_group?).to be false it { is_expected.to be_falsey }
end end
it 'returns true when the runner is assigned to a group' do context 'when group runner' do
group = create :group let(:group) { create(:group) }
runner = create :ci_runner, description: 'Group runner', groups: [group] let(:runner) { create(:ci_runner, description: 'Group runner', groups: [group]) }
expect(runner.assigned_to_group?).to be true it { is_expected.to be_truthy }
end end
end end
describe 'assigned_to_project?' do describe '#assigned_to_project?' do
it 'returns false when the runner is a group prunner' do subject { runner.assigned_to_project? }
group = create :group
runner = create :ci_runner, description: 'Group runner', groups: [group]
expect(runner.assigned_to_project?).to be false context 'when group runner' do
let(:runner) { create(:ci_runner, description: 'Group runner', groups: [group]) }
let(:group) { create(:group) }
it { is_expected.to be_falsey }
end end
it 'returns false when the runner is a shared runner' do context 'when shared runner' do
runner = create :ci_runner, :shared, description: 'Shared runner' let(:runner) { create(:ci_runner, :shared, description: 'Shared runner') }
it { is_expected.to be_falsey }
expect(runner.assigned_to_project?).to be false
end end
it 'returns true when the runner is assigned to a project' do context 'when project runner' do
project = create :project let(:runner) { create(:ci_runner, description: 'Group runner', projects: [project]) }
runner = create :ci_runner, description: 'Group runner', projects: [project] let(:project) { create(:project) }
expect(runner.assigned_to_project?).to be true it { is_expected.to be_truthy }
end end
end end
describe '#pick_build!' do describe '#pick_build!' do
context 'runner can pick the build' do context 'runner can pick the build' do
it 'calls #tick_runner_queue' do it 'calls #tick_runner_queue' do
ci_build = build :ci_build ci_build = build(:ci_build)
runner = build :ci_runner runner = build(:ci_runner)
allow(runner).to receive(:can_pick?).with(ci_build).and_return(true) allow(runner).to receive(:can_pick?).with(ci_build).and_return(true)
expect(runner).to receive(:tick_runner_queue) expect(runner).to receive(:tick_runner_queue)
...@@ -807,8 +806,8 @@ describe Ci::Runner do ...@@ -807,8 +806,8 @@ describe Ci::Runner do
context 'runner cannot pick the build' do context 'runner cannot pick the build' do
it 'does not call #tick_runner_queue' do it 'does not call #tick_runner_queue' do
ci_build = build :ci_build ci_build = build(:ci_build)
runner = build :ci_runner runner = build(:ci_runner)
allow(runner).to receive(:can_pick?).with(ci_build).and_return(false) allow(runner).to receive(:can_pick?).with(ci_build).and_return(false)
expect(runner).not_to receive(:tick_runner_queue) expect(runner).not_to receive(:tick_runner_queue)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment