Module: Kensho::RSpec::GroupTracker

Defined in:
lib/kensho/rspec/helpers.rb

Overview

Hook RSpec’s example-group definition so Kensho::Feature/Epic/Story can find the group whose describe block is currently executing. We override ‘module_exec` on the freshly-built subclass to push the class onto a tracking stack while RSpec evaluates the user body.

Instance Method Summary collapse

Instance Method Details

#subclass(parent, description, args, registration_collection, &example_group_block) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/kensho/rspec/helpers.rb', line 166

def subclass(parent, description, args, registration_collection, &example_group_block)
  wrapped = nil
  if example_group_block
    tracker = Kensho::RSpec::State
    wrapped = lambda do |*lambda_args|
      tracker.push_group(self)
      begin
        instance_exec(*lambda_args, &example_group_block)
      ensure
        tracker.pop_group
      end
    end
  end
  super(parent, description, args, registration_collection, &(wrapped || example_group_block))
end