Skip to content

Commit a026ca7

Browse files
authored
Add spec for Download (#23)
1 parent 93aa38c commit a026ca7

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

spec/cli/commands/download_spec.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,69 @@
11
require 'spec_helper'
22
require 'ronin/wordlists/cli/commands/download'
3+
require 'ronin/wordlists/root'
34
require_relative 'man_page_example'
45

56
describe Ronin::Wordlists::CLI::Commands::Download do
67
include_examples "man_page"
8+
9+
let(:url) { 'http://example.com/wordlist.txt' }
10+
let(:yaml_result) do
11+
{ 'download_wordlist' => { url: url } }
12+
end
13+
14+
describe '#run' do
15+
context 'when the url is provided' do
16+
it 'must call download with the URL' do
17+
expect(subject).to receive(:download).with(url)
18+
19+
subject.run(url)
20+
end
21+
end
22+
23+
context 'when the name is provided' do
24+
let(:name) { 'download_wordlist' }
25+
26+
context "and exist in wordlist" do
27+
before do
28+
allow(YAML).to receive(:load_file).and_return(yaml_result)
29+
end
30+
31+
it 'must look up the URL from the wordlists and calls download' do
32+
expect(subject).to receive(:download).with(url)
33+
34+
subject.run(name)
35+
end
36+
end
37+
38+
context 'when the name is unknown' do
39+
it 'must print an error and exit' do
40+
expect {
41+
subject.run('unknown_wordlist')
42+
}.to output(/unknown wordlist/).to_stderr.and raise_error(SystemExit)
43+
end
44+
end
45+
end
46+
end
47+
48+
describe '#download' do
49+
context 'when the download is successful' do
50+
it 'must log a success message' do
51+
allow(subject.wordlist_dir).to receive(:download).with(url).and_return(double('DownloadedWordlist', name: 'test_wordlist'))
52+
53+
expect {
54+
subject.download(url)
55+
}.to output(/Wordlist test_wordlist downloaded/).to_stdout
56+
end
57+
end
58+
59+
context 'when the download fails' do
60+
it 'must log error massage and exit' do
61+
allow(subject.wordlist_dir).to receive(:download).with(url).and_raise(Ronin::Wordlists::DownloadFailed.new('Download failed'))
62+
63+
expect {
64+
subject.download(url)
65+
}.to output(/Download failed/).to_stderr.and raise_error(SystemExit)
66+
end
67+
end
68+
end
769
end

0 commit comments

Comments
 (0)