spec/divISOr_spec.rb in divISOr-0.0.1 vs spec/divISOr_spec.rb in divISOr-1.0.0
- old
+ new
@@ -2,14 +2,14 @@
describe "Divisor" do
context 'validation' do
context 'for ISO 3166' do
let(:iso3166) { mock(:validate => true) }
- before { ISO3166.stub(:new => iso3166) }
+ before { ISO3166::Codes.stub(:new => iso3166) }
it 'create a ISO3166 on first call' do
- ISO3166.should_receive(:new)
+ ISO3166::Codes.should_receive(:new)
DivISOr.validate_iso3166('US')
end
it 'delegates to the ISO3166 class' do
iso3166.should_receive(:validate).with('US')
@@ -22,14 +22,14 @@
end
end
context 'for ISO 4217' do
let(:iso4217) { mock(:validate => true) }
- before { ISO4217.stub(:new => iso4217) }
+ before { ISO4217::Codes.stub(:new => iso4217) }
it 'create a ISO4217 on first call' do
- ISO4217.should_receive(:new)
+ ISO4217::Codes.should_receive(:new)
DivISOr.validate_iso4217('USD')
end
it 'delegates to the ISO4217 class' do
iso4217.should_receive(:validate).with('USD')
@@ -42,14 +42,14 @@
end
end
context 'for ISO 10383' do
let(:iso10383) { mock(:validate => true) }
- before { ISO10383.stub(:new => iso10383) }
+ before { ISO10383::Codes.stub(:new => iso10383) }
it 'create a ISO10383 on first call' do
- ISO10383.should_receive(:new)
+ ISO10383::Codes.should_receive(:new)
DivISOr.validate_iso10383('BARX')
end
it 'delegates to the ISO10383 class' do
iso10383.should_receive(:validate).with('BARX')
@@ -60,6 +60,86 @@
iso10383.should_receive(:validate).with('BARX', :code)
DivISOr.validate_iso10383('BARX', :code)
end
end
end
+
+ context 'lookup' do
+ context 'for ISO 4217' do
+ let(:iso4217) { mock(:validate => true) }
+ before { ISO4217::Codes.stub(:new => iso4217) }
+
+ it 'gets all records' do
+ iso4217.should_receive(:all).with('USD')
+ DivISOr.iso4217('USD')
+ end
+ end
+
+ context 'for ISO 3166' do
+ let(:all_records) { mock(:first => false) }
+ let(:iso3166) { mock(:validate => true, :all => all_records) }
+ before { ISO3166::Codes.stub(:new => iso3166) }
+
+ it 'gets all records' do
+ iso3166.should_receive(:all).with('US')
+ DivISOr.iso3166('US')
+ end
+
+ it 'gets the first record' do
+ all_records.should_receive(:first)
+ DivISOr.iso3166('US')
+ end
+ end
+
+ context 'for ISO 10383' do
+ let(:all_records) { mock(:first => false) }
+ let(:iso10383) { mock(:validate => true, :all => all_records) }
+ before { ISO10383::Codes.stub(:new => iso10383) }
+
+ it 'gets all records' do
+ iso10383.should_receive(:all).with('US')
+ DivISOr.iso10383('US')
+ end
+
+ it 'gets the first record' do
+ all_records.should_receive(:first)
+ DivISOr.iso10383('US')
+ end
+ end
+ end
+
+ context 'list all records' do
+ context 'for ISO 4217' do
+ let(:all_records) { mock }
+ let(:iso4217) { mock(:validate => true, :all => all_records) }
+ before { ISO4217::Codes.stub(:new => iso4217) }
+
+ it 'gets all records' do
+ iso4217.should_receive(:all).with(nil)
+ DivISOr.list_iso4217.should == all_records
+ end
+ end
+
+ context 'for ISO 3166' do
+ let(:all_records) { mock }
+ let(:iso3166) { mock(:validate => true, :all => all_records) }
+ before { ISO3166::Codes.stub(:new => iso3166) }
+
+ it 'gets all records' do
+ iso3166.should_receive(:all).with(nil)
+ DivISOr.list_iso3166.should == all_records
+ end
+ end
+
+ context 'for ISO 10383' do
+ let(:all_records) { mock }
+ let(:iso10383) { mock(:validate => true, :all => all_records) }
+ before { ISO10383::Codes.stub(:new => iso10383) }
+
+ it 'gets all records' do
+ iso10383.should_receive(:all).with(nil)
+ DivISOr.list_iso10383.should == all_records
+ end
+ end
+ end
end
+