summaryrefslogtreecommitdiff
path: root/spec/unit/dotnet
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-03-09 16:50:35 -0600
committermo khan <mo.khan@gmail.com>2020-03-09 16:50:35 -0600
commite3d6a1bc45ff57a1003b9ed4ca5d9808ce42d513 (patch)
treea1b719618bbd5e9bd34c9a118edd591beade8ad8 /spec/unit/dotnet
parent892b8483b1272c7f43d7914327082cfed068f729 (diff)
Fix linter errors
Diffstat (limited to 'spec/unit/dotnet')
-rw-r--r--spec/unit/dotnet/index_spec.rb4
-rw-r--r--spec/unit/dotnet/nuget_gateway_spec.rb36
2 files changed, 24 insertions, 16 deletions
diff --git a/spec/unit/dotnet/index_spec.rb b/spec/unit/dotnet/index_spec.rb
index 32e9a90..29f3b65 100644
--- a/spec/unit/dotnet/index_spec.rb
+++ b/spec/unit/dotnet/index_spec.rb
@@ -15,8 +15,8 @@ RSpec.describe Spandx::Dotnet::Index do
before do
allow(Spandx::Dotnet::NugetGateway).to receive(:new).and_return(gateway)
- allow(gateway).to receive(:each)
- .and_yield('id' => 'Polaroider', 'version' => '0.2.0', 'licenseExpression' => 'MIT')
+ item = { 'id' => 'Polaroider', 'version' => '0.2.0', 'licenseExpression' => 'MIT' }
+ allow(gateway).to receive(:each).and_yield(item, 0)
subject.update!(catalogue: catalogue)
end
diff --git a/spec/unit/dotnet/nuget_gateway_spec.rb b/spec/unit/dotnet/nuget_gateway_spec.rb
index 46e0060..e647abe 100644
--- a/spec/unit/dotnet/nuget_gateway_spec.rb
+++ b/spec/unit/dotnet/nuget_gateway_spec.rb
@@ -18,8 +18,8 @@ RSpec.describe Spandx::Dotnet::NugetGateway do
pending 'when the package specifies the license using a url'
end
- describe "#each" do
- context "when iterating through every package" do
+ describe '#each' do
+ context 'when iterating through every package' do
let(:total_pages) { 10 }
before do
@@ -30,15 +30,16 @@ RSpec.describe Spandx::Dotnet::NugetGateway do
}
end
- stub_request(:get, "https://api.nuget.org/v3/catalog0/index.json")
+ stub_request(:get, 'https://api.nuget.org/v3/catalog0/index.json')
.and_return(status: 200, body: JSON.generate({ items: pages }))
total_pages.times do |i|
+ items = {
+ '@id' => "https://api.nuget.org/v3/catalog0/page#{i}.json",
+ items: [{ '@id' => "https://api.nuget.org/v3/catalog0/data/2020.01.01.00.00.00/spandx.0.1.#{i}.json" }]
+ }
stub_request(:get, "https://api.nuget.org/v3/catalog0/page#{i}.json")
- .and_return(status: 200, body: JSON.generate({
- '@id' => "https://api.nuget.org/v3/catalog0/page#{i}.json",
- items: [{ '@id' => "https://api.nuget.org/v3/catalog0/data/2020.01.01.00.00.00/spandx.0.1.#{i}.json" }]
- }))
+ .and_return(status: 200, body: JSON.generate(items))
stub_request(:get, "https://api.nuget.org/v3/catalog0/data/2020.01.01.00.00.00/spandx.0.1.#{i}.json")
.and_return(status: 200, body: JSON.generate({ id: 'spandx', version: "0.1.#{i}", licenseExpression: 'MIT' }))
@@ -58,23 +59,30 @@ RSpec.describe Spandx::Dotnet::NugetGateway do
subject.each do |item, _page|
collection << item
end
- expect(collection).to match_array(total_pages.times.map { |i| {"id"=>"spandx", "licenseExpression"=>"MIT", "version"=>"0.1.#{i}"} })
+ expect(collection).to match_array(total_pages.times.map { |i| { 'id' => 'spandx', 'licenseExpression' => 'MIT', 'version' => "0.1.#{i}" } })
end
end
- context "when iterating through packages starting from a specific page" do
- it 'fetches each item starting from a specific page' do
- called = false
+ context 'when iterating through packages starting from a specific page' do
+ let(:expected_pages) { [0, 1] }
+ def play
VCR.use_cassette('nuget-catalogue-from-page-1') do
- subject.each(page: 1) do |item, page|
- called = true
- expect([0, 1]).to include(page)
+ subject.each(page: expected_pages.max) do |item, page|
+ yield item, page
end
end
+ end
+ it 'yields each items back' do
+ called = false
+ play { called = true }
expect(called).to be(true)
end
+
+ it 'fetches each item starting from a specific page' do
+ play { |_item, page| expect(expected_pages).to include(page) }
+ end
end
end
end