Class: Plok::Engine
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- Plok::Engine
- Defined in:
- lib/plok/engine.rb
Instance Method Summary collapse
- #class_exists?(class_name) ⇒ Boolean
-
#load_spec_supports ⇒ Object
You can call this in your spec/rails_helper.rb file so you can make use of the spec supports to test concerns.
- #module_exists?(module_name) ⇒ Boolean
Instance Method Details
#class_exists?(class_name) ⇒ Boolean
22 23 24 25 26 27 |
# File 'lib/plok/engine.rb', line 22 def class_exists?(class_name) klass = Module.const_get(class_name.to_s) klass.is_a?(Class) rescue NameError return false end |
#load_spec_supports ⇒ Object
You can call this in your spec/rails_helper.rb file so you can make use of the spec supports to test concerns.
You cannot call it in the engine itself, because RSpec won’t have the same context available when tests are ran.
42 43 44 |
# File 'lib/plok/engine.rb', line 42 def load_spec_supports Dir.glob("#{root}/spec/{factories,support}/**/*.rb").sort.each { |f| require f } end |
#module_exists?(module_name) ⇒ Boolean
29 30 31 32 33 34 35 |
# File 'lib/plok/engine.rb', line 29 def module_exists?(module_name) # By casting to a string and making a constant, we can assume module_name # can be either one without it being a problem. module_name.to_s.constantize.is_a?(Module) rescue NameError return false end |