5
5
6
6
describe Egghunter do
7
7
8
- subject do
9
- Egghunter ::Driver . new
10
- end
8
+ describe Egghunter ::Driver do
9
+
10
+ subject do
11
+ Egghunter ::Driver . new
12
+ end
13
+
14
+ let ( :egg ) {
15
+ 'W00T'
16
+ }
17
+
18
+ describe '#run' do
19
+
20
+ def get_stdout ( &block )
21
+ out = $stdout
22
+ $stdout = fake = StringIO . new
23
+ begin
24
+ yield
25
+ ensure
26
+ $stdout = out
27
+ end
28
+ fake . string
29
+ end
30
+
31
+ let ( :default_opts ) {
32
+ { :platform => 'windows' , :format => 'c' , :eggtag => egg , :arch => 'x86' }
33
+ }
34
+
35
+ before ( :each ) do
36
+ allow ( Egghunter ::OptsConsole ) . to receive ( :parse ) . with ( any_args ) . and_return ( options )
37
+ end
11
38
12
- describe '#run' do
39
+ context 'when the platform is windows' do
40
+ let ( :options ) { default_opts }
13
41
14
- context 'when the platform is windows' do
15
- it 'returns a windows egghunter' do
42
+ it 'returns a windows egghunter' do
43
+ output = get_stdout { subject . run }
44
+ expect ( output ) . to include ( "\\ x66\\ x81\\ xca\\ xff" )
45
+ end
46
+ end
47
+
48
+ context 'when the platform is linux' do
49
+ let ( :options ) do
50
+ { :platform => 'linux' , :format => 'c' , :eggtag => egg , :arch => 'x86' }
51
+ end
52
+
53
+ it 'returns a linux egghunter' do
54
+ output = get_stdout { subject . run }
55
+ expect ( output ) . to include ( "\\ xfc\\ x66\\ x81\\ xc9\\ xff" )
56
+ end
57
+ end
58
+
59
+ context 'when the egg is WOOT' do
60
+ let ( :options ) { default_opts }
61
+
62
+ it 'includes W00T in the egghunter' do
63
+ output = get_stdout { subject . run }
64
+ expect ( output ) . to include ( "\\ x57\\ x30\\ x30\\ x54" )
65
+ end
16
66
end
17
67
end
68
+ end
69
+
18
70
19
- context 'when the platform is linux' do
20
- it 'returns a linux egghunter' do
71
+ describe Egghunter ::OptsConsole do
72
+ subject do
73
+ Egghunter ::OptsConsole
74
+ end
75
+
76
+ context 'when no options are given' do
77
+ it 'raises OptionParser::MissingArgument' do
78
+ expect { subject . parse ( [ ] ) } . to raise_error ( OptionParser ::MissingArgument )
21
79
end
22
80
end
23
81
24
- context 'when the output format is java' do
25
- it 'returns java format egghunter' do
82
+ context 'when no format is specified and --list-formats isn\'t used' do
83
+ it 'raises OptionParser::MissingArgument' do
84
+ args = '-e AAAA' . split
85
+ expect { subject . parse ( args ) } . to raise_error ( OptionParser ::MissingArgument )
26
86
end
27
87
end
28
88
29
- context 'when the egg is WOOT' do
30
- it 'includes W00TW00T in the egghunter' do
89
+ context 'when no egg is specified and --list-formats isn\'t used' do
90
+ it 'raises OptionParser::MissingArgument' do
91
+ args = '-f python' . split
92
+ expect { subject . parse ( args ) } . to raise_error ( OptionParser ::MissingArgument )
31
93
end
32
94
end
33
95
96
+ context 'when :depsize is a string' do
97
+ it 'raises OptionParser::InvalidOption' do
98
+ args = '-e AAAA -f c --depsize STRING' . split
99
+ expect { subject . parse ( args ) } . to raise_error ( OptionParser ::InvalidOption )
100
+ end
101
+ end
34
102
end
103
+
35
104
end
0 commit comments