Skip to content

Commit 4463121

Browse files
committed
change specs
1 parent c459baa commit 4463121

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

spec/fixtures/extra_wordlists/extra_wordlist1.txt

Whitespace-only changes.

spec/fixtures/extra_wordlists/extra_wordlist2.txt

Whitespace-only changes.

spec/search_paths_spec.rb

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,78 @@
33
require 'ronin/wordlists/exceptions'
44

55
describe Ronin::Wordlists::SearchPaths do
6-
subject { described_class.new([path]) }
6+
subject { described_class.new([path1, path2]) }
77

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')) }
1010

1111
describe "#initialize" do
1212
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])
1515
end
1616
end
1717

1818
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
2235
end
2336
end
2437

2538
describe "#each" do
26-
let(:example_block) { proc { p "test" } }
39+
let(:wordlist_dirs) { [Ronin::Wordlists::WordlistDir.new(path2), Ronin::Wordlists::WordlistDir.new(path1)] }
2740

2841
it "must iterate over #paths and yield each directory" do
2942
yielded_values = []
43+
3044
subject.each do |value|
3145
yielded_values << value
3246
end
3347

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))
3550
end
3651
end
3752

3853
describe "#<<" do
54+
before do
55+
subject << path1
56+
end
57+
3958
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)
4261
end
4362
end
4463

4564
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") }
4766

4867
it "must return wordlist path if it could be found" do
4968
expect(subject.find("example_wordlist.txt")).to eq(example_wrodlist_path)
5069
end
5170

5271
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)
5473
end
5574
end
5675

5776
describe "#list" do
58-
let(:all_wordlists) { Dir.children(path) }
77+
let(:all_wordlists) { [*Dir.children(path1), *Dir.children(path2)] }
5978

6079
context "if argument is not passed" do
6180
it "must list all wordlists in the wordlist directories" do
@@ -76,10 +95,11 @@
7695

7796
describe "#open" do
7897
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") }
8099

81100
it "must call .open on Wordlist with path" do
82101
expect(Wordlist).to receive(:open).with(example_wrodlist_path)
102+
83103
subject.open("example_wordlist")
84104
end
85105
end

0 commit comments

Comments
 (0)