|
7 | 7 | let(:committed_cache_path) { File.join(__dir__, "fixtures", "committed_cache") } |
8 | 8 | let(:store) { ActiveSupport::Cache::SourceControlCacheStore.new(cache_path: committed_cache_path) } |
9 | 9 |
|
10 | | - # Track files that exist at the start of the test suite |
11 | | - let(:initial_files) do |
12 | | - if File.directory?(committed_cache_path) |
13 | | - Dir.glob(File.join(committed_cache_path, "**", "*"), File::FNM_DOTMATCH) |
14 | | - .reject { |f| File.directory?(f) } |
15 | | - .sort |
16 | | - else |
17 | | - [] |
18 | | - end |
19 | | - end |
20 | | - |
21 | 10 | describe "initial cache population" do |
22 | 11 | it "creates the cache directory if it doesn't exist" do |
23 | 12 | expect(File.directory?(committed_cache_path)).to be true |
|
52 | 41 | end |
53 | 42 |
|
54 | 43 | describe "cache stability verification" do |
55 | | - before(:all) do |
56 | | - # Capture the state of files before any tests run |
57 | | - committed_cache_path = File.join(__dir__, "fixtures", "committed_cache") |
58 | | - store = ActiveSupport::Cache::SourceControlCacheStore.new(cache_path: committed_cache_path) |
59 | | - |
60 | | - # Ensure initial cache entries exist |
| 44 | + # Capture initial state for comparison |
| 45 | + let(:initial_file_list) do |
| 46 | + Dir.glob(File.join(committed_cache_path, "**", "*"), File::FNM_DOTMATCH) |
| 47 | + .reject { |f| File.directory?(f) } |
| 48 | + .sort |
| 49 | + end |
| 50 | + |
| 51 | + before(:each) do |
| 52 | + # Ensure cache entries exist before each test |
61 | 53 | store.write("user:123:profile", { name: "John Doe", email: "[email protected]" }) |
62 | 54 | store.write("user:456:profile", { name: "Jane Smith", email: "[email protected]" }) |
63 | 55 | store.write("config:app:settings", { theme: "dark", language: "en" }) |
64 | | - |
65 | | - @initial_file_list = Dir.glob(File.join(committed_cache_path, "**", "*"), File::FNM_DOTMATCH) |
66 | | - .reject { |f| File.directory?(f) } |
67 | | - .sort |
68 | 56 | end |
69 | 57 |
|
70 | 58 | it "does not create new files when reading existing entries" do |
| 59 | + # Capture state before reading |
| 60 | + files_before = initial_file_list |
| 61 | + |
71 | 62 | # Read existing entries |
72 | 63 | store.read("user:123:profile") |
73 | 64 | store.read("user:456:profile") |
|
79 | 70 | .sort |
80 | 71 |
|
81 | 72 | # Verify no new files were created |
82 | | - expect(current_files).to eq(@initial_file_list) |
| 73 | + expect(current_files).to eq(files_before) |
83 | 74 | end |
84 | 75 |
|
85 | 76 | it "does not create new files when writing to existing keys with same values" do |
| 77 | + # Capture state before writing |
| 78 | + files_before = initial_file_list |
| 79 | + |
86 | 80 | # Write same values to existing keys |
87 | 81 | store.write("user:123:profile", { name: "John Doe", email: "[email protected]" }) |
88 | 82 | store.write("user:456:profile", { name: "Jane Smith", email: "[email protected]" }) |
|
94 | 88 | .sort |
95 | 89 |
|
96 | 90 | # Verify no new files were created (same files should exist) |
97 | | - expect(current_files).to eq(@initial_file_list) |
| 91 | + expect(current_files).to eq(files_before) |
98 | 92 | end |
99 | 93 |
|
100 | 94 | it "has all expected cache files present" do |
|
114 | 108 | end |
115 | 109 |
|
116 | 110 | it "does not create new files during multiple read operations" do |
| 111 | + # Capture state before reading |
| 112 | + files_before = initial_file_list |
| 113 | + |
117 | 114 | # Perform multiple read operations |
118 | 115 | 10.times do |
119 | 116 | store.read("user:123:profile") |
|
127 | 124 | .sort |
128 | 125 |
|
129 | 126 | # Verify no new files were created |
130 | | - expect(current_files).to eq(@initial_file_list) |
| 127 | + expect(current_files).to eq(files_before) |
131 | 128 | end |
132 | 129 | end |
133 | 130 |
|
|
0 commit comments