forked from zdavatz/oddb2xml
/
options_spec.rb
201 lines (180 loc) · 5.97 KB
/
options_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# encoding: utf-8
require 'spec_helper'
require "#{Dir.pwd}/lib/oddb2xml/options"
module Kernel
def cli_capture(stream)
begin
stream = stream.to_s
eval "$#{stream} = StringIO.new"
yield
result = eval("$#{stream}").string
ensure
eval "$#{stream} = #{stream.upcase}"
end
result
end
end
describe Oddb2xml::Options do
include ServerMockHelper
Default_opts = {
:fi => false,
:adr => false,
:address => false,
:nonpharma => false,
:extended => false,
:compress_ext => nil,
:format => :xml,
:calc => false,
:tag_suffix => nil,
:debug => false,
:ean14 => false,
:skip_download=> false,
:log => false,
:percent => nil,
}
context 'when default_opts' do
specify { expect(Oddb2xml::Options.default_opts).to eq Default_opts }
end
context 'when no options is passed' do
options = Oddb2xml::Options.new
specify { expect(options.opts).to eq Default_opts }
end
context 'when -c tar.gz option is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-c tar.gz'.split(' '))
specify { expect(options.opts[:compress_ext]).to eq('tar.gz') }
expected = Default_opts.clone
expected[:compress_ext] = 'tar.gz'
specify { expect(options.opts).to eq expected }
end
context 'when -c tar.gz option --skip-download is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-c tar.gz --skip-download'.split(' '))
expected = Default_opts.clone
expected[:compress_ext] = 'tar.gz'
expected[:skip_download] = true
specify { expect(options.opts).to eq expected }
end
context 'when -c tar.gz option --skip-download is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-c tar.gz --skip-download'.split(' '))
expected = Default_opts.clone
expected[:compress_ext] = 'tar.gz'
expected[:skip_download] = true
specify { expect(options.opts).to eq expected }
end
context 'when -a is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-a'.split(' '))
expected = Default_opts.clone
expected[:nonpharma] = true
specify { expect(options.opts).to eq expected }
end
context 'when --append is given' do
options = Oddb2xml::Options.new
options.parser.parse!('--append '.split(' '))
expected = Default_opts.clone
expected[:nonpharma] = true
specify { expect(options.opts).to eq expected }
end
context 'when -e is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-e'.split(' '))
expected = Default_opts.clone
expected[:extended] = true
expected[:nonpharma] = true
expected[:calc] = true
expected[:price] = :zurrose
specify { expect(options.opts).to eq expected }
end
context 'when -e -I 80 is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-e -I 80'.split(' '))
expected = Default_opts.clone
expected[:extended] = true
expected[:nonpharma] = true
expected[:calc] = true
expected[:price] = :zurrose
expected[:percent] = 80
specify { expect(options.opts).to eq expected }
end
context 'when -f dat is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-f dat'.split(' '))
expected = Default_opts.clone
expected[:format] = :dat
specify { expect(options.opts).to eq expected }
end
context 'when -f dat -I 80 is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-f dat -I 80'.split(' '))
expected = Default_opts.clone
expected[:format] = :dat
expected[:percent] = 80
expected[:price] = :zurrose
specify { expect(options.opts).to eq expected }
end
context 'when -I 80 is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-I 80'.split(' '))
expected = Default_opts.clone
expected[:percent] = 80
expected[:price] = :zurrose
specify { expect(options.opts).to eq expected }
end
context 'when -o is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-o'.split(' '))
expected = Default_opts.clone
expected[:fi] = true
specify { expect(options.opts).to eq expected }
end
context 'when -i ean14 is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-i ean14'.split(' '))
expected = Default_opts.clone
expected[:ean14] = true
specify { expect(options.opts).to eq expected }
end
context 'when -x addr is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-x addr'.split(' '))
expected = Default_opts.clone
expected[:address] = true
specify { expect(options.opts).to eq expected }
end
context 'when -p zurrose is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-p zurrose'.split(' '))
expected = Default_opts.clone
expected[:price] = :zurrose
specify { expect(options.opts).to eq expected }
end
context 'when -o fi --log is given' do
options = Oddb2xml::Options.new
options.parser.parse!('-o fi --log'.split(' '))
expected = Default_opts.clone
expected[:fi] = true
expected[:log] = true
specify { expect(options.opts).to eq expected }
end
context 'when -a nonpharma -p zurrose is given' do
options = Oddb2xml::Options.new
args = '-a nonpharma -p zurrose'.split(' ')
options.parser.parse!(args) # .should raise
expected = Default_opts.clone
expected[:price] = :zurrose
expected[:nonpharma] = true
specify { expect(options.opts).to eq expected }
specify { expect(args).to eq ["nonpharma", "zurrose"] } # will lead to an exit 2 in bin/oddb2xml
end
context 'when --calc is given' do
options = Oddb2xml::Options.new
args = '--calc'.split(' ')
options.parser.parse!(args) # .should raise
expected = Default_opts.clone
expected[:calc] = true
specify { expect(options.opts).to eq expected }
specify { expect(args).to eq [] }
end
end