def set_tester_connector(klass) define_method :tester_connector_class do klass end include_context 'with tester connector' end RSpec.shared_context 'with tester connector' do before(:all) do @connector = described_class.new(SpecSupport.db) @tester_connector = tester_connector_class.new @tester_connector.cleanup end after(:all){ @tester_connector.cleanup } end RSpec.shared_context 'cleanup after all', cleanup_after: :all do after(:all){ @tester_connector.cleanup } end RSpec.shared_context 'cleanup after each', cleanup_after: :each do after { @tester_connector.cleanup } end