Skip to content

Commit d933eda

Browse files
committed
feat(ruby-version): enabled writing desired version to the proper file
1 parent 2c4e149 commit d933eda

File tree

8 files changed

+82
-5
lines changed

8 files changed

+82
-5
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"gherkin-lint": "^3.3.6",
5656
"husky": "^3.0.3",
5757
"mocha": "^6.2.0",
58+
"mock-fs": "^4.10.1",
5859
"npm-run-all": "^4.1.5",
5960
"nyc": "^14.1.1",
6061
"remark-cli": "^7.0.0",

src/ruby-version-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {promises} from 'fs';
2+
import {assert} from 'chai';
3+
import sinon from 'sinon';
4+
import any from '@travi/any';
5+
import scaffoldRubyVersion from './ruby-version';
6+
7+
suite('ruby-version', () => {
8+
let sandbox;
9+
10+
setup(() => {
11+
sandbox = sinon.createSandbox();
12+
13+
sandbox.stub(promises, 'writeFile');
14+
});
15+
16+
teardown(() => sandbox.restore());
17+
18+
test('that the version file is written to the file system', async () => {
19+
const projectRoot = any.string();
20+
21+
await scaffoldRubyVersion(projectRoot);
22+
23+
assert.calledWith(promises.writeFile, `${projectRoot}/.ruby-version`, '2.6.3');
24+
});
25+
});

src/ruby-version.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {promises} from 'fs';
2+
3+
export default async function (projectRoot) {
4+
await promises.writeFile(`${projectRoot}/.ruby-version`, '2.6.3');
5+
}

src/scaffolder-test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
import {assert} from 'chai';
2+
import sinon from 'sinon';
3+
import any from '@travi/any';
4+
import * as rubyVersionScaffolder from './ruby-version';
25
import {scaffold} from './scaffolder';
36

47
suite('scaffolder', () => {
8+
let sandbox;
9+
10+
setup(() => {
11+
sandbox = sinon.createSandbox();
12+
13+
sandbox.stub(rubyVersionScaffolder, 'default');
14+
});
15+
16+
teardown(() => sandbox.restore());
17+
518
test('that the project is scaffolded', async () => {
6-
const result = await scaffold();
19+
const projectRoot = any.string();
20+
21+
const result = await scaffold({projectRoot});
722

23+
assert.calledWith(rubyVersionScaffolder.default, projectRoot);
824
assert.equal(result.verificationCommand, 'rake');
925
});
1026
});

src/scaffolder.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export function scaffold() {
1+
import scaffoldRubyVersion from './ruby-version';
2+
3+
export async function scaffold({projectRoot}) {
4+
await scaffoldRubyVersion(projectRoot);
5+
26
return {
37
verificationCommand: 'rake'
48
};

test/integration/features/basic.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ Feature: Simplest Use
33
Scenario: Minimal Options
44
Given the default answers are chosen
55
When the project is scaffolded
6-
# Then the expected files are generated
7-
Then the expected results are returned to the project scaffolder
6+
Then the expected files are generated
7+
And the expected results are returned to the project scaffolder

test/integration/features/step_definitions/common-steps.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1+
import {promises} from 'fs';
2+
import stubbedFs from 'mock-fs';
13
// import bddStdIn from 'bdd-stdin';
24
import {assert} from 'chai';
35
import any from '@travi/any';
4-
import {Given, Then, When} from 'cucumber';
6+
import {After, Before, Given, Then, When} from 'cucumber';
57
import {scaffold} from '../../../../src';
68

79
let scaffoldResult;
810

11+
Before(async function () {
12+
// work around for overly aggressive mock-fs, see:
13+
// https://github.com/tschaub/mock-fs/issues/213#issuecomment-347002795
14+
require('mock-stdin'); // eslint-disable-line import/no-extraneous-dependencies
15+
16+
stubbedFs({});
17+
});
18+
19+
After(function () {
20+
stubbedFs.restore();
21+
});
22+
923
Given('the default answers are chosen', async function () {
1024
return undefined;
1125
});
@@ -39,6 +53,12 @@ When(/^the project is scaffolded$/, async function () {
3953
});
4054
});
4155

56+
Then('the expected files are generated', async function () {
57+
const rubyVersion = await promises.readFile(`${process.cwd()}/.ruby-version`);
58+
59+
assert.equal(rubyVersion.toString(), '2.6.3');
60+
});
61+
4262
Then('the expected results are returned to the project scaffolder', async function () {
4363
assert.equal(scaffoldResult.verificationCommand, 'rake');
4464
});

0 commit comments

Comments
 (0)