Permalink
Browse files

Improve tests

  • Loading branch information...
1 parent b10cc3a commit 96e02d1ed1dcc92bb1234e5116645d073280984f Neil Middleton committed Jan 4, 2012
Showing with 31 additions and 0 deletions.
  1. +31 −0 spec/vatman_spec.rb
View
@@ -2,23 +2,54 @@
describe Vatman 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.should be_valid
v.name.should == 'KYANMEDIA LTD'
v.address.should == "171 HIGH STREET\nGUILDFORD\nSURREY\n\n\nGU1 3AJ"
end
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.should be_valid
end
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.should_not be_valid
end
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.should_not be_valid
end

0 comments on commit 96e02d1

Please sign in to comment.