How to mix a module into an rspec context

后端 未结 2 645
遇见更好的自我
遇见更好的自我 2021-02-02 17:49

How can I mix a module into an rspec context (aka describe), such that the module\'s constants are available to the spec?

module Foo
  FOO = 1
end

         


        
2条回答
  •  旧时难觅i
    2021-02-02 18:21

    You can use RSpec's shared_context:

    shared_context 'constants' do
      FOO = 1
    end
    
    describe Model do
      include_context 'constants'
    
      p FOO    # => 1
    end
    

提交回复
热议问题