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