Skip to content

Commit 8028d5b

Browse files
committed
generate tests for bump
1 parent 980a12c commit 8028d5b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

spec/lib/utils/bump_spec.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
require 'spec_helper'
2+
require 'utils/bump'
3+
4+
RSpec.describe Bump do
5+
let(:config) { double('config') }
6+
let(:level) { 'patch' }
7+
let(:payload) { { 'repository' => { 'full_name' => 'owner/repo' }, 'issue' => { 'number' => 123 } } }
8+
let(:client) { double('client') }
9+
let(:version_file_path) { 'path/to/version/file' }
10+
let(:other_version_file_paths) { ['path/to/other/version/file'] }
11+
let(:content) { double('content') }
12+
let(:commit) { double('commit') }
13+
14+
before do
15+
allow(config).to receive(:payload).and_return(payload)
16+
allow(config).to receive(:client).and_return(client)
17+
allow(config).to receive(:version_file_path).and_return(version_file_path)
18+
allow(config).to receive(:other_version_file_paths).and_return(other_version_file_paths)
19+
allow(Content).to receive(:new).with(config: config, ref: 'base_branch', path: version_file_path).and_return(content)
20+
allow(Content).to receive(:new).with(config: config, ref: 'head_branch', path: version_file_path).and_return(content)
21+
allow(content).to receive(:content).and_return('version: 1.0.0')
22+
allow(content).to receive(:content=)
23+
allow(client).to receive(:pull_request).with('owner/repo', 123).and_return({ 'head' => { 'ref' => 'head_branch' }, 'base' => { 'ref' => 'base_branch' } })
24+
allow(Semantic::Version).to receive(:new).and_return(double('version'))
25+
allow(double('version')).to receive(:increment!)
26+
allow(Commit).to receive(:new).with(config).and_return(commit)
27+
allow(commit).to receive(:multiple_files)
28+
end
29+
30+
describe '#bump_everything' do
31+
it 'bumps the version and commits the changes' do
32+
bump = Bump.new(config, level)
33+
expect(Content).to receive(:new).with(config: config, ref: 'base_branch', path: version_file_path).and_return(content).ordered
34+
expect(Content).to receive(:new).with(config: config, ref: 'head_branch', path: version_file_path).and_return(content).ordered
35+
expect(content).to receive(:content).and_return('version: 1.0.0').ordered
36+
expect(content).to receive(:content=).with('version: 1.0.1').ordered
37+
expect(commit).to receive(:multiple_files).with([{ path: version_file_path, mode: '100644', type: 'blob', content: 'version: 1.0.1' }], 'Bump patch version')
38+
bump.bump_everything
39+
end
40+
41+
it 'skips updating if the desired version bump is already present' do
42+
bump = Bump.new(config, level)
43+
expect(Content).to receive(:new).with(config: config, ref: 'base_branch', path: version_file_path).and_return(content).ordered
44+
expect(Content).to receive(:new).with(config: config, ref: 'head_branch', path: version_file_path).and_return(content).ordered
45+
expect(content).to receive(:content).and_return('version: 1.0.1').ordered
46+
expect(commit).not_to receive(:multiple_files)
47+
expect { bump.bump_everything }.to output("::notice title=Nothing to update::The desired version bump is already present for: path/to/version/file\n").to_stdout
48+
end
49+
end
50+
end

0 commit comments

Comments
 (0)