File: runner_spec.rb

package info (click to toggle)
ruby-html-proofer 5.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,524 kB
  • sloc: ruby: 4,389; sh: 8; makefile: 4; javascript: 1; php: 1
file content (64 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download
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
# frozen_string_literal: true

require "spec_helper"

describe "Runner" do
  describe "#before_request" do
    it "sends authorization header to github.com" do
      skip 'VCR not available'
      opts = {}
      url = "https://github.com"
      proofer = make_proofer([url], :links, opts)
      request = nil
      auth = "Bearer <TOKEN>"
      proofer.before_request do |r|
        r.options[:headers]["Authorization"] = auth if r.base_url == url
        request = r
      end

      cassette_name = make_cassette_name(File.join(FIXTURES_DIR, "links", "check_just_once.html"), opts)
      VCR.use_cassette(cassette_name, record: :new_episodes) do
        capture_stderr { proofer.run }
        proofer
      end

      expect(request).to(respond_to(:options))
      expect(request.options).to(include(:headers))
      expect(request.options[:headers]).to(include("Authorization" => auth))
    end

    it "plays nice with cache" do
      skip 'VCR not available'
      cache_file_name = ".runner.json"
      storage_dir = File.join(FIXTURES_DIR, "cache", "version_2")
      cache_location = File.join(storage_dir, cache_file_name)

      File.delete(cache_location) if File.exist?(cache_location)

      now_time = Time.local(2022, 2, 17, 12, 0, 0)
      Timecop.freeze(now_time) do
        opts = {
          cache: { timeframe: { external: "1d" }, cache_file: cache_file_name, storage_dir: storage_dir },
        }
        dir = File.join(FIXTURES_DIR, "links", "_site")
        proofer = make_proofer(dir, :directory, opts)
        request = nil
        auth = "Bearer <TOKEN>"
        proofer.before_request do |r|
          r.options[:headers]["Authorization"] = auth
          request = r
        end

        cassette_name = make_cassette_name(dir, opts)
        VCR.use_cassette(cassette_name, record: :new_episodes) do
          capture_stderr { proofer.run }
          proofer
        end

        expect(request).to(respond_to(:options))
        expect(request.options).to(include(:headers))
        expect(request.options[:headers]).to(include("Authorization" => auth))
      end
    end
  end
end