Class: Karafka::Core::Helpers::RSpecLocator
- Inherits:
-
Module
- Object
- Module
- Karafka::Core::Helpers::RSpecLocator
- Defined in:
- lib/karafka/core/helpers/rspec_locator.rb
Overview
RSpec extension for the RSpec.describe
subject class auto-discovery It automatically detects the class name that should be described in the given spec based on the spec file path.
Instance Method Summary collapse
-
#extended(rspec) ⇒ Object
Builds needed API.
-
#inherited ⇒ Class
Class name for the RSpec
#describe
method. -
#initialize(spec_helper_file_path, inflections = {}) ⇒ RSpecLocator
constructor
A new instance of RSpecLocator.
Constructor Details
#initialize(spec_helper_file_path, inflections = {}) ⇒ RSpecLocator
Returns a new instance of RSpecLocator.
17 18 19 20 21 |
# File 'lib/karafka/core/helpers/rspec_locator.rb', line 17 def initialize(spec_helper_file_path, inflections = {}) super() @inflections = inflections @specs_root_dir = ::File.dirname(spec_helper_file_path) end |
Instance Method Details
#extended(rspec) ⇒ Object
Builds needed API
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/karafka/core/helpers/rspec_locator.rb', line 25 def extended(rspec) 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 specs rspec.define_singleton_method :describe_current do |&block| describe(this.inherited, &block) end end |
#inherited ⇒ Class
Returns class name for the RSpec #describe
method.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/karafka/core/helpers/rspec_locator.rb', line 39 def inherited caller(2..2) .first .split(':') .first .gsub(@specs_root_dir, '') .gsub('_spec.rb', '') .split('/') .delete_if(&:empty?) .itself[1..] .join('/') .camelize .then { |string| transform_inflections(string) } .constantize end |