File: cache_spec.rb

package info (click to toggle)
ruby-jekyll-include-cache 0.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 188 kB
  • sloc: ruby: 267; sh: 5; makefile: 4
file content (57 lines) | stat: -rw-r--r-- 1,263 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
# frozen_string_literal: true

RSpec.describe JekyllIncludeCache::Cache do
  before { subject["foo"] = "bar" }

  it "sets" do
    subject["foo2"] = "bar2"
    cache = subject.instance_variable_get("@cache")
    expect(cache["foo2"]).to eql("bar2")
  end

  it "gets" do
    expect(subject["foo"]).to eql("bar")
  end

  it "raises when a key doesn't exist" do
    expect { subject["doesnt_exist"] }.to raise_error(RuntimeError)
  end

  it "knows if a key exists" do
    expect(subject.key?("foo")).to be_truthy
    expect(subject.key?("bar")).to be_falsy
  end

  it "deletes" do
    subject["foo2"] = "bar2"
    expect(subject.key?("foo2")).to be_truthy
    subject.delete("foo2")
    expect(subject.key?("foo2")).to be_falsy
  end

  it "clears" do
    expect(subject.key?("foo")).to be_truthy
    subject.clear
    cache = subject.instance_variable_get("@cache")
    expect(cache).to eql({})
  end

  context "getset" do
    it "returns an existing value" do
      value = subject.getset "foo" do
        "bar2"
      end

      expect(value).to eql("bar")
    end

    it "sets a new value" do
      value = subject.getset "foo3" do
        "bar3"
      end

      expect(value).to eql("bar3")
      expect(subject["foo3"]).to eql("bar3")
    end
  end
end