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
|