mardi 10 juillet 2018

RSpec: How to properly test class method that loops through a collection / calls instance method

Consider the following class and class method:

class Foo < ActiveRecord::Base
    scope :active, -> { where(deleted: false) }

    class << self
      def some_class_method
        active.each do |foo|
          foo.some_instance_method
        end
      end
    end
end

what is the best practice to test such a method in RSpec? What I have learned thus far suggests that I should make sure that each active instance of Foo receives a call to some_instance_method, but if I were to make an expectation regarding Foo.some_class_method, to my knowledge I cannot assert a nested expectation about any instance of Foo.

Any help would be appreciated!!

Aucun commentaire:

Enregistrer un commentaire