tonyedwardspz
tonyedwardspz

Reputation: 1885

Tests failing because a gems method is undefined

I'm writing tests for a rails application and keep getting the following error, which is related to this UK postcode validator gem:

Error:
    OrganisationsControllerTest#test_0001_should get index:
    NoMethodError: undefined method `full_valid?' for # <UKPostcode::GeographicPostcode:0x007fe405e6caf8>
app/validators/postcode_validator.rb:4:in `validate_each'
test/controllers/organisations_controller_test.rb:7:in `block in <class:OrganisationsControllerTest>'

The error is refering to the line where FactoryGirl instantiates and object for use in the tests. This is the factory used:

FactoryGirl.define do
  factory :organisation do
    name 'Acme Corp'
    address_1 'Acme House'
    address_2 '40 - 44 Harvard Road'
    address_3 'Archingdon'
    town 'Exeter'
    postcode 'EX4 6PX'
    phone_number '03309 890890'
    email '[email protected]'
    linkedin_url 'https://linkedin.com/acmecorp'
    twitter_handle 'acmecorp'
    facebook_url 'https://facebook.com/acmecorp'
    website 'https://www.acmecopr.com'
  end
end

I assume the error is because I need to require the library somewhere, but I can't seem to find the right place. So far I have added require 'uk_postcode' to the file the factory is defined in, the failing controller test class and test_helper.rb.

How can I stop this error?

Any help much appreciated :)

Upvotes: 0

Views: 42

Answers (1)

Shishir
Shishir

Reputation: 780

Doesn't look like require error. It is unable to find full_valid? method on the instance of UKPostcode::GeographicPostcode object. It can be because of the version of gem you have doesn't have this method.

Look here to see how you can verify it. Open console and create a new UKPostcode::GeographicPostcode object and verify if the method exists.

Upvotes: 1

Related Questions