Skip to content

Commit

Permalink
Update specs to test against fixture data.
Browse files Browse the repository at this point in the history
  • Loading branch information
jim committed Dec 20, 2011
1 parent 88d7457 commit 20df6dd
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/carmen/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def initialize(data={})
end

def subregions
return [] unless subregions?
@subregions ||= load_subregions
end

Expand Down
41 changes: 30 additions & 11 deletions spec/carmen/country_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,51 @@
describe Carmen::Country do

it "provides an API for finding countries by name" do
us = Carmen::Country.named('United States')
us.instance_of?(Carmen::Region).must_equal true
eastasia = Carmen::Country.named('Eastasia')
eastasia.instance_of?(Carmen::Region).must_equal true
end

it "provides an API for finding countries by code" do
us = Carmen::Country.coded('US')
us.instance_of?(Carmen::Region).must_equal true
eurasia = Carmen::Country.coded('EU')
eurasia.instance_of?(Carmen::Region).must_equal true
end

describe "with a country" do
it "is of type :country" do
@oceania = Carmen::Country.coded('OC')
@oceania.type.must_equal 'country'
end

describe "a country with subregions" do
before do
@us = Carmen::Country.coded('US')
@oceania = Carmen::Country.coded('OC')
end

it 'has a subregion data path' do
expected = Carmen.data_path + 'regions/us.yml'
@us.subregion_data_path.must_equal expected
expected = Carmen.data_path + 'regions/oc.yml'
@oceania.subregion_data_path.must_equal expected
end

it "has subregions" do
@us.subregions.instance_of?(Carmen::RegionCollection).must_equal true
@oceania.subregions?.must_equal true
end

it "has subregions" do
@oceania.subregions.instance_of?(Carmen::RegionCollection).must_equal true
@oceania.subregions.size.must_equal 1
end
end

describe "a country without subregions" do
before do
@eastasia = Carmen::Country.coded('ES')
end

it "has no subregions" do
@eastasia.subregions?.must_equal false
end

it "is of type :country" do
@us.type.must_equal 'country'
it "has an empty subregions collection" do
@eastasia.subregions.must_equal []
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/carmen/region_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
describe Carmen::Region do

it 'has a reasonable inspect value' do
us = Carmen::Country.coded('US')
us.inspect.must_equal '<#Carmen::Region type=country subregions?=true>'
oceania = Carmen::Country.coded('OC')
oceania.inspect.must_equal '<#Carmen::Region type=country subregions?=true>'
end

end
4 changes: 2 additions & 2 deletions spec/carmen/world_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Carmen::World.is_a?(Carmen::Region).must_equal(true)
end

it 'has 200 subregions' do
Carmen::World.subregions.size.must_equal(249)
it 'has 3 subregions' do
Carmen::World.subregions.size.must_equal(3)
end

end
8 changes: 8 additions & 0 deletions spec/data/regions/oc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- code: OC-01
name: Airstrip One
type: providence
subregions:
- code: OC-LO
name: London
type: city
22 changes: 22 additions & 0 deletions spec/data/world.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- alpha_2_code: OC
alpha_3_code: OCE
numeric_code: "001"
common_name: Oceania
name: Oceania
official_name: The Superstate of Oceania
type: country
- alpha_2_code: EU
alpha_3_code: EUR
numeric_code: "001"
common_name: Eurasia
name: Eurasia
official_name: The Superstate of Eurasia
type: country
- alpha_2_code: ES
alpha_3_code: EST
numeric_code: "003"
common_name: Eastasia
name: Eastasia
official_name: The Superstate of Eastasia
type: country

0 comments on commit 20df6dd

Please sign in to comment.