Rails & RSpec - Testing Concerns class methods

前端 未结 5 877
面向向阳花
面向向阳花 2020-12-14 17:09

I have the following (simplified) Rails Concern:

module HasTerms
  extend ActiveSupport::Concern

  module ClassMethods
    def optional_agreement
      # At         


        
5条回答
  •  情话喂你
    2020-12-14 17:54

    You could just test the module implicitly by leaving your tests in the classes that include this module. Alternatively, you can include other requisite modules in your dummy class. For instance, the validates methods in AR models are provided by ActiveModel::Validations. So, for your tests:

    class DummyClass
      include ActiveModel::Validations
      include HasTerms
    end
    

    There may be other modules you need to bring in based on dependencies you implicitly rely on in your HasTerms module.

提交回复
热议问题