|
7 | 7 |
|
8 | 8 | subject { described_class.new(directory) } |
9 | 9 |
|
| 10 | + describe "#initialize" do |
| 11 | + context "when given no arguments" do |
| 12 | + subject { described_class } |
| 13 | + |
| 14 | + context "when a Gemfile.lock exists in Dir.pwd" do |
| 15 | + it "must default root to Dir.pwd" do |
| 16 | + Dir.chdir(directory) do |
| 17 | + scanner = subject.new |
| 18 | + expect(scanner.root).to eq(File.expand_path(Dir.pwd)) |
| 19 | + end |
| 20 | + end |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + context "when given a root directory" do |
| 25 | + let(:root) { directory } |
| 26 | + |
| 27 | + subject { described_class.new(root) } |
| 28 | + |
| 29 | + it "must set #root to the expanded directory path" do |
| 30 | + expect(subject.root).to eq(File.expand_path(root)) |
| 31 | + end |
| 32 | + |
| 33 | + it "must set #database" do |
| 34 | + expect(subject.database).to be_kind_of(Database) |
| 35 | + end |
| 36 | + |
| 37 | + it "must set #lockfile by parsing the Gemfile.lock" do |
| 38 | + expect(subject.lockfile).to be_kind_of(Bundler::LockfileParser) |
| 39 | + end |
| 40 | + |
| 41 | + it "must set #config to a default Configuration when no config file exists" do |
| 42 | + expect(subject.config).to be_kind_of(Configuration) |
| 43 | + expect(subject.config.ignore).to be_empty |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context "when the Gemfile.lock does not exist in the root directory" do |
| 48 | + let(:bad_dir) { File.join('spec','bundle','nonexistent') } |
| 49 | + |
| 50 | + it "must raise Bundler::GemfileLockNotFound" do |
| 51 | + expect { |
| 52 | + described_class.new(bad_dir) |
| 53 | + }.to raise_error(Bundler::GemfileLockNotFound) |
| 54 | + end |
| 55 | + |
| 56 | + it "must include the lock file name and root in the error message" do |
| 57 | + expect { |
| 58 | + described_class.new(bad_dir) |
| 59 | + }.to raise_error(Bundler::GemfileLockNotFound, /Gemfile\.lock/) |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + context "when given a custom gemfile_lock name" do |
| 64 | + it "must raise Bundler::GemfileLockNotFound if the custom lock file does not exist" do |
| 65 | + expect { |
| 66 | + described_class.new(directory, 'NoSuchLockFile.lock') |
| 67 | + }.to raise_error(Bundler::GemfileLockNotFound) |
| 68 | + end |
| 69 | + |
| 70 | + it "must use the custom gemfile_lock name" do |
| 71 | + scanner = described_class.new(directory, 'Gemfile.lock') |
| 72 | + expect(scanner.lockfile).to be_kind_of(Bundler::LockfileParser) |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + context "when given a custom database" do |
| 77 | + let(:custom_db) { Database.new } |
| 78 | + |
| 79 | + subject { described_class.new(directory, 'Gemfile.lock', custom_db) } |
| 80 | + |
| 81 | + it "must set #database to the custom database" do |
| 82 | + expect(subject.database).to be(custom_db) |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + context "when a .bundler-audit.yml config file exists" do |
| 87 | + let(:bundle) { 'unpatched_gems_with_dot_configuration' } |
| 88 | + |
| 89 | + subject { described_class.new(directory) } |
| 90 | + |
| 91 | + it "must load the configuration from the config file" do |
| 92 | + expect(subject.config).to be_kind_of(Configuration) |
| 93 | + expect(subject.config.ignore).to include('OSVDB-89025') |
| 94 | + end |
| 95 | + end |
| 96 | + |
| 97 | + context "when given a custom config_dot_file" do |
| 98 | + let(:config_path) { File.join('spec','bundle','unpatched_gems_with_dot_configuration','.bundler-audit.yml') } |
| 99 | + |
| 100 | + context "when the config_dot_file is an absolute path" do |
| 101 | + let(:absolute_config_path) { File.absolute_path(config_path) } |
| 102 | + |
| 103 | + subject { described_class.new(directory, 'Gemfile.lock', Database.new, absolute_config_path) } |
| 104 | + |
| 105 | + it "must load the configuration from the absolute path" do |
| 106 | + expect(subject.config).to be_kind_of(Configuration) |
| 107 | + expect(subject.config.ignore).to include('OSVDB-89025') |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + context "when the config_dot_file is a relative path" do |
| 112 | + let(:relative_config_path) { File.join('..','unpatched_gems_with_dot_configuration','.bundler-audit.yml') } |
| 113 | + |
| 114 | + subject { described_class.new(directory, 'Gemfile.lock', Database.new, relative_config_path) } |
| 115 | + |
| 116 | + it "must load the configuration from the relative path" do |
| 117 | + expect(subject.config).to be_kind_of(Configuration) |
| 118 | + expect(subject.config.ignore).to include('OSVDB-89025') |
| 119 | + end |
| 120 | + end |
| 121 | + end |
| 122 | + |
| 123 | + context "when no .bundler-audit.yml config file exists" do |
| 124 | + let(:bundle) { 'secure' } |
| 125 | + |
| 126 | + subject { described_class.new(directory) } |
| 127 | + |
| 128 | + it "must set #config to a default empty Configuration" do |
| 129 | + expect(subject.config).to be_kind_of(Configuration) |
| 130 | + expect(subject.config.ignore).to be_empty |
| 131 | + end |
| 132 | + end |
| 133 | + end |
| 134 | + |
10 | 135 | describe "#scan" do |
11 | 136 | it "should yield results" do |
12 | 137 | results = [] |
|
0 commit comments