diff --git a/lib/correios/cep/address.rb b/lib/correios/cep/address.rb index dea08b9..e39055e 100644 --- a/lib/correios/cep/address.rb +++ b/lib/correios/cep/address.rb @@ -12,6 +12,8 @@ class Address element :complemento2, as: :complement2 def ==(other) + return false unless other.is_a?(self.class) + instance_variables.each do |attr| return false unless self.instance_variable_get(attr) == other.instance_variable_get(attr) end diff --git a/spec/correios/cep/address_spec.rb b/spec/correios/cep/address_spec.rb index ea2e33c..64a7a7b 100644 --- a/spec/correios/cep/address_spec.rb +++ b/spec/correios/cep/address_spec.rb @@ -43,6 +43,15 @@ it { should be false } end + + context 'when compares with other kind of object' do + subject do + address = described_class.new + address == :address + end + + it { should be false } + end end describe '#has_content?' do