|
| 1 | +# typed: false |
| 2 | +# frozen_string_literal: true |
| 3 | + |
| 4 | +RSpec.describe QueryPackwerk::Packages do |
| 5 | + include_context 'pseudo packs' |
| 6 | + |
| 7 | + describe '#where' do |
| 8 | + it 'can query packages' do |
| 9 | + packages = described_class.where(owner: QueryPackwerk::Packages::UNOWNED) |
| 10 | + expect(packages).to be_a(described_class) |
| 11 | + expect(packages.map(&:owner).uniq).to eq([QueryPackwerk::Packages::UNOWNED]) |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + describe '#empty? and #any?' do |
| 16 | + it 'returns true for empty? when there are no packages' do |
| 17 | + empty_packages = described_class.new([]) |
| 18 | + expect(empty_packages.empty?).to be true |
| 19 | + expect(empty_packages.any?).to be false |
| 20 | + end |
| 21 | + |
| 22 | + it 'returns false for empty? when there are packages' do |
| 23 | + expect(described_class.all.empty?).to be false |
| 24 | + expect(described_class.all.any?).to be true |
| 25 | + end |
| 26 | + |
| 27 | + it 'supports any? with a block' do |
| 28 | + packages = described_class.all |
| 29 | + expect(packages.any? { |p| p.owner == QueryPackwerk::Packages::UNOWNED }).to be true |
| 30 | + expect(packages.any? { |p| p.name == 'nonexistent' }).to be false |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + describe '#violations' do |
| 35 | + it 'returns violations for all packages in the collection' do |
| 36 | + packages = described_class.all |
| 37 | + violations = packages.violations |
| 38 | + expect(violations).to be_a(QueryPackwerk::Violations) |
| 39 | + expect(violations.count).to be > 0 |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + describe '#inspect' do |
| 44 | + it 'returns a string representation of an empty collection' do |
| 45 | + packages = described_class.new([]) |
| 46 | + expect(packages.inspect).to eq("#<#{described_class.name} []>") |
| 47 | + end |
| 48 | + |
| 49 | + it 'returns a string representation of the packages' do |
| 50 | + packages = described_class.all |
| 51 | + expect(packages.inspect).to eq("#<#{described_class.name} [\n#{described_class.all.map(&:inspect).join("\n")}\n]>") |
| 52 | + end |
| 53 | + end |
| 54 | +end |
0 commit comments