@@ -112,38 +112,36 @@ def read_cache(cache_file)
112
112
let ( :cache_file_name ) { '.within_date.log' }
113
113
114
114
it 'does not write file if timestamp is within date' do
115
- # this is frozen to within 7 days of the log
116
- new_time = Time . local ( 2015 , 10 , 20 , 12 , 0 , 0 )
117
- Timecop . freeze ( new_time )
118
-
119
- log = read_cache ( cache_file )
120
- current_time = log . values . first [ 'time' ]
121
115
122
116
expect_any_instance_of ( HTMLProofer ::Cache ) . to receive ( :write )
123
- run_proofer ( [ 'www.github.com' ] , :links , cache : { timeframe : '30d' , cache_file : cache_file_name } . merge ( default_cache_options ) )
124
117
125
- # note that the timestamp did not change
126
- log = read_cache ( cache_file )
127
- new_time = log . values . first [ 'time' ]
128
- expect ( current_time ) . to eq ( new_time )
118
+ # we expect no add...
119
+ expect_any_instance_of ( HTMLProofer ::Cache ) . to_not receive ( :add )
120
+ # ...since we are mocking within_timeframe? to be true
121
+ within = true
122
+ expect_any_instance_of ( HTMLProofer ::Cache ) . to receive ( :within_timeframe? ) . and_return ( within )
123
+
124
+ run_proofer ( [ 'www.github.com' ] , :links , cache : { timeframe : '30d' , cache_file : cache_file_name } . merge ( default_cache_options ) )
129
125
130
- Timecop . return
131
126
end
132
127
end
133
128
134
129
context 'not within date' do
135
130
let ( :cache_file_name ) { '.not_within_date.log' }
136
131
137
132
it 'does write file if timestamp is not within date' do
138
- # this is frozen to within 20 days after the log
139
- new_time = Time . local ( 2014 , 10 , 21 , 12 , 0 , 0 )
140
- Timecop . travel ( new_time )
141
133
142
- # since the timestamp changed, we expect an add
143
- expect_any_instance_of ( HTMLProofer ::Cache ) . to receive ( :add )
134
+ # mock within_timeframe
135
+ expect_any_instance_of ( HTMLProofer ::Cache ) . to receive ( :write )
136
+
137
+ # we expect an add...
138
+ expect_any_instance_of ( HTMLProofer ::Cache ) . to receive ( :add ) . with ( 'www.github.com' , nil , 200 )
139
+ # ...since we are mocking within_timeframe? to be true
140
+ within = false
141
+ expect_any_instance_of ( HTMLProofer ::Cache ) . to receive ( :within_timeframe? ) . and_return ( within )
142
+
144
143
run_proofer ( [ 'www.github.com' ] , :links , cache : { timeframe : '4d' , cache_file : cache_file_name } . merge ( default_cache_options ) )
145
144
146
- Timecop . return
147
145
end
148
146
end
149
147
@@ -170,18 +168,17 @@ def read_cache(cache_file)
170
168
let ( :cache_file_name ) { '.recheck_failure.log' }
171
169
172
170
it 'does recheck failures, regardless of cache' do
173
- # this is frozen to within 7 days of the log
174
- new_time = Time . local ( 2015 , 10 , 20 , 12 , 0 , 0 )
175
- Timecop . freeze ( new_time )
176
171
177
172
expect_any_instance_of ( HTMLProofer ::Cache ) . to receive ( :write )
173
+
178
174
# we expect the same link to be readded...
179
175
expect_any_instance_of ( HTMLProofer ::Cache ) . to receive ( :add )
176
+ # ...even though we are within the time frame
177
+ within = true
178
+ expect_any_instance_of ( HTMLProofer ::Cache ) . to receive ( :within_timeframe? ) . and_return ( within )
180
179
181
- # ...even though we are within the 30d time frame, because it's a failure
182
180
run_proofer ( [ 'http://www.foofoofoo.biz' ] , :links , cache : { timeframe : '30d' , cache_file : cache_file_name } . merge ( default_cache_options ) )
183
181
184
- Timecop . return
185
182
end
186
183
end
187
184
end
0 commit comments