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
|
require "librarian/helpers"
require "librarian/lockfile/parser"
require "librarian/mock"
module Librarian
describe Lockfile::Parser do
let(:env) { Mock::Environment.new }
let(:parser) { described_class.new(env) }
let(:resolution) { parser.parse(lockfile) }
context "a mock lockfile with one source and no dependencies" do
let(:lockfile) do
Helpers.strip_heredoc <<-LOCKFILE
MOCK
remote: source-a
specs:
DEPENDENCIES
LOCKFILE
end
it "should give an empty list of dependencies" do
expect(resolution.dependencies).to be_empty
end
it "should give an empty list of manifests" do
expect(resolution.manifests).to be_empty
end
end
context "a mock lockfile with one source and one dependency" do
let(:lockfile) do
Helpers.strip_heredoc <<-LOCKFILE
MOCK
remote: source-a
specs:
jelly (1.3.5)
DEPENDENCIES
jelly (!= 1.2.6, ~> 1.1)
LOCKFILE
end
it "should give a list of one dependency" do
expect(resolution.dependencies.size).to eq 1
end
it "should give a dependency with the expected name" do
dependency = resolution.dependencies.first
expect(dependency.name).to eq "jelly"
end
it "should give a dependency with the expected requirement" do
dependency = resolution.dependencies.first
expect(dependency.requirement).to eq Librarian::Dependency::Requirement.new(["~> 1.1", "!= 1.2.6"])
end
it "should give a dependency wth the expected source" do
dependency = resolution.dependencies.first
source = dependency.source
expect(source.name).to eq "source-a"
end
it "should give a list of one manifest" do
expect(resolution.manifests.size).to eq 1
end
it "should give a manifest with the expected name" do
manifest = resolution.manifests.first
expect(manifest.name).to eq "jelly"
end
it "should give a manifest with the expected version" do
manifest = resolution.manifests.first
expect(manifest.version.to_s).to eq "1.3.5"
end
it "should give a manifest with no dependencies" do
manifest = resolution.manifests.first
expect(manifest.dependencies).to be_empty
end
it "should give a manifest with the expected source" do
manifest = resolution.manifests.first
source = manifest.source
expect(source.name).to eq "source-a"
end
it "should give the dependency and the manifest the same source instance" do
dependency = resolution.dependencies.first
manifest = resolution.manifests.first
dependency_source = dependency.source
manifest_source = manifest.source
expect(manifest_source).to be dependency_source
end
end
context "a mock lockfile with one source and a complex dependency" do
let(:lockfile) do
Helpers.strip_heredoc <<-LOCKFILE
MOCK
remote: source-a
specs:
butter (2.5.3)
jelly (1.3.5)
butter (< 3, >= 1.1)
DEPENDENCIES
jelly (!= 1.2.6, ~> 1.1)
LOCKFILE
end
it "should give a list of one dependency" do
expect(resolution.dependencies.size).to eq 1
end
it "should have the expected dependency" do
dependency = resolution.dependencies.first
expect(dependency.name).to eq "jelly"
end
it "should give a list of all the manifests" do
expect(resolution.manifests.size).to eq 2
end
it "should include all the expected manifests" do
manifests = ManifestSet.new(resolution.manifests)
expect(manifests.to_hash.keys).to match_array( %w(butter jelly) )
end
it "should have an internally consistent set of manifests" do
manifests = ManifestSet.new(resolution.manifests)
expect(manifests).to be_consistent
end
it "should have an externally consistent set of manifests" do
dependencies = resolution.dependencies
manifests = ManifestSet.new(resolution.manifests)
expect(manifests).to be_in_compliance_with dependencies
end
end
end
end
|