测试失败,因为未定义 gems 方法
Tests failing because a gems method is undefined
我正在为 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 'hello@acme.com'
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'
添加到定义工厂的文件中,失败的控制器测试 class 和 test_helper.rb.
我怎样才能阻止这个错误?
非常感谢任何帮助:)
看起来不像 require 错误。找不到full_valid? UKPostcode::GeographicPostcode 对象实例上的方法。可能是你的gem版本没有这个方法。
查看 here 以了解如何验证它。打开控制台并创建一个新的
UKPostcode::GeographicPostcode 对象并验证该方法是否存在。
我正在为 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 'hello@acme.com'
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'
添加到定义工厂的文件中,失败的控制器测试 class 和 test_helper.rb.
我怎样才能阻止这个错误?
非常感谢任何帮助:)
看起来不像 require 错误。找不到full_valid? UKPostcode::GeographicPostcode 对象实例上的方法。可能是你的gem版本没有这个方法。
查看 here 以了解如何验证它。打开控制台并创建一个新的 UKPostcode::GeographicPostcode 对象并验证该方法是否存在。