Skip to content

Commit

Permalink
Merge pull request #837 from mrstebo/add-music-faker
Browse files Browse the repository at this point in the history
Added the Music module
  • Loading branch information
Marak authored Sep 6, 2020
2 parents 90f6dbe + 0aefab1 commit 81f1adf
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
* paragraphs
* text
* lines
* music
* genre
* name
* firstName
* lastName
Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ function Faker (opts) {
var Vehicle = require('./vehicle');
self.vehicle = new Vehicle(self);

var Music = require('./music');
self.music = new Music(self);

var _definitions = {
"name": ["first_name", "last_name", "prefix", "suffix", "gender", "title", "male_prefix", "female_prefix", "male_first_name", "female_first_name", "male_middle_name", "female_middle_name", "male_last_name", "female_last_name"],
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "country_code_alpha_3", "state", "state_abbr", "street_prefix", "postcode", "postcode_by_state", "direction", "direction_abbr", "time_zone"],
Expand All @@ -112,6 +115,7 @@ function Faker (opts) {
"system": ["mimeTypes", "directoryPaths"],
"date": ["month", "weekday"],
"vehicle": ["vehicle", "manufacturer", "model", "type", "fuel", "vin", "color"],
"music": ["genre"],
"title": "",
"separator": ""
};
Expand Down
1 change: 1 addition & 0 deletions lib/locales/en/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ en.finance = require("./finance");
en.date = require("./date");
en.system = require("./system");
en.vehicle = require("./vehicle");
en.music = require("./music");
20 changes: 20 additions & 0 deletions lib/locales/en/music/genre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module["exports"] = [
"Rock",
"Metal",
"Pop",
"Electronic",
"Folk",
"World",
"Country",
"Jazz",
"Funk",
"Soul",
"Hip Hop",
"Classical",
"Latin",
"Reggae",
"Stage And Screen",
"Blues",
"Non Music",
"Rap"
];
3 changes: 3 additions & 0 deletions lib/locales/en/music/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var music = {};
module['exports'] = music;
music.genre = require("./genre");
22 changes: 22 additions & 0 deletions lib/music.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
*
* @namespace faker.music
*/
var Music = function (faker) {
var self = this;
/**
* genre
*
* @method faker.music.genre
*/
self.genre = function () {
return faker.random.arrayElement(faker.definitions.music.genre);
};

self.genre.schema = {
"description": "Generates a genre.",
"sampleResults": ["Rock", "Metal", "Pop"]
};
};

module["exports"] = Music;
17 changes: 17 additions & 0 deletions test/music.unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if (typeof module !== 'undefined') {
var assert = require('assert');
var sinon = require('sinon');
var faker = require('../index');
}

describe("music.js", function () {
describe("genre()", function () {
it("returns a genre", function () {
sinon.stub(faker.music, 'genre').returns('Rock');
var genre = faker.music.genre();

assert.equal(genre, 'Rock');
faker.music.genre.restore();
});
});
});

0 comments on commit 81f1adf

Please sign in to comment.