我在寫測試Rails應用程序,並不斷收到以下錯誤,這是關係到這個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>'
的誤差指的所在行FactoryGirl在測試中實例化和使用對象。這是工廠使用:
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
我假設的錯誤是因爲我需要在一些地方require
庫中,但我似乎無法找到合適的地方。到目前爲止,我已將require 'uk_postcode'
添加到工廠定義的文件中,失敗的控制器測試類和test_helper.rb。
我該如何阻止此錯誤?
任何幫助非常感謝:)
在通過控制檯創建組織時是否出現此錯誤? – KPheasey
Gem文件中是否列出了您的測試組中的Gem? –
@ChrisBlunt不,但它現在和我得到相同的消息 – tonyedwardspz