|
| 1 | +require "spec_helper" |
| 2 | +require "json" |
| 3 | + |
| 4 | +RSpec.describe RailsTracepointStack::Duration::Output do |
| 5 | + describe "#show_top_files" do |
| 6 | + before do |
| 7 | + allow(File) |
| 8 | + .to receive(:open) |
| 9 | + .with("log-boot-4.txt", "r") |
| 10 | + .and_return( |
| 11 | + StringIO.new( |
| 12 | + {file: "file1", duration: 1}.to_json + "\n" + |
| 13 | + {file: "file1", duration: 2}.to_json + "\n" + |
| 14 | + {file: "file2", duration: 1}.to_json + "\n" + |
| 15 | + {file: "file2", duration: 1}.to_json + "\n" + |
| 16 | + {file: "file2", duration: 1}.to_json + "\n" + |
| 17 | + {file: "file3", duration: 1}.to_json + "\n" + |
| 18 | + {file: "file4", duration: 1}.to_json + "\n" + |
| 19 | + {file: "file5", duration: 1}.to_json + "\n" + |
| 20 | + {file: "file5", duration: 1}.to_json + "\n" + |
| 21 | + {file: "file5", duration: 1}.to_json + "\n" + |
| 22 | + {file: "file6", duration: 1}.to_json + "\n" + |
| 23 | + {file: "file7", duration: 1}.to_json + "\n" + |
| 24 | + {file: "file8", duration: 1}.to_json + "\n" + |
| 25 | + {file: "file9", duration: 1}.to_json + "\n" + |
| 26 | + {file: "file10", duration: 1}.to_json + "\n" + |
| 27 | + {file: "file11", duration: 1}.to_json + "\n" |
| 28 | + ) |
| 29 | + ) |
| 30 | + end |
| 31 | + |
| 32 | + it "prints the top 10 files with their total duration" do |
| 33 | + expect { described_class.new.show_top_files } |
| 34 | + .to output( |
| 35 | + <<~OUTPUT |
| 36 | + 1. File: file1 - Total Duration: 3 seconds |
| 37 | + 2. File: file2 - Total Duration: 3 seconds |
| 38 | + 3. File: file5 - Total Duration: 3 seconds |
| 39 | + 4. File: file3 - Total Duration: 1 seconds |
| 40 | + 5. File: file4 - Total Duration: 1 seconds |
| 41 | + 6. File: file6 - Total Duration: 1 seconds |
| 42 | + 7. File: file7 - Total Duration: 1 seconds |
| 43 | + 8. File: file8 - Total Duration: 1 seconds |
| 44 | + 9. File: file9 - Total Duration: 1 seconds |
| 45 | + 10. File: file10 - Total Duration: 1 seconds |
| 46 | + OUTPUT |
| 47 | + ).to_stdout |
| 48 | + end |
| 49 | + end |
| 50 | +end |
0 commit comments