diff options
| author | Bryan Donovan <[email protected]> | 2013-01-07 00:03:37 -0800 |
|---|---|---|
| committer | Bryan Donovan <[email protected]> | 2013-01-07 00:03:37 -0800 |
| commit | ee9c13d35ed0dbd67e4a27ed3d525fa5926929a5 (patch) | |
| tree | c7144a15eab901e4d4332f8e5c0f1d1b5d0e0b0b | |
| parent | a0c614c620125efa0553aec2b470c8d8539b8ec5 (diff) | |
| download | faker-ee9c13d35ed0dbd67e4a27ed3d525fa5926929a5.tar.xz faker-ee9c13d35ed0dbd67e4a27ed3d525fa5926929a5.zip | |
brState() tests
| -rw-r--r-- | lib/address.js | 12 | ||||
| -rw-r--r-- | lib/random.js | 6 | ||||
| -rw-r--r-- | test/address.unit.js | 36 |
3 files changed, 48 insertions, 6 deletions
diff --git a/lib/address.js b/lib/address.js index d1892748..9b5a63c0 100644 --- a/lib/address.js +++ b/lib/address.js @@ -61,18 +61,18 @@ exports.secondaryAddress = function () { )); }; -exports.brState = function (abbr) { - return Helpers.randomize(definitions[abbr ? 'br_state_abbr' : 'br_state']()); +exports.brState = function (useAbbr) { + return useAbbr ? random.br_state_abbr() : random.br_state(); }; exports.ukCounty = function () { - return Helpers.randomize(definitions.uk_county()); + return random.uk_county(); }; exports.ukCountry = function () { - return Helpers.randomize(definitions.uk_country()); + return random.uk_country(); }; -exports.usState = function (abbr) { - return Helpers.randomize(definitions[abbr ? 'us_state_abbr' : 'us_state']()); +exports.usState = function (useAbbr) { + return useAbbr ? random.us_state_abbr() : random.us_state(); }; diff --git a/lib/random.js b/lib/random.js index f1a4dfbd..e7a9b667 100644 --- a/lib/random.js +++ b/lib/random.js @@ -21,6 +21,12 @@ var method_names = [ 'city_prefix', 'city_suffix', 'street_suffix', + 'br_state', + 'br_state_abbr', + 'us_state', + 'us_state_abbr', + 'uk_county', + 'uk_country', // Name 'first_name', diff --git a/test/address.unit.js b/test/address.unit.js index 07b5c43f..f5bbee92 100644 --- a/test/address.unit.js +++ b/test/address.unit.js @@ -157,4 +157,40 @@ describe("name.js", function () { }); }); }); + + describe("secondaryAddress()", function() { + // TODO + }); + + describe("brState()", function() { + beforeEach(function () { + sinon.spy(random, 'br_state_abbr'); + sinon.spy(random, 'br_state'); + }); + + afterEach(function () { + random.br_state_abbr.restore(); + random.br_state.restore(); + }); + + context("when useAbbr is true", function () { + it("returns a br_state_abbr", function () { + var state = Faker.Address.brState(true); + + assert.ok(state); + assert.ok(random.br_state_abbr.called); + assert.ok(!random.br_state.called); + }); + }); + + context("when useAbbr is not set", function () { + it("returns a br_state", function () { + var state = Faker.Address.brState(); + + assert.ok(state); + assert.ok(!random.br_state_abbr.called); + assert.ok(random.br_state.called); + }); + }); + }); }); |
