|
82 | 82 | expect(lines[0..10].join).to match_approval('cli/generate/wrap-script') |
83 | 83 | end |
84 | 84 | end |
| 85 | + |
| 86 | + context "with --upgrade" do |
| 87 | + let(:lib_files) { Dir["spec/tmp/src/lib/**/*.sh"].sort } |
| 88 | + let(:outdated_text) { "OUTDATED TEXT" } |
85 | 89 |
|
| 90 | + before do |
| 91 | + reset_tmp_dir copy_from: 'spec/fixtures/workspaces/lib-upgrade' |
| 92 | + end |
| 93 | + |
| 94 | + it "claims to upgrade all upgradable libraries" do |
| 95 | + expect { subject.run %w[generate -u] }.to output_approval('cli/generate/upgrade') |
| 96 | + end |
| 97 | + |
| 98 | + it "actually upgrades all upgradable libraries" do |
| 99 | + lib_files.each do |file| |
| 100 | + File.append file, outdated_text |
| 101 | + end |
| 102 | + |
| 103 | + expect { subject.run %w[generate -u] }.to output_approval('cli/generate/upgrade') |
| 104 | + |
| 105 | + lib_files.each do |file| |
| 106 | + expect(File.read file).to_not include(outdated_text), |
| 107 | + "Expected to not find #{outdated_text} in #{file}, but found it" |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + context "when the magic comment does not exist in the target file" do |
| 112 | + let(:selective_lib_files) { lib_files[0..-2] } |
| 113 | + |
| 114 | + before do |
| 115 | + selective_lib_files.each do |file| |
| 116 | + File.write file, File.read(file).gsub("[@bashly-upgrade", "[@please-dont") |
| 117 | + end |
| 118 | + end |
| 119 | + |
| 120 | + it "avoids upgrading it" do |
| 121 | + expect { subject.run %w[generate -u] }.to output_approval('cli/generate/dont-upgrade') |
| 122 | + |
| 123 | + selective_lib_files.each do |file| |
| 124 | + expect(File.read file).to include("@please-dont"), |
| 125 | + "Expected to find @please-dont in #{file}, but didn't" |
| 126 | + end |
| 127 | + end |
| 128 | + end |
| 129 | + |
| 130 | + context "when the upgrade candidate has a different path than the library's" do |
| 131 | + let(:file) { lib_files[0] } |
| 132 | + let(:custom_text) { "CUSTOM TEXT" } |
| 133 | + let(:alt_filename) { file.gsub /([a-z])\.sh/, '\1-b.sh' } |
| 134 | + |
| 135 | + before do |
| 136 | + File.append file, custom_text |
| 137 | + expect(system "mv #{file} #{alt_filename}").to be true |
| 138 | + end |
| 139 | + |
| 140 | + it "avoids upgrading it and shows a warning" do |
| 141 | + expect { subject.run %w[generate -u] }.to output_approval('cli/generate/upgrade-path-mismatch') |
| 142 | + |
| 143 | + expect(File.read alt_filename).to include(custom_text), |
| 144 | + "Expected to find #{custom_text} in #{file}, but didn't" |
| 145 | + end |
| 146 | + end |
| 147 | + |
| 148 | + end |
86 | 149 | end |
0 commit comments