0

在我们的 rails 3.2.12 应用程序中,model project需要在引擎find_config_const的模块中使用方法。中,所以有authentify_utility.rbauthentifymodel project

include Authentify::AuthentifyUtility 

该方法find_config_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)

在模块 authentify_utility 中,在方法定义之后,方法 find_config_const 的模块函数声明为(使该方法可供其他人使用):

module_function :find_config_const

除了这个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
4

2 回答 2

1

您必须在规范中或规范中要求该模块spec_helper.rb

require 'authentify/authentify_utility'
于 2013-05-20T15:38:55.223 回答
1

你能说明 的定义find_config_const吗?

没有看到它,我最好的猜测是您不应该使用模块名称调用该方法,因为您在模型中#include 了它。

于 2013-05-20T04:25:51.987 回答