Class: Karafka::Core::Helpers::MinitestLocator
- Inherits:
-
Module
- Object
- Module
- Karafka::Core::Helpers::MinitestLocator
- Defined in:
- lib/karafka/core/helpers/minitest_locator.rb
Overview
Minitest/spec extension for the subject class auto-discovery. It automatically detects the class name that should be described in the given test based on the test file path.
Instance Method Summary collapse
-
#extended(minitest_module) ⇒ Object
Builds needed API.
-
#inherited ⇒ Class
Class name for the minitest ‘describe` method.
-
#initialize(test_helper_file_path, inflections = {}) ⇒ MinitestLocator
constructor
A new instance of MinitestLocator.
Constructor Details
#initialize(test_helper_file_path, inflections = {}) ⇒ MinitestLocator
Returns a new instance of MinitestLocator.
14 15 16 17 18 |
# File 'lib/karafka/core/helpers/minitest_locator.rb', line 14 def initialize(test_helper_file_path, inflections = {}) super() @inflections = inflections @tests_root_dir = ::File.dirname(test_helper_file_path) end |
Instance Method Details
#extended(minitest_module) ⇒ Object
Builds needed API
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/karafka/core/helpers/minitest_locator.rb', line 22 def extended(minitest_module) super this = self # Allows "auto subject" definitions for the `describe` method, as it will figure # out the proper class that we want to describe # @param block [Proc] block with tests minitest_module.define_singleton_method :describe_current do |&block| describe(this.inherited, &block) end end |
#inherited ⇒ Class
Returns class name for the minitest ‘describe` method.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/karafka/core/helpers/minitest_locator.rb', line 34 def inherited caller(2..2) .first .split(":") .first .gsub(@tests_root_dir, "") .gsub("_test.rb", "") .split("/") .delete_if(&:empty?) .itself[1..] .join("/") .then { |path| custom_camelize(path) } .then { |string| transform_inflections(string) } .then { |class_name| custom_constantize(class_name) } end |