|
268 | 268 | end
|
269 | 269 | end
|
270 | 270 | end
|
| 271 | + |
| 272 | + describe "#run_cmd" do |
| 273 | + |
| 274 | + end |
| 275 | + |
| 276 | + let(:osql) do |
| 277 | + 'osql' |
| 278 | + end |
| 279 | + |
| 280 | + let(:sql_command) do |
| 281 | + 'sqlcmd' |
| 282 | + end |
| 283 | + |
| 284 | + describe "#check_osql" do |
| 285 | + it "should return nil if no osql" do |
| 286 | + expect(subject).to receive(:run_cmd).with('osql -?').and_return('blah') |
| 287 | + subject.check_osql.should be_falsey |
| 288 | + end |
| 289 | + |
| 290 | + it "should return true if present" do |
| 291 | + expect(subject).to receive(:run_cmd).with('osql -?').and_return('(usage: osql)') |
| 292 | + subject.check_osql.should be_truthy |
| 293 | + end |
| 294 | + end |
| 295 | + |
| 296 | + describe "#check_sqlcmd" do |
| 297 | + it "should return nil if no sqlcmd" do |
| 298 | + expect(subject).to receive(:run_cmd).and_return('blah') |
| 299 | + subject.check_sqlcmd.should be_falsey |
| 300 | + end |
| 301 | + |
| 302 | + it "should return true if present" do |
| 303 | + expect(subject).to receive(:run_cmd).and_return('SQL Server Command Line Tool') |
| 304 | + subject.check_sqlcmd.should be_truthy |
| 305 | + end |
| 306 | + |
| 307 | + end |
| 308 | + |
| 309 | + describe "#get_sql_client" do |
| 310 | + it "should return nil if no client is available" do |
| 311 | + expect(subject).to receive(:check_sqlcmd).and_return(false) |
| 312 | + expect(subject).to receive(:check_osql).and_return(false) |
| 313 | + subject.get_sql_client.should be_nil |
| 314 | + subject.sql_client.should be_nil |
| 315 | + end |
| 316 | + |
| 317 | + it "should return 'osql' if osql is available" do |
| 318 | + expect(subject).to receive(:check_sqlcmd).and_return(false) |
| 319 | + expect(subject).to receive(:check_osql).and_return(true) |
| 320 | + subject.get_sql_client.should eq osql |
| 321 | + subject.sql_client.should eq osql |
| 322 | + end |
| 323 | + |
| 324 | + it "should return 'sqlcmd' if sqlcmd is available" do |
| 325 | + allow(subject).to receive(:check_osql).and_return(true) |
| 326 | + expect(subject).to receive(:check_sqlcmd).and_return(true) |
| 327 | + subject.get_sql_client.should eq sql_command |
| 328 | + subject.sql_client.should eq sql_command |
| 329 | + end |
| 330 | + end |
271 | 331 | end
|
0 commit comments