|
148 | 148 | ) |
149 | 149 | end |
150 | 150 | end |
| 151 | + |
| 152 | + describe 'extracting a CHANGELOG part for the release notes' do |
| 153 | + let(:changelog_content) do |
| 154 | + <<~CHANGELOG |
| 155 | + ## [Unreleased] |
| 156 | +
|
| 157 | + - Upcoming feature that is not yet released |
| 158 | + - Another upcoming feature |
| 159 | +
|
| 160 | + ## [0.3.0] - 2026-01-29 |
| 161 | +
|
| 162 | + - New `rake bun:install:package` task: automatically migrates `package.json` scripts |
| 163 | + - New `rake bun:install:procfile` task: automatically migrates `Procfile` files |
| 164 | + - Both tasks are automatically invoked by `rake bun:install` |
| 165 | +
|
| 166 | + ## [0.2.0] - 2025-01-30 |
| 167 | +
|
| 168 | + - Major update with new features |
| 169 | + - Breaking changes included |
| 170 | +
|
| 171 | + ## [0.1.0] - 2024-12-15 |
| 172 | +
|
| 173 | + - Initial release |
| 174 | + CHANGELOG |
| 175 | + end |
| 176 | + |
| 177 | + let(:tmpfile) do |
| 178 | + file = Tempfile.new(['CHANGELOG', '.md']) |
| 179 | + file.write(changelog_content) |
| 180 | + file.close |
| 181 | + file |
| 182 | + end |
| 183 | + |
| 184 | + after { tmpfile.unlink } |
| 185 | + |
| 186 | + before do |
| 187 | + allow(File).to receive(:expand_path) |
| 188 | + .with('../../CHANGELOG.md', anything) |
| 189 | + .and_return(tmpfile.path) |
| 190 | + end |
| 191 | + |
| 192 | + it 'extracts changelog content for a base version' do |
| 193 | + result = publisher.send(:extract_changelog_for_version, '0.3.0') |
| 194 | + |
| 195 | + expect(result).to include('rake bun:install:package') |
| 196 | + expect(result).to include('rake bun:install:procfile') |
| 197 | + expect(result).to include('Both tasks are automatically invoked') |
| 198 | + end |
| 199 | + |
| 200 | + it 'extracts changelog content for a composite version' do |
| 201 | + result = publisher.send(:extract_changelog_for_version, '0.3.0.1.1.38') |
| 202 | + |
| 203 | + expect(result).to include('rake bun:install:package') |
| 204 | + expect(result).not_to include('Unreleased') |
| 205 | + expect(result).not_to include('Major update') |
| 206 | + end |
| 207 | + |
| 208 | + it 'extracts the last version in changelog' do |
| 209 | + result = publisher.send(:extract_changelog_for_version, '0.1.0') |
| 210 | + |
| 211 | + expect(result).to eq('- Initial release') |
| 212 | + end |
| 213 | + |
| 214 | + it 'returns nil for non-existent version' do |
| 215 | + result = publisher.send(:extract_changelog_for_version, '9.9.9') |
| 216 | + |
| 217 | + expect(result).to be_nil |
| 218 | + end |
| 219 | + |
| 220 | + it 'does not include content from other versions' do |
| 221 | + result = publisher.send(:extract_changelog_for_version, '0.2.0') |
| 222 | + |
| 223 | + expect(result).to include('Major update') |
| 224 | + expect(result).not_to include('Initial release') |
| 225 | + expect(result).not_to include('rake bun:install:package') |
| 226 | + end |
| 227 | + |
| 228 | + context 'when changelog file does not exist' do |
| 229 | + before do |
| 230 | + allow(File).to receive(:expand_path) |
| 231 | + .with('../../CHANGELOG.md', anything) |
| 232 | + .and_return('/nonexistent/path/CHANGELOG.md') |
| 233 | + end |
| 234 | + |
| 235 | + it 'returns nil' do |
| 236 | + result = publisher.send(:extract_changelog_for_version, '0.3.0') |
| 237 | + |
| 238 | + expect(result).to be_nil |
| 239 | + end |
| 240 | + end |
| 241 | + |
| 242 | + context 'when changelog has malformed content' do |
| 243 | + let(:changelog_content) { 'This is not a valid changelog format' } |
| 244 | + |
| 245 | + it 'returns nil' do |
| 246 | + result = publisher.send(:extract_changelog_for_version, '0.3.0') |
| 247 | + |
| 248 | + expect(result).to be_nil |
| 249 | + end |
| 250 | + end |
| 251 | + end |
151 | 252 | end |
0 commit comments