|
18 | 18 | } |
19 | 19 | end |
20 | 20 |
|
| 21 | + # File list helpers |
| 22 | + let(:key_files) { Dir.glob(File.join(committed_cache_path, "*.key")) } |
| 23 | + let(:value_files) { Dir.glob(File.join(committed_cache_path, "*.value")) } |
| 24 | + let(:all_files) do |
| 25 | + Dir.glob(File.join(committed_cache_path, "**", "*"), File::FNM_DOTMATCH) |
| 26 | + .reject { |f| File.directory?(f) } |
| 27 | + .sort |
| 28 | + end |
| 29 | + let(:key_contents) { key_files.map { |f| File.read(f) }.sort } |
| 30 | + |
21 | 31 | # Shared examples for validating cache state |
22 | 32 | shared_examples "validates committed cache files" do |
23 | 33 | it "has the expected number of key files" do |
24 | | - key_files = Dir.glob(File.join(committed_cache_path, "*.key")) |
25 | 34 | expect(key_files.length).to eq(3) |
26 | 35 | end |
27 | 36 |
|
28 | 37 | it "has the expected number of value files" do |
29 | | - value_files = Dir.glob(File.join(committed_cache_path, "*.value")) |
30 | 38 | expect(value_files.length).to eq(3) |
31 | 39 | end |
32 | 40 |
|
33 | 41 | it "preserves original keys in .key files" do |
34 | | - key_files = Dir.glob(File.join(committed_cache_path, "*.key")) |
35 | | - key_contents = key_files.map { |f| File.read(f) }.sort |
36 | 42 | expect(key_contents).to contain_exactly(*cache_entries.keys.sort) |
37 | 43 | end |
38 | 44 |
|
39 | 45 | it "has valid value files that can be deserialized" do |
40 | | - value_files = Dir.glob(File.join(committed_cache_path, "*.value")) |
41 | 46 | # All value files should be readable |
42 | 47 | value_files.each do |value_file| |
43 | 48 | expect(File.read(value_file).length).to be > 0 |
44 | 49 | end |
45 | 50 | end |
46 | 51 |
|
47 | 52 | it "maintains the exact file count" do |
48 | | - current_files = Dir.glob(File.join(committed_cache_path, "**", "*"), File::FNM_DOTMATCH) |
49 | | - .reject { |f| File.directory?(f) } |
50 | | - .sort |
51 | 53 | # Should have exactly 7 files (3 entries × 2 files each + 1 README.md) |
52 | | - expect(current_files.length).to eq(7) |
| 54 | + expect(all_files.length).to eq(7) |
53 | 55 | end |
54 | 56 | end |
55 | 57 |
|
56 | 58 | describe "cache stability verification" do |
57 | 59 | # Capture initial state for comparison |
58 | | - let(:initial_file_list) do |
59 | | - Dir.glob(File.join(committed_cache_path, "**", "*"), File::FNM_DOTMATCH) |
60 | | - .reject { |f| File.directory?(f) } |
61 | | - .sort |
62 | | - end |
| 60 | + let(:initial_file_list) { all_files } |
63 | 61 |
|
64 | 62 | before(:each) do |
65 | 63 | # Ensure cache entries exist before each test using raw mode |
|
77 | 75 | store.read(key, raw: true) |
78 | 76 | end |
79 | 77 |
|
80 | | - # Get current file list |
81 | | - current_files = Dir.glob(File.join(committed_cache_path, "**", "*"), File::FNM_DOTMATCH) |
82 | | - .reject { |f| File.directory?(f) } |
83 | | - .sort |
84 | | - |
85 | 78 | # Verify no new files were created |
86 | | - expect(current_files).to eq(files_before) |
| 79 | + expect(all_files).to eq(files_before) |
87 | 80 | end |
88 | 81 |
|
89 | 82 | it "does not create new files when writing to existing keys with same values" do |
|
95 | 88 | store.write(key, value, raw: true) |
96 | 89 | end |
97 | 90 |
|
98 | | - # Get current file list |
99 | | - current_files = Dir.glob(File.join(committed_cache_path, "**", "*"), File::FNM_DOTMATCH) |
100 | | - .reject { |f| File.directory?(f) } |
101 | | - .sort |
102 | | - |
103 | 91 | # Verify no new files were created (same files should exist) |
104 | | - expect(current_files).to eq(files_before) |
| 92 | + expect(all_files).to eq(files_before) |
105 | 93 | end |
106 | 94 |
|
107 | 95 | it "has all expected cache files present" do |
|
122 | 110 | end |
123 | 111 | end |
124 | 112 |
|
125 | | - # Get current file list |
126 | | - current_files = Dir.glob(File.join(committed_cache_path, "**", "*"), File::FNM_DOTMATCH) |
127 | | - .reject { |f| File.directory?(f) } |
128 | | - .sort |
129 | | - |
130 | 113 | # Verify no new files were created |
131 | | - expect(current_files).to eq(files_before) |
| 114 | + expect(all_files).to eq(files_before) |
132 | 115 | end |
133 | 116 |
|
134 | 117 | include_examples "validates committed cache files" |
|
0 commit comments