2016-03-30 14 views
0

我在寫測試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。

我該如何阻止此錯誤?

任何幫助非常感謝:)

+0

在通過控制檯創建組織時是否出現此錯誤? – KPheasey

+0

Gem文件中是否列出了您的測試組中的Gem? –

+0

@ChrisBlunt不,但它現在和我得到相同的消息 – tonyedwardspz

回答

1

看起來不像是要求錯誤。它無法找到full_valid?方法在UKPostcode :: GeographicPostcode對象的實例上。這可能是因爲你的寶石版本沒有這個方法。

看看here看看你如何驗證它。打開控制檯並創建一個新的UKPostcode :: GeographicPostcode對象並驗證該方法是否存在。

+0

您是對的。更新寶石到最新版本解決了這個問題。非常感謝 – tonyedwardspz

相關問題