|
184 | 184 | expect(content.respond_to?("diff")).to eq(false)
|
185 | 185 | end
|
186 | 186 |
|
187 |
| - [true, false].product([true, false]).each do |cfg, param| |
188 |
| - describe "and Puppet[:show_diff] is #{cfg} and show_diff => #{param}" do |
| 187 | + describe "showing the diff" do |
| 188 | + it "doesn't show the diff when #show_diff? is false" do |
| 189 | + content.expects(:show_diff?).returns false |
| 190 | + content.expects(:diff).never |
| 191 | + expect(content).not_to be_safe_insync("other content") |
| 192 | + end |
| 193 | + |
| 194 | + describe "and #show_diff? is true" do |
189 | 195 | before do
|
190 |
| - Puppet[:show_diff] = cfg |
191 |
| - resource.stubs(:show_diff?).returns param |
| 196 | + content.expects(:show_diff?).returns true |
192 | 197 | resource[:loglevel] = "debug"
|
193 | 198 | end
|
194 | 199 |
|
195 |
| - if cfg and param |
196 |
| - it "should display a diff" do |
197 |
| - content.expects(:diff).returns("my diff").once |
198 |
| - content.expects(:debug).with("\nmy diff").once |
199 |
| - expect(content).not_to be_safe_insync("other content") |
200 |
| - end |
201 |
| - else |
202 |
| - it "should not display a diff" do |
203 |
| - content.expects(:diff).never |
204 |
| - expect(content).not_to be_safe_insync("other content") |
205 |
| - end |
| 200 | + it "prints the diff" do |
| 201 | + content.expects(:diff).returns("my diff").once |
| 202 | + content.expects(:debug).with("\nmy diff").once |
| 203 | + expect(content).not_to be_safe_insync("other content") |
| 204 | + end |
| 205 | + |
| 206 | + it "redacts the diff when the property is sensitive" do |
| 207 | + content.sensitive = true |
| 208 | + content.expects(:diff).returns("my diff").never |
| 209 | + content.expects(:debug).with("[diff redacted]").once |
| 210 | + expect(content).not_to be_safe_insync("other content") |
206 | 211 | end
|
207 | 212 | end
|
208 | 213 | end
|
|
308 | 313 | end
|
309 | 314 | end
|
310 | 315 |
|
| 316 | + describe "determining if a diff should be shown" do |
| 317 | + let(:content) { described_class.new(:resource => resource) } |
| 318 | + |
| 319 | + before do |
| 320 | + Puppet[:show_diff] = true |
| 321 | + resource[:show_diff] = true |
| 322 | + end |
| 323 | + |
| 324 | + it "is true if there are changes and the global and per-resource show_diff settings are true" do |
| 325 | + expect(content.show_diff?(true)).to be_truthy |
| 326 | + end |
| 327 | + |
| 328 | + it "is false if there are no changes" do |
| 329 | + expect(content.show_diff?(false)).to be_falsey |
| 330 | + end |
| 331 | + |
| 332 | + it "is false if show_diff is globally disabled" do |
| 333 | + Puppet[:show_diff] = false |
| 334 | + expect(content.show_diff?(false)).to be_falsey |
| 335 | + end |
| 336 | + |
| 337 | + it "is false if show_diff is disabled on the resource" do |
| 338 | + resource[:show_diff] = false |
| 339 | + expect(content.show_diff?(false)).to be_falsey |
| 340 | + end |
| 341 | + end |
| 342 | + |
311 | 343 | describe "when changing the content" do
|
312 | 344 | let(:content) { described_class.new(:resource => resource) }
|
313 | 345 |
|
|
0 commit comments