summaryrefslogtreecommitdiff
path: root/spec/unit/dotnet
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-22 09:28:44 -0600
committermo khan <mo.khan@gmail.com>2020-05-25 18:31:06 -0600
commit1ca2a951d05480759af1668ed586793ff5d36a26 (patch)
treeca16267ec26b1d8c3b1a1346a1ab9e8689992116 /spec/unit/dotnet
parentf8092c7f0ad26d04c8137b3b7d4faea5508a53ce (diff)
Convert from using string paths to using Pathname
* Extract a ./bin/run script * Extract defintion for NEWLINE * Add specs for matching yarn.lock * Add specs for Report * Convert package_manager to pathname * Display path in report * matches? to match?
Diffstat (limited to 'spec/unit/dotnet')
-rw-r--r--spec/unit/dotnet/parsers/csproj_spec.rb44
-rw-r--r--spec/unit/dotnet/parsers/packages_config_spec.rb20
-rw-r--r--spec/unit/dotnet/parsers/sln_spec.rb30
3 files changed, 54 insertions, 40 deletions
diff --git a/spec/unit/dotnet/parsers/csproj_spec.rb b/spec/unit/dotnet/parsers/csproj_spec.rb
index c377f8c..940b6c8 100644
--- a/spec/unit/dotnet/parsers/csproj_spec.rb
+++ b/spec/unit/dotnet/parsers/csproj_spec.rb
@@ -1,43 +1,43 @@
# frozen_string_literal: true
RSpec.describe Spandx::Dotnet::Parsers::Csproj do
- subject { described_class.new }
+ subject(:described_instance) { described_class.new }
+
+ def build(name, version, path)
+ Spandx::Core::Dependency.new(name: name, version: version, path: path)
+ end
describe '#parse' do
context 'when parsing a .csproj file' do
- let(:lockfile) { fixture_file('nuget/example.csproj') }
+ subject { described_instance.parse(file) }
+
+ let(:file) { fixture_file('nuget/example.csproj') }
- let(:because) { subject.parse(lockfile) }
- let(:jive) { because.find { |item| item.name == 'jive' } }
+ let(:jive) { subject.find { |item| item.name == 'jive' } }
- specify { expect(jive.name).to eql('jive') }
- specify { expect(jive.version).to eql('0.1.0') }
+ specify { expect(subject).to match_array([build('jive', '0.1.0', file)]) }
end
context 'when parsing a .csproj file that has a reference to another project' do
- let(:lockfile) { fixture_file('nuget/nested/test.csproj') }
+ subject { described_instance.parse(fixture_file('nuget/nested/test.csproj')) }
- let(:because) { subject.parse(lockfile) }
-
- specify { expect(because.map(&:name)).to match_array(%w[jive xunit]) }
+ specify { expect(subject.map(&:name)).to match_array(%w[jive xunit]) }
end
context 'when parsing `Nancy.Hosting.Self.csproj`' do
- let(:lockfile) { fixture_file('nuget/Nancy.Hosting.Self.csproj') }
-
- let(:because) { subject.parse(lockfile) }
+ subject { described_instance.parse(fixture_file('nuget/Nancy.Hosting.Self.csproj')) }
- specify { expect(because.count).to be(1) }
- specify { expect(because[0].name).to eql('System.Security.Principal.Windows') }
- specify { expect(because[0].version).to eql('4.3.0') }
+ specify { expect(subject.count).to be(1) }
+ specify { expect(subject[0].name).to eql('System.Security.Principal.Windows') }
+ specify { expect(subject[0].version).to eql('4.3.0') }
end
end
- describe '.matches?' do
- specify { expect(subject.matches?('/root/simple.csproj')).to be(true) }
- specify { expect(subject.matches?('C:\Documents and Settings\simple.csproj')).to be(true) }
- specify { expect(subject.matches?('C:\Documents and Settings\hello world.csproj')).to be(true) }
- specify { expect(subject.matches?('/root/Packages.props')).to be(true) }
- specify { expect(subject.matches?('/root/simple.sln')).to be(false) }
+ describe '#match?' do
+ specify { is_expected.to be_match(to_path('/root/Packages.props')) }
+ specify { is_expected.to be_match(to_path('/root/simple.csproj')) }
+ specify { is_expected.not_to be_match(to_path('/root/simple.sln')) }
+ specify { is_expected.to be_match(to_path('C:\Documents and Settings\hello world.csproj')) }
+ specify { is_expected.to be_match(to_path('C:\Documents and Settings\simple.csproj')) }
end
end
diff --git a/spec/unit/dotnet/parsers/packages_config_spec.rb b/spec/unit/dotnet/parsers/packages_config_spec.rb
index ef13bc6..7e1a23b 100644
--- a/spec/unit/dotnet/parsers/packages_config_spec.rb
+++ b/spec/unit/dotnet/parsers/packages_config_spec.rb
@@ -1,20 +1,24 @@
# frozen_string_literal: true
RSpec.describe Spandx::Dotnet::Parsers::PackagesConfig do
- subject { described_class.new }
+ let(:described_instance) { described_class.new }
describe '#parse' do
context 'when parsing a Gemfile with a single dependency' do
- let(:lockfile) { fixture_file('nuget/packages.config') }
- let(:because) { subject.parse(lockfile) }
- let(:nhibernate) { because.find { |item| item.name == 'NHibernate' } }
+ subject { described_instance.parse(fixture_file('nuget/packages.config')) }
+
+ let(:nhibernate) { subject.find { |item| item.name == 'NHibernate' } }
specify { expect(nhibernate.name).to eql('NHibernate') }
specify { expect(nhibernate.version).to eql('5.2.6') }
- pending { expect(because.map(&:name)).to include('Antlr3.Runtime') }
- pending { expect(because.map(&:name)).to include('Iesi.Collections') }
- pending { expect(because.map(&:name)).to include('Remotion.Linq') }
- pending { expect(because.map(&:name)).to include('Remotion.Linq.EagerFetching') }
+ pending { expect(subject.map(&:name)).to match_array(['Antlr3.Runtime', 'Iesi.Collections', 'NHibernate', 'Remotion.Linq', 'Remotion.Linq.EagerFetching']) }
end
end
+
+ describe '#match?' do
+ it { is_expected.not_to be_match(to_path('/root/not-packages.config')) }
+ it { is_expected.not_to be_match(to_path('/root/simple.sln')) }
+ it { is_expected.to be_match(to_path('/root/packages.config')) }
+ it { is_expected.to be_match(to_path('./packages.config')) }
+ end
end
diff --git a/spec/unit/dotnet/parsers/sln_spec.rb b/spec/unit/dotnet/parsers/sln_spec.rb
index 41b9981..50b86d7 100644
--- a/spec/unit/dotnet/parsers/sln_spec.rb
+++ b/spec/unit/dotnet/parsers/sln_spec.rb
@@ -1,25 +1,35 @@
# frozen_string_literal: true
RSpec.describe Spandx::Dotnet::Parsers::Sln do
- subject { described_class.new }
+ def build(name, version, path)
+ Spandx::Core::Dependency.new(name: name, version: version, path: path)
+ end
describe '#parse' do
context 'when parsing a sln file without any project references' do
- let(:sln) { fixture_file('nuget/empty.sln') }
-
- specify { expect(subject.parse(sln)).to be_empty }
+ specify { expect(subject.parse(fixture_file('nuget/empty.sln'))).to be_empty }
end
context 'when parsing a sln file with a single project reference' do
- let(:sln) { fixture_file('nuget/single.sln') }
- let(:because) { subject.parse(sln) }
+ subject { described_class.new.parse(path) }
+
+ let(:path) { fixture_file('nuget/single.sln') }
+ let(:csproj_path) { path.parent.join('nested/test.csproj') }
- specify { expect(because.map(&:name)).to match_array(%w[jive xunit]) }
+ specify do
+ expect(subject).to match_array([
+ build('jive', '0.1.0', csproj_path),
+ build('xunit', '2.4.0', csproj_path)
+ ])
+ end
end
end
- describe '.matches?' do
- specify { expect(subject.matches?('/root/example.sln')).to be(true) }
- specify { expect(subject.matches?('C:\development\hello world.sln')).to be(true) }
+ describe '#match?' do
+ it { is_expected.to be_match(to_path('example.sln')) }
+ it { is_expected.to be_match(to_path('./example.sln')) }
+ it { is_expected.to be_match(to_path('/root/example.sln')) }
+ it { is_expected.to be_match(to_path('C:\development\hello world.sln')) }
+ it { is_expected.not_to be_match(to_path('/root/not.sln.csproj')) }
end
end