|
3 | 3 | require 'ronin/wordlists/exceptions'
|
4 | 4 |
|
5 | 5 | describe Ronin::Wordlists::SearchPaths do
|
6 |
| - subject { described_class.new([path]) } |
| 6 | + subject { described_class.new([path1, path2]) } |
7 | 7 |
|
8 |
| - let(:path) { File.expand_path(File.join(__dir__, '..', 'spec', 'fixtures', 'wordlists')) } |
9 |
| - let(:wordlist_dir) { Ronin::Wordlists::WordlistDir.new(path) } |
| 8 | + let(:path1) { File.expand_path(File.join(__dir__, '..', 'spec', 'fixtures', 'wordlists')) } |
| 9 | + let(:path2) { File.expand_path(File.join(__dir__, '..', 'spec', 'fixtures', 'extra_wordlists')) } |
10 | 10 |
|
11 | 11 | describe "#initialize" do
|
12 | 12 | it "must initialize #paths and call #<< for each one" do
|
13 |
| - expect(subject.paths[0]).to be_kind_of(Ronin::Wordlists::WordlistDir) |
14 |
| - expect(subject.paths[0].path).to eq(path) |
| 13 | + expect(subject.paths).to all(be_kind_of(Ronin::Wordlists::WordlistDir)) |
| 14 | + expect(subject.paths.map(&:path).sort).to eq([path2, path1]) |
15 | 15 | end
|
16 | 16 | end
|
17 | 17 |
|
18 | 18 | describe ".[]" do
|
19 |
| - it "must initialize SearchPaths instance" do |
20 |
| - expect(described_class[path]).to be_kind_of(Ronin::Wordlists::SearchPaths) |
21 |
| - expect(described_class[path].paths[0].path).to eq(path) |
| 19 | + context "for single path" do |
| 20 | + subject { described_class[path1] } |
| 21 | + |
| 22 | + it "must initialize SearchPaths instance" do |
| 23 | + expect(subject).to be_kind_of(Ronin::Wordlists::SearchPaths) |
| 24 | + expect(subject.paths.map(&:path)).to eq([path1]) |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + context "for multiple paths" do |
| 29 | + subject { described_class[path1, path2] } |
| 30 | + |
| 31 | + it "must initialize SearchPaths instance" do |
| 32 | + expect(subject).to be_kind_of(Ronin::Wordlists::SearchPaths) |
| 33 | + expect(subject.paths.map(&:path)).to eq([path2, path1]) |
| 34 | + end |
22 | 35 | end
|
23 | 36 | end
|
24 | 37 |
|
25 | 38 | describe "#each" do
|
26 |
| - let(:example_block) { proc { p "test" } } |
| 39 | + let(:wordlist_dirs) { [Ronin::Wordlists::WordlistDir.new(path2), Ronin::Wordlists::WordlistDir.new(path1)] } |
27 | 40 |
|
28 | 41 | it "must iterate over #paths and yield each directory" do
|
29 | 42 | yielded_values = []
|
| 43 | + |
30 | 44 | subject.each do |value|
|
31 | 45 | yielded_values << value
|
32 | 46 | end
|
33 | 47 |
|
34 |
| - expect(yielded_values[0].path).to eq(wordlist_dir.path) |
| 48 | + expect(yielded_values.size).to eq(2) |
| 49 | + expect(yielded_values.map(&:path)).to eq(wordlist_dirs.map(&:path)) |
35 | 50 | end
|
36 | 51 | end
|
37 | 52 |
|
38 | 53 | describe "#<<" do
|
| 54 | + before do |
| 55 | + subject << path1 |
| 56 | + end |
| 57 | + |
39 | 58 | it "must add a new WordlistDir instance to search paths and return self" do
|
40 |
| - expect(subject << path).to be_kind_of(Ronin::Wordlists::SearchPaths) |
41 |
| - expect((subject << path).paths.size).to eq(3) |
| 59 | + expect(subject).to be_kind_of(Ronin::Wordlists::SearchPaths) |
| 60 | + expect(subject.paths.size).to eq(3) |
42 | 61 | end
|
43 | 62 | end
|
44 | 63 |
|
45 | 64 | describe "#find" do
|
46 |
| - let(:example_wrodlist_path) { File.join(path, "example_wordlist.txt") } |
| 65 | + let(:example_wrodlist_path) { File.join(path1, "example_wordlist.txt") } |
47 | 66 |
|
48 | 67 | it "must return wordlist path if it could be found" do
|
49 | 68 | expect(subject.find("example_wordlist.txt")).to eq(example_wrodlist_path)
|
50 | 69 | end
|
51 | 70 |
|
52 | 71 | it "must return nil if path could not be found" do
|
53 |
| - expect(subject.find("foo")).to eq(nil) |
| 72 | + expect(subject.find("foo")).to be(nil) |
54 | 73 | end
|
55 | 74 | end
|
56 | 75 |
|
57 | 76 | describe "#list" do
|
58 |
| - let(:all_wordlists) { Dir.children(path) } |
| 77 | + let(:all_wordlists) { [*Dir.children(path1), *Dir.children(path2)] } |
59 | 78 |
|
60 | 79 | context "if argument is not passed" do
|
61 | 80 | it "must list all wordlists in the wordlist directories" do
|
|
76 | 95 |
|
77 | 96 | describe "#open" do
|
78 | 97 | context "if wordlist exist" do
|
79 |
| - let(:example_wrodlist_path) { File.join(path, "example_wordlist.txt") } |
| 98 | + let(:example_wrodlist_path) { File.join(path1, "example_wordlist.txt") } |
80 | 99 |
|
81 | 100 | it "must call .open on Wordlist with path" do
|
82 | 101 | expect(Wordlist).to receive(:open).with(example_wrodlist_path)
|
| 102 | + |
83 | 103 | subject.open("example_wordlist")
|
84 | 104 | end
|
85 | 105 | end
|
|
0 commit comments