|
241 | 241 | end |
242 | 242 | end |
243 | 243 |
|
244 | | - context 'with display_detail_add on' do |
245 | | - describe '#generate' do |
246 | | - before(:all) do |
247 | | - diff = [ |
248 | | - [ |
249 | | - '+', |
250 | | - 'File[/tmp/foo]', |
251 | | - { |
252 | | - 'type' => 'File', |
253 | | - 'title' => '/tmp/foo', |
254 | | - 'parameters' => { |
255 | | - 'mode' => '0644', |
256 | | - 'content' => 'x' * 150, |
257 | | - 'owner' => 'root', |
258 | | - 'group' => 'wheel' |
259 | | - } |
| 244 | + context 'with display_detail_add' do |
| 245 | + before(:all) do |
| 246 | + @diff = [ |
| 247 | + [ |
| 248 | + '+', |
| 249 | + 'File[/tmp/foo]', |
| 250 | + { |
| 251 | + 'type' => 'File', |
| 252 | + 'title' => '/tmp/foo', |
| 253 | + 'parameters' => { |
| 254 | + 'mode' => '0644', |
| 255 | + 'content' => 'x' * 150, |
| 256 | + 'owner' => 'root', |
| 257 | + 'group' => 'wheel' |
260 | 258 | } |
261 | | - ] |
| 259 | + } |
262 | 260 | ] |
263 | | - @result = OctocatalogDiff::CatalogDiff::Display::Text.generate(diff, display_detail_add: true, color: false) |
264 | | - end |
| 261 | + ] |
| 262 | + end |
265 | 263 |
|
266 | | - it 'should display parameters when display_detail_add is true' do |
267 | | - expect(@result[1]).to match(/^\s+parameters =>/) |
| 264 | + context 'with --no-truncate-details' do |
| 265 | + describe '#generate' do |
| 266 | + before(:all) do |
| 267 | + @result = OctocatalogDiff::CatalogDiff::Display::Text.generate( |
| 268 | + @diff, |
| 269 | + display_detail_add: true, |
| 270 | + color: false, |
| 271 | + truncate_details: false |
| 272 | + ) |
| 273 | + end |
| 274 | + |
| 275 | + it 'should not truncate long strings' do |
| 276 | + expect(@result[2]).to match(/^\s+"content": /) |
| 277 | + expect(@result[2].length).to eq(169), "Wrong line length for: '#{@result[2]}': #{@result[2].length}" |
| 278 | + end |
268 | 279 | end |
| 280 | + end |
269 | 281 |
|
270 | | - it 'should truncate long strings' do |
271 | | - expect(@result[2]).to match(/^\s+"content": /) |
272 | | - # Desired line length is 84 because the '..."' adds 4 characters to the truncated length of 80 |
273 | | - expect(@result[2].length).to eq(84), "Wrong line length for: '#{@result[2]}'" |
| 282 | + context 'with --no-truncate-details and a multi-line string' do |
| 283 | + describe '#generate' do |
| 284 | + before(:all) do |
| 285 | + diff = [ |
| 286 | + [ |
| 287 | + '+', |
| 288 | + 'File[/tmp/foo]', |
| 289 | + { |
| 290 | + 'type' => 'File', |
| 291 | + 'title' => '/tmp/foo', |
| 292 | + 'parameters' => { |
| 293 | + 'mode' => '0644', |
| 294 | + 'content' => "foo\nbar\nbaz", |
| 295 | + 'owner' => 'root', |
| 296 | + 'group' => 'wheel' |
| 297 | + } |
| 298 | + } |
| 299 | + ] |
| 300 | + ] |
| 301 | + @result = OctocatalogDiff::CatalogDiff::Display::Text.generate( |
| 302 | + diff, |
| 303 | + display_detail_add: true, |
| 304 | + color: false, |
| 305 | + truncate_details: false |
| 306 | + ) |
| 307 | + end |
| 308 | + |
| 309 | + it 'should sort keys without newlines before keys with newlines' do |
| 310 | + expect(@result[2]).to match(/^\s+"group": /) |
| 311 | + expect(@result[3]).to match(/^\s+"mode": /) |
| 312 | + expect(@result[4]).to match(/^\s+"owner": /) |
| 313 | + end |
| 314 | + |
| 315 | + it 'should display lines on their own' do |
| 316 | + expect(@result[5]).to match(/^\s+"content": >>>/) |
| 317 | + expect(@result[6]).to eq('foo') |
| 318 | + expect(@result[7]).to eq('bar') |
| 319 | + expect(@result[8]).to eq('baz') |
| 320 | + expect(@result[9]).to eq('<<<') |
| 321 | + end |
274 | 322 | end |
| 323 | + end |
275 | 324 |
|
276 | | - it 'should sort keys in parameters hash' do |
277 | | - index_content = @result.find_index { |x| x =~ /^\s+"content": / } |
278 | | - expect(index_content).not_to be(nil), 'Results missing "content"' |
279 | | - index_group = @result.find_index { |x| x =~ /^\s+"group": / } |
280 | | - expect(index_group).not_to be(nil), 'Results missing "group"' |
281 | | - index_mode = @result.find_index { |x| x =~ /^\s+"mode": / } |
282 | | - expect(index_mode).not_to be(nil), 'Results missing "mode"' |
283 | | - index_owner = @result.find_index { |x| x =~ /^\s+"owner": / } |
284 | | - expect(index_owner).not_to be(nil), 'Results missing "owner"' |
285 | | - expect(index_content).to be < index_group |
286 | | - expect(index_group).to be < index_mode |
287 | | - expect(index_mode).to be < index_owner |
| 325 | + context 'without --no-truncate-details' do |
| 326 | + describe '#generate' do |
| 327 | + before(:all) do |
| 328 | + @result = OctocatalogDiff::CatalogDiff::Display::Text.generate(@diff, display_detail_add: true, color: false) |
| 329 | + end |
| 330 | + |
| 331 | + it 'should display parameters when display_detail_add is true' do |
| 332 | + expect(@result[1]).to match(/^\s+parameters =>/) |
| 333 | + end |
| 334 | + |
| 335 | + it 'should truncate long strings' do |
| 336 | + expect(@result[2]).to match(/^\s+"content": /) |
| 337 | + # Desired line length is 84 because the '..."' adds 4 characters to the truncated length of 80 |
| 338 | + expect(@result[2].length).to eq(84), "Wrong line length for: '#{@result[2]}'" |
| 339 | + end |
| 340 | + |
| 341 | + it 'should sort keys in parameters hash' do |
| 342 | + index_content = @result.find_index { |x| x =~ /^\s+"content": / } |
| 343 | + expect(index_content).not_to be(nil), 'Results missing "content"' |
| 344 | + index_group = @result.find_index { |x| x =~ /^\s+"group": / } |
| 345 | + expect(index_group).not_to be(nil), 'Results missing "group"' |
| 346 | + index_mode = @result.find_index { |x| x =~ /^\s+"mode": / } |
| 347 | + expect(index_mode).not_to be(nil), 'Results missing "mode"' |
| 348 | + index_owner = @result.find_index { |x| x =~ /^\s+"owner": / } |
| 349 | + expect(index_owner).not_to be(nil), 'Results missing "owner"' |
| 350 | + expect(index_content).to be < index_group |
| 351 | + expect(index_group).to be < index_mode |
| 352 | + expect(index_mode).to be < index_owner |
| 353 | + end |
288 | 354 | end |
289 | 355 | end |
290 | 356 | end |
|
0 commit comments