Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Middleton committed Jan 4, 2012
1 parent b10cc3a commit 96e02d1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/vatman_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,23 +2,54 @@


describe Vatman do describe Vatman do
it 'should return details of a valid VAT number' do it 'should return details of a valid VAT number' do

cl = {}
resp = {}
resp[:check_vat_response] = {}
resp[:check_vat_response][:valid] = true
resp[:check_vat_response][:name] = "KYANMEDIA LTD"
resp[:check_vat_response][:address] = "171 HIGH STREET\nGUILDFORD\nSURREY\n\n\nGU1 3AJ"
cl.stub(:request){resp}
Savon::Client.stub(:new){cl}

v = Vatman::Check.new("GB", 800634860) v = Vatman::Check.new("GB", 800634860)
v.should be_valid v.should be_valid
v.name.should == 'KYANMEDIA LTD' v.name.should == 'KYANMEDIA LTD'
v.address.should == "171 HIGH STREET\nGUILDFORD\nSURREY\n\n\nGU1 3AJ" v.address.should == "171 HIGH STREET\nGUILDFORD\nSURREY\n\n\nGU1 3AJ"
end end


it 'should accept string formatted numbers' do it 'should accept string formatted numbers' do
cl = {}
resp = {}
resp[:check_vat_response] = {}
resp[:check_vat_response][:valid] = true
cl.stub(:request).with(:tnsl, :check_vat, :body => {:country_code => "GB", :vat_number => "800634860"}){resp}
Savon::Client.stub(:new){cl}

v = Vatman::Check.new("GB", "800 6348 60") v = Vatman::Check.new("GB", "800 6348 60")
v.should be_valid v.should be_valid
end end


it 'should reject invalid VAT numbers' do it 'should reject invalid VAT numbers' do
cl = {}
resp = {}
resp[:check_vat_response] = {}
resp[:check_vat_response][:valid] = false
cl.stub(:request).with(:tnsl, :check_vat, :body => {:country_code => "GB", :vat_number => "12345679"}){resp}
Savon::Client.stub(:new){cl}

v = Vatman::Check.new("GB", 12345679) v = Vatman::Check.new("GB", 12345679)
v.should_not be_valid v.should_not be_valid
end end


it 'should reject invalid string vat numbers' do it 'should reject invalid string vat numbers' do
cl = {}
resp = {}
resp[:check_vat_response] = {}
resp[:check_vat_response][:valid] = false
cl.stub(:request).with(:tnsl, :check_vat, :body => {:country_code => "GB", :vat_number => "abcdefghijkl"}){resp}
Savon::Client.stub(:new){cl}

v = Vatman::Check.new("GB", "abcdefghijkl") v = Vatman::Check.new("GB", "abcdefghijkl")
v.should_not be_valid v.should_not be_valid
end end
Expand Down

0 comments on commit 96e02d1

Please sign in to comment.