166 | 166 |
@resolve.value.should == "foo"
|
167 | 167 |
end
|
168 | 168 |
|
|
169 |
describe "when dealing with whitespace" do
|
|
170 |
it "should by default strip whitespace" do
|
|
171 |
@resolve.setcode {' value '}
|
|
172 |
@resolve.value.should == 'value'
|
|
173 |
end
|
|
174 |
|
|
175 |
describe "when given a string" do
|
|
176 |
[true, false
|
|
177 |
].each do |windows|
|
|
178 |
describe "#{ (windows) ? '' : 'not' } on Windows" do
|
|
179 |
before do
|
|
180 |
Facter::Util::Config.stubs(:is_windows?).returns(windows)
|
|
181 |
end
|
|
182 |
|
|
183 |
describe "stripping whitespace" do
|
|
184 |
[{:name => 'leading', :result => ' value', :expect => 'value'},
|
|
185 |
{:name => 'trailing', :result => 'value ', :expect => 'value'},
|
|
186 |
{:name => 'internal', :result => 'val ue', :expect => 'val ue'},
|
|
187 |
{:name => 'leading and trailing', :result => ' value ', :expect => 'value'},
|
|
188 |
{:name => 'leading and internal', :result => ' val ue', :expect => 'val ue'},
|
|
189 |
{:name => 'trailing and internal', :result => 'val ue ', :expect => 'val ue'}
|
|
190 |
].each do |scenario|
|
|
191 |
|
|
192 |
it "should remove outer whitespace when whitespace is #{scenario[:name]}" do
|
|
193 |
@resolve.setcode "/bin/foo"
|
|
194 |
Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns scenario[:result]
|
|
195 |
@resolve.value.should == scenario[:expect]
|
|
196 |
end
|
|
197 |
|
|
198 |
end
|
|
199 |
end
|
|
200 |
|
|
201 |
describe "not stripping whitespace" do
|
|
202 |
before do
|
|
203 |
@resolve.preserve_whitespace
|
|
204 |
end
|
|
205 |
|
|
206 |
[{:name => 'leading', :result => ' value', :expect => ' value'},
|
|
207 |
{:name => 'trailing', :result => 'value ', :expect => 'value '},
|
|
208 |
{:name => 'internal', :result => 'val ue', :expect => 'val ue'},
|
|
209 |
{:name => 'leading and trailing', :result => ' value ', :expect => ' value '},
|
|
210 |
{:name => 'leading and internal', :result => ' val ue', :expect => ' val ue'},
|
|
211 |
{:name => 'trailing and internal', :result => 'val ue ', :expect => 'val ue '}
|
|
212 |
].each do |scenario|
|
|
213 |
|
|
214 |
it "should not remove #{scenario[:name]} whitespace" do
|
|
215 |
@resolve.setcode "/bin/foo"
|
|
216 |
Facter::Util::Resolution.expects(:exec).once.with("/bin/foo").returns scenario[:result]
|
|
217 |
@resolve.value.should == scenario[:expect]
|
|
218 |
end
|
|
219 |
|
|
220 |
end
|
|
221 |
end
|
|
222 |
end
|
|
223 |
end
|
|
224 |
end
|
|
225 |
|
|
226 |
describe "when given a block" do
|
|
227 |
describe "stripping whitespace" do
|
|
228 |
[{:name => 'leading', :result => ' value', :expect => 'value'},
|
|
229 |
{:name => 'trailing', :result => 'value ', :expect => 'value'},
|
|
230 |
{:name => 'internal', :result => 'val ue', :expect => 'val ue'},
|
|
231 |
{:name => 'leading and trailing', :result => ' value ', :expect => 'value'},
|
|
232 |
{:name => 'leading and internal', :result => ' val ue', :expect => 'val ue'},
|
|
233 |
{:name => 'trailing and internal', :result => 'val ue ', :expect => 'val ue'}
|
|
234 |
].each do |scenario|
|
|
235 |
|
|
236 |
it "should remove outer whitespace when whitespace is #{scenario[:name]}" do
|
|
237 |
@resolve.setcode {scenario[:result]}
|
|
238 |
@resolve.value.should == scenario[:expect]
|
|
239 |
end
|
|
240 |
|
|
241 |
end
|
|
242 |
end
|
|
243 |
|
|
244 |
describe "not stripping whitespace" do
|
|
245 |
before do
|
|
246 |
@resolve.preserve_whitespace
|
|
247 |
end
|
|
248 |
|
|
249 |
[{:name => 'leading', :result => ' value', :expect => ' value'},
|
|
250 |
{:name => 'trailing', :result => 'value ', :expect => 'value '},
|
|
251 |
{:name => 'internal', :result => 'val ue', :expect => 'val ue'},
|
|
252 |
{:name => 'leading and trailing', :result => ' value ', :expect => ' value '},
|
|
253 |
{:name => 'leading and internal', :result => ' val ue', :expect => ' val ue'},
|
|
254 |
{:name => 'trailing and internal', :result => 'val ue ', :expect => 'val ue '}
|
|
255 |
].each do |scenario|
|
|
256 |
|
|
257 |
it "should not remove #{scenario[:name]} whitespace" do
|
|
258 |
@resolve.setcode {scenario[:result]}
|
|
259 |
@resolve.value.should == scenario[:expect]
|
|
260 |
end
|
|
261 |
|
|
262 |
end
|
|
263 |
end
|
|
264 |
end
|
|
265 |
end
|
|
266 |
|
169 | 267 |
describe "and setcode has not been called" do
|
170 | 268 |
it "should return nil" do
|
171 | 269 |
Facter::Util::Resolution.expects(:exec).with(nil, nil).never
|