File: last_run_spec.rb

package info (click to toggle)
ruby-simplecov 0.22.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,500 kB
  • sloc: ruby: 5,550; makefile: 10
file content (48 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

require "helper"

describe SimpleCov::LastRun do
  subject { SimpleCov::LastRun }

  it "defines a last_run_path" do
    expect(subject.last_run_path).to include "tmp/coverage/.last_run.json"
  end

  it "writes json to its last_run_path that can be parsed again" do
    structure = [{"key" => "value"}]
    subject.write(structure)
    file_contents = File.read(subject.last_run_path)
    expect(JSON.parse(file_contents)).to eq structure
  end

  context "reading" do
    context "but the last_run file does not exist" do
      before { File.delete(subject.last_run_path) if File.exist?(subject.last_run_path) }

      it "returns nil" do
        expect(subject.read).to be_nil
      end
    end

    context "a non empty result" do
      before { subject.write([]) }

      it "reads json from its last_run_path" do
        expect(subject.read).to eq([])
      end
    end

    context "an empty result" do
      before do
        File.open(subject.last_run_path, "w+") do |f|
          f.puts ""
        end
      end

      it "returns nil" do
        expect(subject.read).to be_nil
      end
    end
  end
end