|
102 | 102 | end
|
103 | 103 |
|
104 | 104 | context 'changes' do
|
105 |
| - it 'reports an error when the install path is invalid' do |
| 105 | + let(:tmp) { tmpdir('module_changes') } |
| 106 | + |
| 107 | + before :each do |
106 | 108 | Puppet.initialize_settings(['-E', 'direnv'])
|
107 | 109 | Puppet[:color] = false
|
| 110 | + end |
| 111 | + |
| 112 | + def use_local_fixture |
108 | 113 | Puppet[:environmentpath] = File.join(my_fixture_dir, 'environments')
|
109 |
| - dir = tmpdir('module_changes') |
| 114 | + end |
| 115 | + |
| 116 | + def create_working_copy |
| 117 | + Puppet[:environmentpath] = File.join(tmp, 'environments') |
| 118 | + FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp) |
| 119 | + end |
| 120 | + |
| 121 | + it 'reports an error when the install path is invalid' do |
| 122 | + use_local_fixture |
110 | 123 |
|
111 | 124 | pattern = Regexp.new([
|
112 |
| - %Q{.*Error: Could not find a valid module at "#{dir}/nginx".*}, |
| 125 | + %Q{.*Error: Could not find a valid module at "#{tmp}/nginx".*}, |
113 | 126 | %Q{.*Error: Try 'puppet help module changes' for usage.*},
|
114 | 127 | ].join("\n"), Regexp::MULTILINE)
|
115 | 128 |
|
116 | 129 | expect {
|
117 |
| - app.command_line.args = ['changes', File.join(dir, 'nginx')] |
| 130 | + app.command_line.args = ['changes', File.join(tmp, 'nginx')] |
118 | 131 | app.run
|
119 | 132 | }.to exit_with(1)
|
120 | 133 | .and output(pattern).to_stderr
|
121 | 134 | end
|
122 | 135 |
|
123 | 136 | it 'reports when checksums are missing from metadata.json' do
|
124 |
| - tmp = tmpdir('module_invalid_checksums') |
125 |
| - FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp) |
| 137 | + create_working_copy |
126 | 138 |
|
127 | 139 | # overwrite checksums in metadata.json
|
128 | 140 | nginx_dir = File.join(tmp, 'environments', 'direnv', 'modules', 'nginx')
|
|
133 | 145 | }
|
134 | 146 | END
|
135 | 147 |
|
136 |
| - Puppet.initialize_settings(['-E', 'direnv']) |
137 |
| - Puppet[:color] = false |
138 |
| - Puppet[:environmentpath] = File.join(tmp, 'environments') |
139 |
| - |
140 | 148 | pattern = Regexp.new([
|
141 | 149 | %Q{.*Error: No file containing checksums found.*},
|
142 | 150 | %Q{.*Error: Try 'puppet help module changes' for usage.*},
|
|
150 | 158 | end
|
151 | 159 |
|
152 | 160 | it 'reports module not found when metadata.json is missing' do
|
153 |
| - tmp = tmpdir('module_missing_metadata') |
154 |
| - FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp) |
| 161 | + create_working_copy |
155 | 162 |
|
156 | 163 | # overwrite checksums in metadata.json
|
157 | 164 | nginx_dir = File.join(tmp, 'environments', 'direnv', 'modules', 'nginx')
|
158 | 165 | File.unlink(File.join(nginx_dir, 'metadata.json'))
|
159 | 166 |
|
160 |
| - Puppet.initialize_settings(['-E', 'direnv']) |
161 |
| - Puppet[:color] = false |
162 |
| - Puppet[:environmentpath] = File.join(tmp, 'environments') |
163 |
| - |
164 | 167 | pattern = Regexp.new([
|
165 | 168 | %Q{.*Error: Could not find a valid module at.*},
|
166 | 169 | %Q{.*Error: Try 'puppet help module changes' for usage.*},
|
|
174 | 177 | end
|
175 | 178 |
|
176 | 179 | it 'reports when a file is modified' do
|
177 |
| - tmp = tmpdir('module_modified_metadata') |
178 |
| - FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp) |
| 180 | + create_working_copy |
179 | 181 |
|
180 | 182 | # overwrite README so checksum doesn't match
|
181 | 183 | nginx_dir = File.join(tmp, 'environments', 'direnv', 'modules', 'nginx')
|
182 | 184 | File.write(File.join(nginx_dir, 'README'), '')
|
183 | 185 |
|
184 |
| - Puppet.initialize_settings(['-E', 'direnv']) |
185 |
| - Puppet[:color] = false |
186 |
| - Puppet[:environmentpath] = File.join(tmp, 'environments') |
187 |
| - |
188 | 186 | pattern = Regexp.new([
|
189 | 187 | %Q{.*Warning: 1 files modified.*},
|
190 | 188 | ].join("\n"), Regexp::MULTILINE)
|
|
198 | 196 | end
|
199 | 197 |
|
200 | 198 | it 'reports when a file is missing' do
|
201 |
| - tmp = tmpdir('module_missing_file') |
202 |
| - FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp) |
| 199 | + create_working_copy |
203 | 200 |
|
204 | 201 | # delete README so checksum doesn't match
|
205 | 202 | nginx_dir = File.join(tmp, 'environments', 'direnv', 'modules', 'nginx')
|
206 | 203 | File.unlink(File.join(nginx_dir, 'README'))
|
207 | 204 |
|
208 |
| - Puppet.initialize_settings(['-E', 'direnv']) |
209 |
| - Puppet[:color] = false |
210 |
| - Puppet[:environmentpath] = File.join(tmp, 'environments') |
211 |
| - |
212 | 205 | # odd that it says modified
|
213 | 206 | pattern = Regexp.new([
|
214 | 207 | %Q{.*Warning: 1 files modified.*},
|
|
223 | 216 | end
|
224 | 217 |
|
225 | 218 | it 'reports when there are no changes' do
|
226 |
| - Puppet.initialize_settings(['-E', 'direnv']) |
227 |
| - Puppet[:color] = false |
228 |
| - Puppet[:environmentpath] = File.join(my_fixture_dir, 'environments') |
| 219 | + use_local_fixture |
| 220 | + |
229 | 221 | nginx_dir = File.join(Puppet[:environmentpath], 'direnv', 'modules', 'nginx')
|
230 | 222 |
|
231 | 223 | expect {
|
|
0 commit comments