spec/federation_spec.rb in icu_utils-1.0.0 vs spec/federation_spec.rb in icu_utils-1.0.1
- old
+ new
@@ -1,9 +1,11 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
module ICU
describe Federation do
+ let(:total) { 179 }
+
context "#find using codes" do
it "should find a federation given a valid code" do
fed = Federation.find('IRL')
fed.code.should == 'IRL'
fed.name.should == 'Ireland'
@@ -82,10 +84,18 @@
Federation.find('Republic of Macedonia').name.should == 'Macedonia'
Federation.find('former yugoslav republic').name.should == 'Macedonia'
end
end
+ context "#find from common code errors" do
+ it "should find IRL from ICU" do
+ Federation.find('ICU').code.should == 'IRL'
+ Federation.find('SPA').code.should == 'ESP'
+ Federation.find('WAL').code.should == 'WLS'
+ end
+ end
+
context "#find with alternative inputs" do
it "should behave robustly with completely invalid inputs" do
Federation.find().should be_nil
Federation.find(nil).should be_nil
Federation.find('').should be_nil
@@ -113,75 +123,67 @@
Federation.find('land').should be_nil
end
end
context "#menu" do
- before(:all) do
- @total = 174
- end
-
it "should return array of name-code pairs in order of name by default" do
menu = Federation.menu
- menu.should have(@total).items
+ menu.should have(total).items
names = menu.map{|m| m.first}.join(',')
codes = menu.map{|m| m.last}.join(',')
names.index('Afghanistan').should == 0
names.index('Iraq,Ireland,Israel').should_not be_nil
codes.index('AFG').should == 0
codes.index('IRQ,IRL,ISR').should_not be_nil
end
it "should be configuarble to order the list by codes" do
menu = Federation.menu(:order => "code")
- menu.should have(@total).items
+ menu.should have(total).items
names = menu.map{|m| m.first}.join(',')
codes = menu.map{|m| m.last}.join(',')
names.index('Afghanistan').should == 0
names.index('Ireland,Iraq,Iceland').should_not be_nil
codes.index('AFG').should == 0
codes.index('IRL,IRQ,ISL').should_not be_nil
end
it "should be configuarble to have a selected country at the top" do
menu = Federation.menu(:top => 'IRL')
- menu.should have(@total).items
+ menu.should have(total).items
names = menu.map{|m| m.first}.join(',')
codes = menu.map{|m| m.last}.join(',')
names.index('Ireland,Afghanistan').should == 0
names.index('Iraq,Israel').should_not be_nil
codes.index('IRL,AFG').should == 0
codes.index('IRQ,ISR').should_not be_nil
end
it "should be configuarble to have 'None' entry at the top" do
menu = Federation.menu(:none => 'None')
- menu.should have(@total + 1).items
+ menu.should have(total + 1).items
names = menu.map{|m| m.first}.join(',')
codes = menu.map{|m| m.last}.join(',')
names.index('None,Afghanistan').should == 0
codes.index(',AFG').should == 0
end
it "should be able to handle multiple configuarations" do
menu = Federation.menu(:top => 'IRL', :order => 'code', :none => 'None')
- menu.should have(@total + 1).items
+ menu.should have(total + 1).items
names = menu.map{|m| m.first}.join(',')
codes = menu.map{|m| m.last}.join(',')
names.index('None,Ireland,Afghanistan').should == 0
names.index('Iraq,Iceland').should_not be_nil
codes.index(',IRL,AFG').should == 0
codes.index('IRQ,ISL').should_not be_nil
end
end
context "#codes" do
- before(:all) do
- @total = 174
- end
-
it "should return array of codes ordered alphabetically" do
codes = Federation.codes
- codes.should have(@total).items
+ codes.should have(total).items
all = codes.join(',')
all.index('AFG').should == 0
all.index('INA,IND,IRI,IRL,IRQ,ISL,ISR,ISV,ITA,IVB').should_not be_nil
end
end