Skip to content

Commit

Permalink
feat(gems): wrote the gemfile to the filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Aug 20, 2019
1 parent 0d29fbc commit 4dda5fa
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
30 changes: 30 additions & 0 deletions src/gems-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {resolve} from 'path';
import {assert} from 'chai';
import sinon from 'sinon';
import any from '@travi/any';
import * as fsAsync from '../thirdparty-wrappers/fs';
import scaffoldGems from './gems';

suite('Gems', () => {
let sandbox;

setup(() => {
sandbox = sinon.createSandbox();

sandbox.stub(fsAsync, 'copyFile');
});

teardown(() => sandbox.restore());

test('that the Gemfile is generated', async () => {
const projectRoot = any.string();

await scaffoldGems(projectRoot);

assert.calledWith(
fsAsync.copyFile,
resolve(__dirname, '..', 'templates', 'Gemfile.rb'),
`${projectRoot}/Gemfile`
);
});
});
6 changes: 6 additions & 0 deletions src/gems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {resolve} from 'path';
import {copyFile} from '../thirdparty-wrappers/fs';

export default async function (projectRoot) {
await copyFile(resolve(__dirname, '..', 'templates', 'Gemfile.rb'), `${projectRoot}/Gemfile`);
}
6 changes: 5 additions & 1 deletion src/scaffolder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sinon from 'sinon';
import any from '@travi/any';
import * as rubyVersionScaffolder from './ruby-version';
import * as rakeScaffolder from './rake';
import * as gemsScaffolder from './gems';
import {scaffold} from './scaffolder';

suite('scaffolder', () => {
Expand All @@ -13,17 +14,20 @@ suite('scaffolder', () => {

sandbox.stub(rubyVersionScaffolder, 'default');
sandbox.stub(rakeScaffolder, 'default');
sandbox.stub(gemsScaffolder, 'default');
});

teardown(() => sandbox.restore());

test('that the project is scaffolded', async () => {
const projectRoot = any.string();
const gemsForRake = any.listOf(any.word);
rakeScaffolder.default.withArgs(projectRoot).resolves({gems: gemsForRake});

const result = await scaffold({projectRoot});

assert.calledWith(rubyVersionScaffolder.default, projectRoot);
assert.calledWith(rakeScaffolder.default, projectRoot);
assert.calledWith(gemsScaffolder.default, projectRoot, gemsForRake);
assert.equal(result.verificationCommand, 'rake');
});
});
9 changes: 6 additions & 3 deletions src/scaffolder.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import scaffoldRubyVersion from './ruby-version';
import scaffoldRake from './rake';
import scaffoldGem from './gems';

export async function scaffold({projectRoot}) {
await Promise.all([
scaffoldRubyVersion(projectRoot),
scaffoldRake(projectRoot)
const [rakeResults] = await Promise.all([
scaffoldRake(projectRoot),
scaffoldRubyVersion(projectRoot)
]);

await scaffoldGem(projectRoot, rakeResults.gems);

return {
verificationCommand: 'rake'
};
Expand Down
6 changes: 6 additions & 0 deletions templates/Gemfile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

group :verify do
gem 'mdl'
gem 'rake'
end
9 changes: 6 additions & 3 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Before(async function () {

stubbedFs({
templates: {
'Rakefile.rb': await readFile(resolve(__dirname, '../../../../', 'templates/Rakefile.rb'))
'Rakefile.rb': await readFile(resolve(__dirname, '../../../../', 'templates/Rakefile.rb')),
'Gemfile.rb': await readFile(resolve(__dirname, '../../../../', 'templates/Gemfile.rb'))
}
});

Expand Down Expand Up @@ -69,13 +70,15 @@ When(/^the project is scaffolded$/, async function () {

Then('the expected files are generated', async function () {
const projectRoot = process.cwd();
const [rubyVersion, rakefileExists] = await Promise.all([
const [rubyVersion, rakefileExists, gemfileExists] = await Promise.all([
readFile(`${projectRoot}/.ruby-version`),
existsAsync(`${projectRoot}/Rakefile`)
existsAsync(`${projectRoot}/Rakefile`),
existsAsync(`${projectRoot}/Gemfile`)
]);

assert.equal(rubyVersion.toString(), '2.6.3');
assert.isTrue(rakefileExists);
assert.isTrue(gemfileExists);
});

Then('the expected results are returned to the project scaffolder', async function () {
Expand Down

0 comments on commit 4dda5fa

Please sign in to comment.