|
3 | 3 | require 'spec_helper' |
4 | 4 | require 'ruby-gem-release/workflow/ruby_gem' |
5 | 5 | require 'ruby-gem-release/changelog' |
| 6 | +require 'ruby-gem-release/version/references' |
6 | 7 |
|
7 | 8 | RSpec.describe RubyGemRelease::Workflow::RubyGem do |
8 | 9 | let(:events) { [] } |
@@ -91,6 +92,48 @@ def run_callbacks |
91 | 92 | expect(objects.fetch(:git)).to have_received(:commit_next!).twice |
92 | 93 | end |
93 | 94 |
|
| 95 | + it 'increments the configured next version part from the release version', :aggregate_failures do |
| 96 | + install(next_version: :minor) |
| 97 | + Rake::Task['release:bump'].invoke |
| 98 | + expect(version).to have_received(:increment!).with(from: '2.0.0', part: :minor) |
| 99 | + expect(objects.fetch(:git)).to have_received(:commit_next!).with(having_attributes(next_version: '2.0.1')) |
| 100 | + end |
| 101 | + |
| 102 | + it 'accepts next version parts as strings' do |
| 103 | + install(next_version: 'major') |
| 104 | + Rake::Task['release:bump'].invoke |
| 105 | + expect(version).to have_received(:increment!).with(from: '2.0.0', part: :major) |
| 106 | + end |
| 107 | + |
| 108 | + it 'rejects unknown next version parts at construction', :aggregate_failures do |
| 109 | + [:build, nil, 1, ''].each do |next_version| |
| 110 | + expect { described_class.new(version: version, changelog: nil, next_version: next_version) } |
| 111 | + .to raise_error(ArgumentError, 'next_version must be :major, :minor, or :patch') |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + it 'requires custom version objects to accept part: only for non-patch next versions', :aggregate_failures do |
| 116 | + custom = Class.new do |
| 117 | + def read = '1.2.3' |
| 118 | + def set!(value) = value |
| 119 | + def increment!(from:) = from |
| 120 | + end.new |
| 121 | + expect { described_class.new(version: custom, changelog: nil, next_version: :minor) } |
| 122 | + .to raise_error(ArgumentError, "version object's increment! must accept part: to use next_version: :minor") |
| 123 | + expect { described_class.new(version: custom, changelog: nil) }.not_to raise_error |
| 124 | + end |
| 125 | + |
| 126 | + it 'writes the next minor version through a reference-updating Ruby constant' do |
| 127 | + Dir.mktmpdir do |directory| |
| 128 | + path = File.join(directory, 'version.rb') |
| 129 | + File.write(path, "VERSION = '2.0.0'\n") |
| 130 | + constant = RubyGemRelease::Version::RubyConstant.new(path: path, constant: 'VERSION') |
| 131 | + described_class.new(version: RubyGemRelease::Version::References.new(version: constant, references: {}), changelog: nil, **objects.except(:changelog), next_version: :minor).install_tasks |
| 132 | + Rake::Task['release:bump'].invoke |
| 133 | + expect(File.read(path)).to eq("VERSION = '2.1.0'\n") |
| 134 | + end |
| 135 | + end |
| 136 | + |
94 | 137 | it 'rejects an Actions checkpoint without a configured workflow' do |
95 | 138 | RubyGemRelease::Tasks.install |
96 | 139 | expect { Rake::Task['release:workflow:checkpoint'].invoke }.to raise_error(/must implement checkpoint!/) |
|
0 commit comments