1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
|
# frozen_string_literal: true
require "spec_helper"
describe "Cache" do
let(:cache_fixture_dir) { File.join(FIXTURES_DIR, "cache") }
let(:default_cache_options) { { storage_dir: cache_fixture_dir } }
let(:file_runner) { HTMLProofer.check_file(test_file, runner_options) }
let(:link_runner) { HTMLProofer.check_links(links, runner_options) }
let(:described_class) { HTMLProofer::Cache }
def read_cache(cache_filename)
JSON.parse(File.read(File.join(cache_fixture_dir, cache_filename)))
end
context "when parsing time" do
let(:links) { ["www.github.com"] }
let(:runner_options) { default_cache_options }
it "understands months" do
now_time = Time.local(2019, 9, 6, 12, 0, 0)
Timecop.freeze(now_time) do
cache = described_class.new(link_runner, timeframe: { external: "2M" })
check_time = Time.local(2019, 8, 6, 12, 0, 0).to_s
expect(cache.within_external_timeframe?(check_time)).to(be(true))
check_time = Time.local(2019, 5, 6, 12, 0, 0).to_s
expect(cache.within_external_timeframe?(check_time)).to(be(false))
end
end
it "understands days" do
now_time = Time.local(2019, 9, 6, 12, 0, 0)
Timecop.freeze(now_time) do
cache = described_class.new(link_runner, timeframe: { external: "2d" })
check_time = Time.local(2019, 9, 5, 12, 0, 0).to_s
expect(cache.within_external_timeframe?(check_time)).to(be(true))
check_time = Time.local(2019, 5, 6, 12, 0, 0).to_s
expect(cache.within_external_timeframe?(check_time)).to(be(false))
end
end
it "understands weeks" do
now_time = Time.local(2019, 9, 6, 12, 0, 0)
Timecop.freeze(now_time) do
cache = described_class.new(link_runner, timeframe: { external: "2w" })
check_time = Time.local(2019, 8, 30, 12, 0, 0).to_s
expect(cache.within_external_timeframe?(check_time)).to(be(true))
check_time = Time.local(2019, 5, 6, 12, 0, 0).to_s
expect(cache.within_external_timeframe?(check_time)).to(be(false))
end
end
it "understands hours" do
now_time = Time.local(2019, 9, 6, 12, 0, 0)
Timecop.freeze(now_time) do
cache = described_class.new(link_runner, timeframe: { external: "3h" })
check_time = Time.local(2019, 9, 6, 9, 0, 0).to_s
expect(cache.within_external_timeframe?(check_time)).to(be(true))
check_time = Time.local(2019, 5, 6, 12, 0, 0).to_s
expect(cache.within_external_timeframe?(check_time)).to(be(false))
end
end
it "fails on an invalid date" do
file = File.join(FIXTURES_DIR, "links", "broken_link_external.html")
expect do
run_proofer(file, :file, cache: { timeframe: { external: "30x" } }.merge(default_cache_options))
end.to(raise_error(ArgumentError))
end
end
context "with version 2" do
let(:version) { "version_2" }
it "knows how to write to cache" do
test_file = File.join(cache_fixture_dir, "internal_and_external_example.html")
cache_filename = File.join(version, ".htmlproofer_test.json")
cache_filepath = File.join(cache_fixture_dir, cache_filename)
File.delete(cache_filepath) if File.exist?(cache_filepath)
allow(described_class).to(receive(:write).once)
run_proofer(
test_file,
:file,
cache: { timeframe: { external: "30d", internal: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
log = read_cache(cache_filename)
expect(log.keys.length).to(eq(3))
# should look like:
# {
# "version": xxx,
# "internal": {
# "/": {
# "time": "2015-10-20 12:00:00 -0700",
# "found": false,
# "metadata": [...]
# }
# },
# "external": {
# "www.github.com": {
# "time": "2015-10-20 12:00:00 -0700",
# "status": 200,
# "message": "OK",
# "metadata": [...]
# }
# }
# }
expect(log["version"]).to(eq(2))
external_urls = log["external"]
external_url = external_urls["https://github.com/gjtorikian/html-proofer"]
expect(external_url["status_code"]).to(eq(200))
expect(external_url["metadata"].first["line"]).to(eq(7))
internal_urls = log["internal"]
internal_url = internal_urls["/somewhere.html"]
expect(internal_url["metadata"].first["line"]).to(eq(11))
expect(internal_url["metadata"].first["found"]).to(be(false))
File.delete(cache_filepath) if File.exist?(cache_filepath)
end
it "internal cache is disabled w/o internal timeframe" do
test_file = File.join(cache_fixture_dir, "internal_and_external_example.html")
cache_filename = File.join(version, ".htmlproofer_test.json")
cache_filepath = File.join(cache_fixture_dir, cache_filename)
allow(described_class).to(receive(:write).once)
expect_any_instance_of(HTMLProofer::Runner).not_to(receive(:load_internal_cache))
run_proofer(
test_file,
:file,
cache: { timeframe: { external: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
cache = read_cache(cache_filename)
expect(cache["external"].keys.length).to(eq(1))
expect(cache["internal"].keys.length).to(eq(0))
File.delete(cache_filepath) if File.exist?(cache_filepath)
end
it "external cache is disabled w/o external timeframe" do
test_file = File.join(cache_fixture_dir, "internal_and_external_example.html")
cache_filename = File.join(version, ".htmlproofer_test.json")
cache_filepath = File.join(cache_fixture_dir, cache_filename)
allow(described_class).to(receive(:write).once)
expect_any_instance_of(HTMLProofer::Runner).not_to(receive(:load_external_cache))
run_proofer(
test_file,
:file,
cache: { timeframe: { internal: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
cache = read_cache(cache_filename)
expect(cache["internal"].keys.length).to(eq(1))
expect(cache["external"].keys.length).to(eq(0))
File.delete(cache_filepath) if File.exist?(cache_filepath)
end
it "internal/external cache is disabled w/o internal/external timeframe" do
test_file = File.join(cache_fixture_dir, "internal_and_external_example.html")
cache_filename = File.join(version, ".htmlproofer_test.json")
cache_filepath = File.join(cache_fixture_dir, cache_filename)
allow(described_class).to(receive(:write).once)
expect_any_instance_of(HTMLProofer::Runner).not_to(receive(:load_internal_cache))
expect_any_instance_of(HTMLProofer::Runner).not_to(receive(:load_external_cache))
run_proofer(
test_file,
:file,
cache: { timeframe: {}, cache_file: cache_filename }.merge(default_cache_options),
)
cache = read_cache(cache_filename)
expect(cache["internal"].keys.length).to(eq(0))
expect(cache["external"].keys.length).to(eq(0))
File.delete(cache_filepath) if File.exist?(cache_filepath)
end
context "when checking external links and including dates" do
let(:cache_filename) { File.join(version, ".within_date_external.json") }
it "does not write file if timestamp is within date" do
new_time = Time.local(2015, 10, 27, 12, 0, 0)
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
# we expect no add since we are within the timeframe
expect_any_instance_of(described_class).not_to(receive(:add_external))
run_proofer(
["www.github.com"],
:links,
cache: { timeframe: { external: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
it "does write file if timestamp is not within date" do
new_time = Time.local(2021, 10, 27, 12, 0, 0)
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
# we expect an add since we are mocking outside the timeframe
expect_any_instance_of(described_class).to(receive(:add_external).with("www.github.com", [], 200, "OK", true))
run_proofer(
["www.github.com"],
:links,
cache: { timeframe: { external: "4d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
end
context "when checking external links and a new external url added" do
let(:cache_filename) { File.join(version, ".new_external_url.json") }
it "does write file if a new URL is added" do
new_time = Time.local(2015, 10, 20, 12, 0, 0)
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
# we expect one new link to be added, but github.com can stay...
expect_any_instance_of(described_class).to(receive(:add_external).with("www.google.com", [], 200, "OK", true))
# ...because it's within the 30d time frame
run_proofer(
["www.github.com", "www.google.com"],
:links,
cache: { timeframe: { external: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
it "handles slashed and unslashed URLs as the same" do
new_time = Time.local(2015, 10, 20, 12, 0, 0)
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
# we expect no new link to be added, because it's the same as the cache link (but with a `/`)
expect_any_instance_of(described_class).not_to(receive(:add_external))
run_proofer(
["www.github.com/"],
:links,
cache: { timeframe: { external: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
it "handles multiple slashed and unslashed URLs during additions/deletions" do
cache_filename = File.join(version, ".trailing_slashes.json")
cache_filepath = File.join(cache_fixture_dir, cache_filename)
test_file = File.join(FIXTURES_DIR, "cache", "trailing_slashes.html")
new_time = Time.local(2022, 1, 6, 12, 0, 0)
Timecop.freeze(new_time) do
File.delete(cache_filepath) if File.exist?(cache_filepath)
run_proofer(
test_file,
:file,
cache: { timeframe: { external: "1d" }, cache_file: cache_filename }.merge(default_cache_options),
)
cache = read_cache(cache_filename)
external_urls = cache["external"]
expect(external_urls.keys.sort).to(eq([
"https://github.com",
"https://github.com/gjtorikian",
"https://github.com/riccardoporreca",
"https://rubygems.org",
]))
# we expect no new links to be added, because it's the same as the cache link
expect_any_instance_of(described_class).not_to(receive(:add_external))
run_proofer(
test_file,
:file,
cache: { timeframe: { external: "1d" }, cache_file: cache_filename }.merge(default_cache_options),
)
cache = read_cache(cache_filename)
external_urls = cache["external"]
expect(external_urls.keys.sort).to(eq([
"https://github.com",
"https://github.com/gjtorikian",
"https://github.com/riccardoporreca",
"https://rubygems.org",
]))
File.delete(cache_filepath)
end
end
it "understands encodings even if it is unnormalized coming in" do
new_time = Time.local(2015, 10, 20, 12, 0, 0)
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
# we expect no new link to be added, because it's the same as the cache link
expect_any_instance_of(described_class).not_to(receive(:add_external))
run_proofer(
["github.com/search/issues?q=is%3Aopen+is%3Aissue+fig"],
:links,
cache: { timeframe: { external: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
it "saves unencoded as normalized in cache" do
cache_filename = File.join(version, ".some_other_external_url.json")
new_time = Time.local(2015, 10, 20, 12, 0, 0)
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
expect_any_instance_of(described_class).to(receive(:add_external))
allow_any_instance_of(described_class).to(receive(:cleaned_url).with("github.com/search?q=is%3Aclosed+is%3Aissue+words").and_return("github.com/search?q=is:closed+is:issue+words"))
run_proofer(
["github.com/search?q=is%3Aclosed+is%3Aissue+words"],
:links,
cache: { timeframe: { external: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
end
context "when checking internal links and including dates" do
let(:cache_filename) { File.join(version, ".within_date_internal.json") }
let(:test_file) { File.join(FIXTURES_DIR, "links", "working_root_link_internal.html") }
let(:new_time) { Time.local(2015, 10, 27, 12, 0, 0) }
it "does not write file if timestamp is within date" do
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
# we expect no add since we are within the timeframe
expect_any_instance_of(described_class).not_to(receive(:add_internal))
run_proofer(
test_file,
:file,
disable_external: true,
cache: { timeframe: { internal: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
it "does write file if timestamp is not within date" do
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
# we expect an add since we are mocking outside the timeframe
expect_any_instance_of(described_class).to(receive(:add_internal).with(
"/tel_link.html", hash_including(base_url: "", filename: "spec/html-proofer/fixtures/links/working_root_link_internal.html", found: false, line: 5, source: test_file), true
))
run_proofer(
test_file,
:file,
disable_external: true,
cache: { timeframe: { internal: "4d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
end
context "when checking internal links and new internal url added" do
let(:cache_filename) { File.join(version, ".new_internal_url.json") }
let(:cache_filepath) { File.join(cache_fixture_dir, cache_filename) }
# this is frozen to within 30 days of the log
let(:new_time) { Time.local(2015, 10, 20, 12, 0, 0) }
it "does write file if a new relative URL 200 is added" do
Timecop.freeze(new_time) do
root_link = File.join(FIXTURES_DIR, "links", "root_link", "root_link_with_another_link.html")
expect_any_instance_of(described_class).to(receive(:add_internal).with(
"/",
hash_including(base_url: "", filename: root_link, found: false, line: 5, source: root_link),
true,
).and_call_original)
expect_any_instance_of(described_class).to(receive(:write).once)
run_proofer(
root_link,
:file,
disable_external: true,
cache: { timeframe: { internal: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
it "does write file if a new relative URL 404 is added" do
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
root_link = File.join(FIXTURES_DIR, "links", "broken_internal_link.html")
expect_any_instance_of(described_class).to(receive(:add_internal).once.with(
"#noHash",
hash_including(base_url: "", filename: root_link, found: false, line: 5, source: root_link),
false,
))
run_proofer(
root_link,
:file,
disable_external: true,
cache: { timeframe: { internal: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
it "works if new broken internal file is added and cache is rechecked" do
cache_filename = File.join(version, ".recheck_internal.json")
cache_fullpath = File.join(FIXTURES_DIR, "cache", cache_filename)
test_path = File.join(FIXTURES_DIR, "cache", "existing")
subsite = File.join(FIXTURES_DIR, "cache", "existing", "broken")
Timecop.freeze(new_time) do
proofer = run_proofer(
test_path,
:directory,
disable_external: true,
cache: { timeframe: { internal: "1d" }, cache_file: cache_filename }.merge(default_cache_options),
)
expect(proofer.failed_checks).to(eq([]))
cache = read_cache(cache_filename)
internal_link = cache["internal"]["existing.html"]
internal_link_metadata = internal_link["metadata"]
index_metadata = internal_link_metadata.first
expect(index_metadata["filename"]).to(eq("spec/html-proofer/fixtures/cache/existing/index.html"))
expect(index_metadata["found"]).to(equal(true))
FileUtils.mkdir_p(subsite)
FileUtils.copy(File.join(test_path, "index.html"), File.join(subsite, "index.html"))
proofer = run_proofer(
test_path,
:directory,
disable_external: true,
cache: { timeframe: { internal: "1d" }, cache_file: cache_filename }.merge(default_cache_options),
)
expect(proofer.failed_checks.count).to(eq(1))
cache = read_cache(cache_filename)
internal_link = cache["internal"]["existing.html"]
internal_link_metadata = internal_link["metadata"]
expect(internal_link_metadata.count).to(eq(2))
first_cache_metadata = internal_link_metadata[0]
expect(first_cache_metadata["filename"]).to(eq("spec/html-proofer/fixtures/cache/existing/index.html"))
expect(first_cache_metadata["found"]).to(equal(true))
second_cache_metadata = internal_link_metadata[1]
expect(second_cache_metadata["filename"]).to(eq("spec/html-proofer/fixtures/cache/existing/broken/index.html"))
expect(second_cache_metadata["found"]).to(equal(false))
ensure # cleanup
FileUtils.rm_rf(subsite) if File.directory?(subsite)
FileUtils.rm_rf(cache_fullpath) if File.exist?(cache_fullpath)
end
end
end
context "when rechecking failures" do
let(:new_time) { Time.local(2022, 1, 6, 12, 0, 0) }
it "does recheck failures for newly valid links" do
Timecop.freeze(new_time) do
file = File.join(FIXTURES_DIR, "cache", "valid_link.html")
# link from file is broken in this cache
template = File.join(FIXTURES_DIR, "cache", version, ".broken_external_link.template")
cache_filename = File.join(version, ".broken_external_link.json")
cache_filepath = File.join(FIXTURES_DIR, "cache", cache_filename)
FileUtils.cp(template, cache_filepath)
cache = read_cache(cache_filename)
external_link = cache["external"]["https://github.com/gjtorikian/html-proofer"]
expect(external_link["found"]).to(equal(false))
expect(external_link["status_code"]).to(equal(0))
run_proofer(file, :file, cache: { timeframe: { external: "1d" }, cache_file: cache_filename }.merge(default_cache_options))
cache = read_cache(cache_filename)
external_link = cache["external"]["https://github.com/gjtorikian/html-proofer"]
expect(external_link["found"]).to(equal(true))
expect(external_link["status_code"]).to(equal(200))
expect(external_link["message"]).to(match("OK"))
File.delete(cache_filepath)
end
end
it "does recheck external failures, regardless of cache" do
Timecop.freeze(new_time) do
cache_filename = File.join(version, ".recheck_failure.json")
expect_any_instance_of(described_class).to(receive(:write))
# 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(described_class).to(receive(:add_external))
run_proofer(
["http://www.foofoofoo.biz"],
:links,
cache: { timeframe: { external: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
it "does recheck internal failures, regardless of cache" do
cache_filename = File.join(version, ".broken_internal.json")
test_path = File.join(FIXTURES_DIR, "cache", "example_site")
test_file = File.join(test_path, "index.html")
Timecop.freeze(new_time) do
expect_any_instance_of(described_class).to(receive(:write))
# we expect the same link to be re-added, even though we are within the time frame,
# because `index.html` contains a failure
expect_any_instance_of(described_class).to(receive(:add_internal).with(
"/missing.html",
hash_including(base_url: "", filename: test_file, found: false, line: 6, source: test_path),
false,
))
run_proofer(
test_path,
:directory,
disable_external: true,
cache: { timeframe: { internal: "30d" }, cache_file: cache_filename }.merge(default_cache_options),
)
end
end
it "does recheck failures, regardless of external-only cache" do
Timecop.freeze(new_time) do
cache_filename = File.join(version, ".recheck_external_failure.json")
cache_filepath = File.join(cache_fixture_dir, cache_filename)
file = File.join(FIXTURES_DIR, "cache", "external_example.html")
File.delete(cache_filepath) if File.exist?(cache_filepath)
run_proofer(file, :file, cache: { timeframe: { external: "1d" }, cache_file: cache_filename }.merge(default_cache_options))
cache = read_cache(cache_filename)
external_links = cache["external"]
expect(external_links.keys.first).to(eq("https://github.com/gjtorikian/html-proofer"))
run_proofer(file, :file, cache: { timeframe: { external: "1d" }, cache_file: cache_filename }.merge(default_cache_options))
cache = read_cache(cache_filename)
external_links = cache["external"]
expect(external_links.keys.first).to(eq("https://github.com/gjtorikian/html-proofer"))
end
end
it "does recheck failures, regardless of external and internal cache" do
cache_filename = File.join(version, ".internal_and_external.json")
cache_location = File.join(cache_fixture_dir, cache_filename)
file = File.join(FIXTURES_DIR, "cache", "internal_and_external_example.html")
Timecop.freeze(new_time) do
File.delete(cache_location) if File.exist?(cache_location)
run_proofer(file, :file, cache: { timeframe: { external: "1d", internal: "1d" }, cache_file: cache_filename }.merge(default_cache_options))
cache = read_cache(cache_filename)
external_links = cache["external"]
expect(external_links.keys.first).to(eq("https://github.com/gjtorikian/html-proofer"))
expect(external_links["https://github.com/gjtorikian/html-proofer"]["metadata"].count).to(eq(1))
internal_links = cache["internal"]
expect(internal_links.keys.first).to(eq("/somewhere.html"))
expect(internal_links["/somewhere.html"]["metadata"].count).to(eq(1))
run_proofer(file, :file, cache: { timeframe: { external: "1d", internal: "1d" }, cache_file: cache_filename }.merge(default_cache_options))
cache = read_cache(cache_filename)
external_links = cache["external"]
expect(external_links.keys.first).to(eq("https://github.com/gjtorikian/html-proofer"))
expect(external_links["https://github.com/gjtorikian/html-proofer"]["metadata"].count).to(eq(1))
internal_links = cache["internal"]
expect(internal_links.keys.first).to(eq("/somewhere.html"))
expect(internal_links["/somewhere.html"]["metadata"].count).to(eq(1))
end
end
end
context "when removing links" do
let(:new_time) { Time.local(2022, 1, 6, 12, 0, 0) }
it "removes external links that no longer exist" do
Timecop.freeze(new_time) do
test_file = File.join(FIXTURES_DIR, "cache", "external_example.html")
cache_filename = File.join(version, ".removed_link.json")
cache_location = File.join(cache_fixture_dir, cache_filename)
File.delete(cache_location) if File.exist?(cache_location)
run_proofer(
test_file,
:file,
cache: { timeframe: { external: "1d" }, cache_file: cache_filename }.merge(default_cache_options),
)
cache = read_cache(cache_filename)
external_links = cache["external"]
expect(external_links.keys.first).to(eq("https://github.com/gjtorikian/html-proofer"))
run_proofer(
File.join(FIXTURES_DIR, "cache", "some_link.html"),
:file,
cache: { timeframe: { external: "1d" }, cache_file: cache_filename }.merge(default_cache_options),
)
cache = read_cache(cache_filename)
external_links = cache["external"]
expect(external_links.keys.first).to(eq("https://github.com/gjtorikian"))
end
end
end
end
end
|