|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe CreateGithubRelease::Assertions::ReleasePrLabelExists do |
| 4 | + let(:assertion) { described_class.new(project) } |
| 5 | + let(:options) { CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' } } |
| 6 | + let(:project) { CreateGithubRelease::Project.new(options) { |p| p.release_pr_label = release_pr_label } } |
| 7 | + let(:release_pr_label) { nil } |
| 8 | + |
| 9 | + before do |
| 10 | + allow(assertion).to receive(:`).with(String) { |command| execute_mocked_command(mocked_commands, command) } |
| 11 | + end |
| 12 | + |
| 13 | + describe '#assert' do |
| 14 | + subject do |
| 15 | + @stdout, @stderr, exception = capture_output { assertion.assert } |
| 16 | + raise exception if exception |
| 17 | + end |
| 18 | + let(:stdout) { @stdout } |
| 19 | + let(:stderr) { @stderr } |
| 20 | + |
| 21 | + context 'when release pr label is nil' do |
| 22 | + let(:mocked_commands) { [] } |
| 23 | + it 'should not raise an error' do |
| 24 | + expect { assertion.assert }.not_to raise_error |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + context 'when release pr label is "release"' do |
| 29 | + let(:release_pr_label) { 'release' } |
| 30 | + |
| 31 | + context 'when the label exists' do |
| 32 | + let(:mocked_commands) do |
| 33 | + [ |
| 34 | + MockedCommand.new('gh label list', stdout: <<~LABELS) |
| 35 | + bug\tSomething isn't working\t#d73a4a |
| 36 | + release\tThe PR represents a release\t#0075ca |
| 37 | + duplicate\tThis issue or pull request already exists\t#cfd3d7 |
| 38 | + LABELS |
| 39 | + ] |
| 40 | + end |
| 41 | + |
| 42 | + it 'should not raise an error' do |
| 43 | + expect { assertion.assert }.not_to raise_error |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context 'when the label does not exist' do |
| 48 | + let(:mocked_commands) do |
| 49 | + [ |
| 50 | + MockedCommand.new('gh label list', stdout: <<~LABELS) |
| 51 | + bug\tSomething isn't working\t#d73a4a |
| 52 | + duplicate\tThis issue or pull request already exists\t#cfd3d7 |
| 53 | + LABELS |
| 54 | + ] |
| 55 | + end |
| 56 | + |
| 57 | + it 'should fail' do |
| 58 | + expect { subject }.to raise_error(SystemExit) |
| 59 | + expect(stderr).to start_with("ERROR: Release pr label 'release' does not exist\n") |
| 60 | + end |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + context 'when the gh command fails' do |
| 65 | + let(:release_pr_label) { 'release' } |
| 66 | + |
| 67 | + let(:mocked_commands) do |
| 68 | + [ |
| 69 | + MockedCommand.new('gh label list', exitstatus: 1) |
| 70 | + ] |
| 71 | + end |
| 72 | + |
| 73 | + it 'should fail' do |
| 74 | + expect { subject }.to raise_error(SystemExit) |
| 75 | + expect(stderr).to start_with('ERROR: Could not list pr labels') |
| 76 | + end |
| 77 | + end |
| 78 | + end |
| 79 | +end |
| 80 | + |
| 81 | +# context 'when this is the first release' do |
| 82 | +# let(:release_type) { 'first' } |
| 83 | +# let(:mocked_commands) { [] } |
| 84 | +# it 'should not raise an error' do |
| 85 | +# expect { assertion.assert }.not_to raise_error |
| 86 | +# end |
| 87 | +# end |
| 88 | + |
| 89 | +# context 'when this is NOT the first release' do |
| 90 | +# context 'when the last release tag does not exist' do |
| 91 | +# let(:mocked_commands) do |
| 92 | +# [ |
| 93 | +# MockedCommand.new('git tag --list "v0.0.0"', stdout: "\n") |
| 94 | +# ] |
| 95 | +# end |
| 96 | + |
| 97 | +# it 'should fail' do |
| 98 | +# expect { subject }.to raise_error(SystemExit) |
| 99 | +# expect(stderr).to start_with("ERROR: Last release tag 'v0.0.0' does not exist") |
| 100 | +# end |
| 101 | +# end |
| 102 | + |
| 103 | +# context 'when the last release tag exists' do |
| 104 | +# let(:mocked_commands) do |
| 105 | +# [ |
| 106 | +# MockedCommand.new('git tag --list "v0.0.0"', stdout: "v0.0.0\n") |
| 107 | +# ] |
| 108 | +# end |
| 109 | + |
| 110 | +# it 'should succeed' do |
| 111 | +# expect { subject }.not_to raise_error |
| 112 | +# end |
| 113 | +# end |
| 114 | + |
| 115 | +# context 'when the git command fails' do |
| 116 | +# let(:mocked_commands) do |
| 117 | +# [ |
| 118 | +# MockedCommand.new('git tag --list "v0.0.0"', exitstatus: 1) |
| 119 | +# ] |
| 120 | +# end |
| 121 | + |
| 122 | +# it 'should fail' do |
| 123 | +# expect { subject }.to raise_error(SystemExit) |
| 124 | +# expect(stderr).to start_with('ERROR: Could not list tags') |
| 125 | +# end |
| 126 | +# end |
| 127 | +# end |
| 128 | +# end |
| 129 | +# end |
0 commit comments