How to use generateRegistration method of org.spekframework.spek2.kotlin.SpekExtension class

Best Spek code snippet using org.spekframework.spek2.kotlin.SpekExtension.generateRegistration

SpekExtension.kt

Source:SpekExtension.kt Github

copy

Full Screen

...44class SpekExtension : IrGenerationExtension {45 override fun generate(file: IrFile, backendContext: BackendContext, bindingContext: BindingContext) {46 val spekCollector = SpekCollector(file, backendContext)47 file.acceptChildrenVoid(spekCollector)48 spekCollector.generateRegistrations()49 }50}51private class SpekCollector(52 private val file: IrFile,53 private val backendContext: BackendContext54) : IrElementVisitorVoid {55 private val spekClassName = "org.spekframework.spek2.Spek"56 private val commonContext: CommonBackendContext = backendContext.ir.context57 private var collectedSpeks = mutableListOf<IrClass>()58 override fun visitElement(element: IrElement) {59 element.acceptChildrenVoid(this)60 }61 override fun visitClass(declaration: IrClass) {62 super.visitClass(declaration)63 if (!declaration.isSpek) {64 return65 }66 if (declaration.kind != ClassKind.OBJECT) {67 if (!declaration.isAbstract) {68 commonContext.reportWarning("Declaration ${declaration.name} inherits from $spekClassName but is not an object (it has kind ${declaration.kind}) and so will be not be run.", file, declaration)69 }70 return71 }72 collectedSpeks.add(declaration)73 }74 fun generateRegistrations() {75 collectedSpeks.forEach { generateRegistration(it) }76 }77 // All of this is trying to create a call that looks like this:78 // registerSpek(SpecObject::class, { SpecObject })79 private fun generateRegistration(declaration: IrClass) {80 // TODO: is this the correct way to find the package? This works, but it feels wrong.81 val launcherPackage = backendContext.builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf("org", "spekframework", "spek2", "launcher")))82 val registrationFunction = launcherPackage.memberScope.getContributedFunctions(Name.identifier("registerSpek"), NoLookupLocation.FROM_BACKEND)83 .single()84 val registrationFunctionSymbol = backendContext.ir.symbols85 .externalSymbolTable.referenceSimpleFunction(registrationFunction)86 val classSymbol = declaration.symbol87 commonContext.createIrBuilder(file.symbol, file.startOffset, file.endOffset).run {88 val call = irCall(registrationFunctionSymbol).apply {89 // TODO: should both of the IrType parameters below be declaration.defaultType?90 // Should one be the equivalent of KClass<Spek> or KClass<DerivedSpek>?91 val classReference = IrClassReferenceImpl(startOffset, endOffset, declaration.defaultType, classSymbol, declaration.defaultType)92 putValueArgument(0, classReference)93 val factoryType = registrationFunctionSymbol.owner.valueParameters[1].type...

Full Screen

Full Screen

generateRegistration

Using AI Code Generation

copy

Full Screen

1import org.spekframework.spek2.Spek2import org.spekframework.spek2.SpekExtension3import org.spekframework.spek2.lifecycle.CachingMode4import org.spekframework.spek2.lifecycle.GroupScope5import org.spekframework.spek2.lifecycle.GroupScopeImpl6import org.spekframework.spek2.lifecycle.LifecycleListener7import org.spekframework.spek2.lifecycle.LifecycleListenerAdapter8import org.spekframework.spek2.lifecycle.MemoizedValue9import org.spekframework.spek2.lifecycle.MemoizedValueImpl10import org.spekframework.spek2.lifecycle.ScopeImpl11import org.spekframework.spek2.lifecycle.TestScope12import org.spekframework.spek2.lifecycle.TestScopeImpl13import org.spekframework.spek2.style.specification.describe14import kotlin.reflect.KClass15class MemoizedValueTest : Spek({16 val memoizedValue = MemoizedValueImpl<String>()17 val memoizedValue2 = MemoizedValueImpl<String>()18 val memoizedValue3 = MemoizedValueImpl<String>()19 val memoizedValue4 = MemoizedValueImpl<String>()20 val memoizedValue5 = MemoizedValueImpl<String>()21 val memoizedValue6 = MemoizedValueImpl<String>()22 val memoizedValue7 = MemoizedValueImpl<String>()23 val memoizedValue8 = MemoizedValueImpl<String>()24 val memoizedValue9 = MemoizedValueImpl<String>()25 val memoizedValue10 = MemoizedValueImpl<String>()26 val memoizedValue11 = MemoizedValueImpl<String>()27 val memoizedValue12 = MemoizedValueImpl<String>()28 val memoizedValue13 = MemoizedValueImpl<String>()29 val registration = SpekExtension.generateRegistration {30 group("group 1") {31 memoizedValue = memoizedValue()32 memoizedValue2 = memoizedValue()33 memoizedValue3 = memoizedValue()34 memoizedValue4 = memoizedValue()35 memoizedValue5 = memoizedValue()36 memoizedValue6 = memoizedValue()37 memoizedValue7 = memoizedValue()38 memoizedValue8 = memoizedValue()39 memoizedValue9 = memoizedValue()40 memoizedValue10 = memoizedValue()41 memoizedValue11 = memoizedValue()42 memoizedValue12 = memoizedValue()43 memoizedValue13 = memoizedValue()

Full Screen

Full Screen

generateRegistration

Using AI Code Generation

copy

Full Screen

1 def registration = org.spekframework.spek2.kotlin.SpekExtension.generateRegistration()2 def runtime = new org.spekframework.spek2.runtime.SpekRuntime()3 runtime.run(registration, null, null)4}5dependencies {6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Spek automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful