2 * Copyright 2014 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 var should = require("should");
18 var sinon = require("sinon");
19 var fs = require("fs");
21 var config = require("../../../../red/cli/lib/config");
23 describe("cli config", function() {
24 afterEach(function() {
27 it('loads preferences when target referenced', sinon.test(function() {
28 this.stub(fs,"readFileSync",function() {
29 return '{"target":"http://example.com:1880"}'
31 config.target.should.eql("http://example.com:1880");
33 it('provide default value for target', sinon.test(function() {
34 this.stub(fs,"readFileSync",function() {
37 config.target.should.eql("http://localhost:1880");
39 it('saves preferences when target set', sinon.test(function() {
40 this.stub(fs,"readFileSync",function() {
41 return '{"target":"http://another.example.com:1880"}'
43 this.stub(fs,"writeFileSync",function() {});
45 config.target.should.eql("http://another.example.com:1880");
46 config.target = "http://final.example.com:1880";
48 fs.readFileSync.calledOnce.should.be.true;
49 fs.writeFileSync.calledOnce.should.be.true;