Ruby on rails 为什么在RSPEC中为调用包含模块中的方法而未定义方法?

Ruby on rails 为什么在RSPEC中为调用包含模块中的方法而未定义方法?,ruby-on-rails,ruby-on-rails-3,rspec,Ruby On Rails,Ruby On Rails 3,Rspec,在我们的rails 3.2.12应用程序中,模型项目需要在authenticify引擎中的模块authenticify\u utility.rb中使用方法find\u config\u const。在模型项目中,因此 include Authentify::AuthentifyUtility 方法find\u config\u const在model project中调用为: validates :sales_id, :presence => true,

在我们的rails 3.2.12应用程序中,
模型项目
需要在
authenticify
引擎中的模块
authenticify\u utility.rb
中使用方法
find\u config\u const
。在
模型项目中
,因此

include Authentify::AuthentifyUtility 
方法
find\u config\u const
model project
中调用为:

validates :sales_id, :presence => true,
                       :numericality => {:greater_than => 0} if find_config_const('project_has_sales', 'projectx') == 'true'
以下是rspec中的错误:

project.rb:51:in `<class:Project>': undefined method `find_config_const' for Authentify::AuthentifyUtility:Module (NoMethodError)
除此rspec错误外,执行代码时没有错误。如何修复rspec的此错误?这是rspec中的错误吗?谢谢你的帮助

更新:

方法的定义

def find_config_const(param_name, engine=nil, version=nil)
      const_value = nil
      engineConfig = Authentify::EngineConfig.where(:engine_name => engine, :engine_version => version, :argument_name => param_name).first() if engine.present? && version.present?
      engineConfig = Authentify::EngineConfig.where(:engine_name => engine, :argument_name => param_name).first() if engine.present? && version.blank?
      engineConfig = Authentify::EngineConfig.where(:argument_name => param_name).first() if engine.blank? && version.blank?
      const_value = engineConfig.argument_value unless  engineConfig.nil?
      const_value
end

你能展示一下
find\u config\u const
的定义吗


在没有看到它的情况下,我的最佳猜测是,您不应该使用模块名调用该方法,因为您已将其包含在您的模型中

您必须在
spec\u helper.rb
或您的规范中要求模块:

require 'authentify/authentify_utility'

刚刚用方法的定义更新了帖子。方法是从db中检索一个值。谢谢。我不知道它在rspec之外是如何工作的,但是在您的模型中尝试一下:
如果find\u config\u const('project\u has\u sales','projectx')='true'
我看到了问题:模型中不包含模块
require
在文件顶部,然后以最初的方式调用该方法:
Authentify::AuthentifyUtility。查找\u config\u const
相同的错误。我们所做的是将一个方法validate_sales定义为:def validate_sales return find_config_const('project_has_sales','projectx')=='true'end,并使其符合以下条件:validate_sales。不知何故,对方法的调用会在方法中查找\u config\u const。不知道为什么。但它是有效的。
require 'authentify/authentify_utility'