Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Rspec中测试嵌套类方法_Ruby On Rails_Rspec - Fatal编程技术网

Ruby on rails 在Rspec中测试嵌套类方法

Ruby on rails 在Rspec中测试嵌套类方法,ruby-on-rails,rspec,Ruby On Rails,Rspec,有没有办法测试从另一个类方法调用的类方法是否存在 class AnimalRecord < ApplicationRecord COLLAR_ID = AnimalCollar::ID belongs_to :animal serialize :json, JSON scope :collar_id, -> { for_collar(COLLAR_ID) } def self.current_record(animal) animal_info = An

有没有办法测试从另一个类方法调用的类方法是否存在

class AnimalRecord < ApplicationRecord
  COLLAR_ID = AnimalCollar::ID
  belongs_to :animal
  serialize :json, JSON
  scope :collar_id, -> { for_collar(COLLAR_ID) }

  def self.current_record(animal)
    animal_info = AnimalRecord.collar_id.first
    calculate_nutrients(animal_info)
  end

  def self.calculate_nutrients(animal)
    code result
  end
end
但我得到一个错误,上面写着:

    expected: 1 time with any arguments
       received: 0 times with any arguments

我认为您已经删除了expect(AnimalRecord.)这一行,以便从测试示例中接收(:event)。似乎在
AnimalRecord
上没有定义这样的方法,但您正试图“期望”它。

您需要将您的期望置于您的行动之上。现在你正站在一个公共汽车站,这时公共汽车已经经过了。(在您创建您的期望之前已调用该操作)@engineersmnky我输入了一个错误。谢谢,它在没有
的情况下工作吗?返回
?正是这个
期望(动物记录)。要接收(:计算营养素)
?@ka8725,它需要返回工作。谢谢
    expected: 1 time with any arguments
       received: 0 times with any arguments