Skip to content

Commit 3cc89fc

Browse files
Copilotnhorton
andcommitted
Refactor committed cache specs based on code review feedback
Co-authored-by: nhorton <[email protected]>
1 parent e62b1d6 commit 3cc89fc

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

spec/committed_cache_spec.rb

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@
77
let(:committed_cache_path) { File.join(__dir__, "fixtures", "committed_cache") }
88
let(:store) { ActiveSupport::Cache::SourceControlCacheStore.new(cache_path: committed_cache_path) }
99

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-
2110
describe "initial cache population" do
2211
it "creates the cache directory if it doesn't exist" do
2312
expect(File.directory?(committed_cache_path)).to be true
@@ -52,22 +41,24 @@
5241
end
5342

5443
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
6153
store.write("user:123:profile", { name: "John Doe", email: "[email protected]" })
6254
store.write("user:456:profile", { name: "Jane Smith", email: "[email protected]" })
6355
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
6856
end
6957

7058
it "does not create new files when reading existing entries" do
59+
# Capture state before reading
60+
files_before = initial_file_list
61+
7162
# Read existing entries
7263
store.read("user:123:profile")
7364
store.read("user:456:profile")
@@ -79,10 +70,13 @@
7970
.sort
8071

8172
# Verify no new files were created
82-
expect(current_files).to eq(@initial_file_list)
73+
expect(current_files).to eq(files_before)
8374
end
8475

8576
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+
8680
# Write same values to existing keys
8781
store.write("user:123:profile", { name: "John Doe", email: "[email protected]" })
8882
store.write("user:456:profile", { name: "Jane Smith", email: "[email protected]" })
@@ -94,7 +88,7 @@
9488
.sort
9589

9690
# 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)
9892
end
9993

10094
it "has all expected cache files present" do
@@ -114,6 +108,9 @@
114108
end
115109

116110
it "does not create new files during multiple read operations" do
111+
# Capture state before reading
112+
files_before = initial_file_list
113+
117114
# Perform multiple read operations
118115
10.times do
119116
store.read("user:123:profile")
@@ -127,7 +124,7 @@
127124
.sort
128125

129126
# Verify no new files were created
130-
expect(current_files).to eq(@initial_file_list)
127+
expect(current_files).to eq(files_before)
131128
end
132129
end
133130

0 commit comments

Comments
 (0)