diff --git a/lib/html-proofer/cache.rb b/lib/html-proofer/cache.rb index 1eaa2852..6351dd23 100644 --- a/lib/html-proofer/cache.rb +++ b/lib/html-proofer/cache.rb @@ -120,9 +120,8 @@ def retrieve_urls(external_urls) @cache_log.each_pair do |url, cache| if within_timeframe?(cache['time']) next if cache['message'].empty? # these were successes to skip - else - urls_to_check[url] = cache['filenames'] # recheck expired links end + urls_to_check[url] = cache['filenames'] # recheck expired links end urls_to_check end diff --git a/spec/html-proofer/cache_spec.rb b/spec/html-proofer/cache_spec.rb index 857c51fb..54cb54c7 100644 --- a/spec/html-proofer/cache_spec.rb +++ b/spec/html-proofer/cache_spec.rb @@ -110,37 +110,34 @@ def read_cache(cache_file) context 'within date' do let(:cache_file_name) { '.within_date.log' } - it 'does not write file if timestamp is within date' do # this is frozen to within 7 days of the log - new_time = Time.local(2015, 10, 20, 12, 0, 0) + new_time = Time.local(2015, 10, 27, 12, 0, 0) Timecop.freeze(new_time) - log = read_cache(cache_file) - current_time = log.values.first['time'] - expect_any_instance_of(HTMLProofer::Cache).to receive(:write) - run_proofer(['www.github.com'], :links, cache: { timeframe: '30d', cache_file: cache_file_name }.merge(default_cache_options)) - # note that the timestamp did not change - log = read_cache(cache_file) - new_time = log.values.first['time'] - expect(current_time).to eq(new_time) + # we expect no add since we are within the timeframe + expect_any_instance_of(HTMLProofer::Cache).to_not receive(:add) + + run_proofer(['www.github.com'], :links, cache: { timeframe: '30d', cache_file: cache_file_name }.merge(default_cache_options)) Timecop.return end end context 'not within date' do - let(:cache_file_name) { '.not_within_date.log' } - + let(:cache_file_name) { '.within_date.log' } it 'does write file if timestamp is not within date' do - # this is frozen to within 20 days after the log - new_time = Time.local(2014, 10, 21, 12, 0, 0) - Timecop.travel(new_time) + # this is frozen to within 7 days of the log + new_time = Time.local(2015, 10, 27, 12, 0, 0) + Timecop.freeze(new_time) + + expect_any_instance_of(HTMLProofer::Cache).to receive(:write) + + # we expect an add since we are mocking outside the timeframe + expect_any_instance_of(HTMLProofer::Cache).to receive(:add).with('www.github.com', nil, 200) - # since the timestamp changed, we expect an add - expect_any_instance_of(HTMLProofer::Cache).to receive(:add) run_proofer(['www.github.com'], :links, cache: { timeframe: '4d', cache_file: cache_file_name }.merge(default_cache_options)) Timecop.return @@ -149,14 +146,13 @@ def read_cache(cache_file) context 'new url added' do let(:cache_file_name) { '.new_url.log' } - it 'does write file if a new URL is added' do # this is frozen to within 7 days of the log new_time = Time.local(2015, 10, 20, 12, 0, 0) Timecop.freeze(new_time) expect_any_instance_of(HTMLProofer::Cache).to receive(:write) - # we expect a new link to be added, but github.com can stay... + # we expect one new link to be added, but github.com can stay... expect_any_instance_of(HTMLProofer::Cache).to receive(:add).with('www.google.com', nil, 200) # ...because it's within the 30d time frame @@ -168,17 +164,17 @@ def read_cache(cache_file) context 'recheck failure' do let(:cache_file_name) { '.recheck_failure.log' } - it 'does recheck failures, regardless of cache' do # this is frozen to within 7 days of the log - new_time = Time.local(2015, 10, 20, 12, 0, 0) + new_time = Time.local(2015, 10, 27, 12, 0, 0) Timecop.freeze(new_time) expect_any_instance_of(HTMLProofer::Cache).to receive(:write) - # we expect the same link to be readded... + + # we expect the same link to be re-added, even though we are within the time frame, + # because `foofoofoo.biz` was a failure expect_any_instance_of(HTMLProofer::Cache).to receive(:add) - # ...even though we are within the 30d time frame, because it's a failure run_proofer(['http://www.foofoofoo.biz'], :links, cache: { timeframe: '30d', cache_file: cache_file_name }.merge(default_cache_options)) Timecop.return diff --git a/spec/html-proofer/fixtures/cache/.not_within_date.log b/spec/html-proofer/fixtures/cache/.not_within_date.log deleted file mode 100644 index 31cb822b..00000000 --- a/spec/html-proofer/fixtures/cache/.not_within_date.log +++ /dev/null @@ -1 +0,0 @@ -{"www.github.com":{"time":"2015-10-01 16:18:15 -0700","filenames":null,"status":200,"message":""}} \ No newline at end of file diff --git a/spec/html-proofer/fixtures/cache/.recheck_failure.log b/spec/html-proofer/fixtures/cache/.recheck_failure.log index 4aa0509e..06b73003 100644 --- a/spec/html-proofer/fixtures/cache/.recheck_failure.log +++ b/spec/html-proofer/fixtures/cache/.recheck_failure.log @@ -1 +1 @@ -{"www.foofoofoo.biz":{"time":"2015-10-20 12:00:00 -0700","filenames":null,"status":0,"message":"External link www.foofoofoo.biz failed: 0 "}} \ No newline at end of file +{"http://www.foofoofoo.biz":{"time":"2015-10-20 12:00:00 -0700","filenames":null,"status":0,"message":"External link www.foofoofoo.biz failed: 0 "}} diff --git a/spec/html-proofer/fixtures/cache/.within_date.log b/spec/html-proofer/fixtures/cache/.within_date.log index 4c840aaa..aac87996 100644 --- a/spec/html-proofer/fixtures/cache/.within_date.log +++ b/spec/html-proofer/fixtures/cache/.within_date.log @@ -1 +1 @@ -{"www.github.com":{"time":"2015-10-27 12:00:00 -0700","filenames":null,"status":200,"message":""}} +{"www.github.com":{"time":"2015-10-20 12:00:00 -0700","filenames":null,"status":200,"message":""}} diff --git a/spec/html-proofer/fixtures/vcr_cassettes/www_github_com_cache_timeframe_4d_cache_file_within_date_log_storage_dir_spec/html-proofer/fixtures/cache_log_level_error_type_links_.yml b/spec/html-proofer/fixtures/vcr_cassettes/www_github_com_cache_timeframe_4d_cache_file_within_date_log_storage_dir_spec/html-proofer/fixtures/cache_log_level_error_type_links_.yml new file mode 100644 index 00000000..5448746c --- /dev/null +++ b/spec/html-proofer/fixtures/vcr_cassettes/www_github_com_cache_timeframe_4d_cache_file_within_date_log_storage_dir_spec/html-proofer/fixtures/cache_log_level_error_type_links_.yml @@ -0,0 +1,75 @@ +--- +http_interactions: +- request: + method: head + uri: www.github.com + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; HTML Proofer/3.15.1; +https://github.com/gjtorikian/html-proofer) + Accept: + - application/xml,application/xhtml+xml,text/html;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + Expect: + - '' + response: + status: + code: 200 + message: OK + headers: + Date: + - Tue, 11 Feb 2020 12:26:04 GMT + Content-Type: + - text/html; charset=utf-8 + Server: + - GitHub.com + Status: + - 200 OK + Vary: + - X-PJAX + - Accept-Encoding, Accept + ETag: + - W/"a7cb4d93d4ab298ba08e5b7bfde81bb1" + Cache-Control: + - max-age=0, private, must-revalidate + Set-Cookie: + - _octo=GH1.1.141947230.1581423964; domain=.github.com; path=/; expires=Thu, + 11 Feb 2021 12:26:04 -0000 + - logged_in=no; domain=.github.com; path=/; expires=Thu, 11 Feb 2021 12:26:04 + -0000; secure; HttpOnly + - _gh_sess=Q3lZVkJDU0NrcTEwdUNLUVlzY3VZQkJndWhnakxnUWZIcDY0OExmcXcrd3ZHOXc4RUlRWGIzT3l1SHZwQlZRZmQyZmVJNWJNczN0aUNaVkxGMHBqdnpqcWx4VXFNQSt2RlExUDRtdElyTGtaYTY5OG5rTmVZalVicTc4ekhkSW1OZUJmQ3pKUjlxQld1WHU1cWErczhnPT0tLXJ2ZGIrL25LcWxJUmlkR0srN29Pa1E9PQ%3D%3D--d4aaeed450346ec90679984457d338c49bb643c6; + path=/; secure; HttpOnly + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Frame-Options: + - deny + X-Content-Type-Options: + - nosniff + X-XSS-Protection: + - 1; mode=block + Referrer-Policy: + - origin-when-cross-origin, strict-origin-when-cross-origin + Expect-CT: + - max-age=2592000, report-uri="https://api.github.com/_private/browser/errors" + Content-Security-Policy: + - 'default-src ''none''; base-uri ''self''; block-all-mixed-content; connect-src + ''self'' uploads.github.com www.githubstatus.com collector.githubapp.com api.github.com + www.google-analytics.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com + github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com + wss://live.github.com; font-src github.githubassets.com; form-action ''self'' + github.com gist.github.com; frame-ancestors ''none''; frame-src render.githubusercontent.com; + img-src ''self'' data: github.githubassets.com identicons.github.com collector.githubapp.com + github-cloud.s3.amazonaws.com *.githubusercontent.com customer-stories-feed.github.com + spotlights-feed.github.com; manifest-src ''self''; media-src ''none''; script-src + github.githubassets.com; style-src ''unsafe-inline'' github.githubassets.com' + X-GitHub-Request-Id: + - C3F6:2E6DB:DC9A09:14C1086:5E429D5B + body: + encoding: UTF-8 + string: '' + http_version: '1.1' + adapter_metadata: + effective_url: https://github.com/ + recorded_at: Sat, 21 Oct 2017 11:00:00 GMT +recorded_with: VCR 2.9.3