How to use Collector class of org.spekframework.spek2.runtime package

Best Spek code snippet using org.spekframework.spek2.runtime.Collector

EnvironmentTelemetryCollectorSpec.kt

Source:EnvironmentTelemetryCollectorSpec.kt Github

copy

Full Screen

...30import org.spekframework.spek2.style.specification.Suite31import org.spekframework.spek2.style.specification.describe32import java.lang.management.RuntimeMXBean33import java.util.Properties34object EnvironmentTelemetryCollectorSpec : Spek({35 describe("an environment telemetry collector") {36 val telemetrySessionBuilder by createForEachTest { mock<TelemetrySessionBuilder>() }37 val gitClient by createForEachTest { mock<GitClient>() }38 val systemProperties by createForEachTest { Properties() }39 val ciEnvironmentDetector by createForEachTest {40 mock<CIEnvironmentDetector> {41 on { detect() } doReturn CIDetectionResult(false, null)42 }43 }44 val consoleInfo by createForEachTest {45 mock<ConsoleInfo> {46 on { stdinIsTTY } doReturn false47 on { stdoutIsTTY } doReturn true48 on { supportsInteractivity } doReturn true49 }50 }51 val systemInfo by createForEachTest {52 mock<SystemInfo> {53 on { osArchitecture } doReturn "x86_64"54 on { osName } doReturn "My Cool OS"55 on { osVersion } doReturn "2020.08"56 on { osDetails } doReturn "Ubuntu Linux 20.04"57 }58 }59 val runtimeMXBean by createForEachTest {60 mock<RuntimeMXBean> {61 on { startTime } doReturn 1597138787193 // 2020-08-11T09:39:47.193Z62 }63 }64 val commandType = VersionInfoCommand::class65 beforeEachTest {66 systemProperties.setProperty("java.vendor", "JVMs R Us")67 systemProperties.setProperty("java.version", "2020.1")68 systemProperties.setProperty("java.vm.name", "64-Bit Server VM")69 }70 fun Suite.createEnvironmentCollector(hostEnvironmentVariables: HostEnvironmentVariables, commandLineOptions: CommandLineOptions = CommandLineOptions()) =71 createForEachTest { EnvironmentTelemetryCollector(telemetrySessionBuilder, hostEnvironmentVariables, gitClient, consoleInfo, commandLineOptions, ciEnvironmentDetector, systemInfo, runtimeMXBean, systemProperties) }72 given("the SHELL environment variable is set") {73 val shell = "/usr/local/bin/my-awesome-shell"74 given("the TERM environment variable is set") {75 val term = "xterm-9000color"76 given("the BATECT_WRAPPER_DID_DOWNLOAD environment variable is set to 'true'") {77 val didDownload = "true"78 val hostEnvironmentVariables = HostEnvironmentVariables("SHELL" to shell, "TERM" to term, "BATECT_WRAPPER_DID_DOWNLOAD" to didDownload)79 given("the command line options have their default values") {80 val commandLineOptions = CommandLineOptions()81 val environmentCollector by createEnvironmentCollector(hostEnvironmentVariables, commandLineOptions)82 given("the Git version is available") {83 beforeEachTest {84 whenever(gitClient.version).doReturn(GitVersionRetrievalResult.Succeeded("1.2.3"))85 }86 given("a CI system is not detected") {87 beforeEachTest {88 environmentCollector.collect(commandType)89 }90 it("reports the user's shell, taking only the last segment of the path") {91 verify(telemetrySessionBuilder).addAttribute("shell", "my-awesome-shell")92 }93 it("reports the user's terminal") {94 verify(telemetrySessionBuilder).addAttribute("terminal", "xterm-9000color")95 }96 it("reports the Git version") {97 verify(telemetrySessionBuilder).addAttribute("gitVersion", "1.2.3")98 }99 it("reports details of the operating system") {100 verify(telemetrySessionBuilder).addAttribute("osName", "My Cool OS")101 verify(telemetrySessionBuilder).addAttribute("osVersion", "2020.08")102 verify(telemetrySessionBuilder).addAttribute("osArchitecture", "x86_64")103 verify(telemetrySessionBuilder).addAttribute("osDetails", "Ubuntu Linux 20.04")104 }105 it("reports details of the JVM") {106 verify(telemetrySessionBuilder).addAttribute("jvmVendor", "JVMs R Us")107 verify(telemetrySessionBuilder).addAttribute("jvmName", "64-Bit Server VM")108 verify(telemetrySessionBuilder).addAttribute("jvmVersion", "2020.1")109 }110 it("reports the type of command being run") {111 verify(telemetrySessionBuilder).addAttribute("commandType", "VersionInfoCommand")112 }113 it("reports that the wrapper downloaded the JAR for this invocation") {114 verify(telemetrySessionBuilder).addAttribute("wrapperDidDownload", true)115 }116 it("reports the time the JVM started, in UTC") {117 verify(telemetrySessionBuilder).addAttribute("jvmStartTime", "2020-08-11T09:39:47.193Z")118 }119 it("reports whether stdin is a TTY") {120 verify(telemetrySessionBuilder).addAttribute("stdinIsTTY", false)121 }122 it("reports whether stdout is a TTY") {123 verify(telemetrySessionBuilder).addAttribute("stdoutIsTTY", true)124 }125 it("reports whether interactivity is supported") {126 verify(telemetrySessionBuilder).addAttribute("consoleSupportsInteractivity", true)127 }128 it("reports that a custom configuration file name is not being used") {129 verify(telemetrySessionBuilder).addAttribute("usingNonDefaultConfigurationFileName", false)130 }131 it("reports that a config variables file is not being used") {132 verify(telemetrySessionBuilder).addAttribute("usingConfigVariablesFile", false)133 }134 it("reports the requested output style") {135 verify(telemetrySessionBuilder).addAttribute("requestedOutputStyle", null as String?)136 }137 it("reports that color output has not been disabled") {138 verify(telemetrySessionBuilder).addAttribute("colorOutputDisabled", false)139 }140 it("reports that update notifications have not been disabled") {141 verify(telemetrySessionBuilder).addAttribute("updateNotificationsDisabled", false)142 }143 it("reports that wrapper cache cleanup has not been disabled") {144 verify(telemetrySessionBuilder).addAttribute("wrapperCacheCleanupDisabled", false)145 }146 it("reports that cleanup after success has not been disabled") {147 verify(telemetrySessionBuilder).addAttribute("cleanupAfterSuccessDisabled", false)148 }149 it("reports that cleanup after failure has not been disabled") {150 verify(telemetrySessionBuilder).addAttribute("cleanupAfterFailureDisabled", false)151 }152 it("reports that proxy environment variable propagation has not been disabled") {153 verify(telemetrySessionBuilder).addAttribute("proxyEnvironmentVariablePropagationDisabled", false)154 }155 it("reports the number of additional task command arguments") {156 verify(telemetrySessionBuilder).addAttribute("additionalTaskCommandArgumentCount", 0)157 }158 it("reports the number of command line config variable overrides") {159 verify(telemetrySessionBuilder).addAttribute("commandLineConfigVariableOverrideCount", 0)160 }161 it("reports the number of command line image overrides") {162 verify(telemetrySessionBuilder).addAttribute("commandLineImageOverrideCount", 0)163 }164 it("reports that TLS is not being used for the connection to Docker") {165 verify(telemetrySessionBuilder).addAttribute("usingTLSForDockerConnection", false)166 }167 it("reports that TLS is not being verified for the connection to Docker") {168 verify(telemetrySessionBuilder).addAttribute("verifyingTLSForDockerConnection", false)169 }170 it("reports that an existing Docker network is not being used") {171 verify(telemetrySessionBuilder).addAttribute("usingExistingDockerNetwork", false)172 }173 it("reports that prerequisites are not being skipped") {174 verify(telemetrySessionBuilder).addAttribute("skippingPrerequisites", false)175 }176 it("reports that no maximum level of parallelism is set") {177 verify(telemetrySessionBuilder).addAttribute("maximumLevelOfParallelism", null as Int?)178 }179 it("reports that no CI system was detected") {180 verify(telemetrySessionBuilder).addAttribute("suspectRunningOnCI", false)181 verify(telemetrySessionBuilder).addAttribute("suspectedCISystem", null as String?)182 }183 }184 given("a CI system is detected") {185 beforeEachTest {186 whenever(ciEnvironmentDetector.detect()).doReturn(CIDetectionResult(true, "My CI System"))187 environmentCollector.collect(commandType)188 }189 it("reports that a CI system was detected") {190 verify(telemetrySessionBuilder).addAttribute("suspectRunningOnCI", true)191 }192 it("reports the CI system name") {193 verify(telemetrySessionBuilder).addAttribute("suspectedCISystem", "My CI System")194 }195 }196 }197 given("the Git version is not available") {198 beforeEachTest {199 whenever(gitClient.version).doReturn(GitVersionRetrievalResult.Failed("Something went wrong."))200 environmentCollector.collect(commandType)201 }202 it("reports the Git version as unknown") {203 verify(telemetrySessionBuilder).addNullAttribute("gitVersion")204 }205 }206 }207 given("the command line options do not have their default values") {208 val commandLineOptions = CommandLineOptions(209 configurationFileName = osIndependentPath("not-batect.yml"),210 configVariablesSourceFile = osIndependentPath("some-variables.yml"),211 requestedOutputStyle = OutputStyle.Fancy,212 disableColorOutput = true,213 disableUpdateNotification = true,214 disableWrapperCacheCleanup = true,215 disableCleanupAfterSuccess = true,216 disableCleanupAfterFailure = true,217 dontPropagateProxyEnvironmentVariables = true,218 additionalTaskCommandArguments = listOf("some", "args"),219 configVariableOverrides = mapOf("var" to "value", "other-var" to "other value"),220 imageOverrides = mapOf("container-1" to "image-1"),221 dockerUseTLS = true,222 dockerVerifyTLS = true,223 existingNetworkToUse = "some-network",224 skipPrerequisites = true,225 maximumLevelOfParallelism = 3226 )227 val environmentCollector by createEnvironmentCollector(hostEnvironmentVariables, commandLineOptions)228 beforeEachTest { environmentCollector.collect(commandType) }229 it("reports that a custom configuration file name is being used") {230 verify(telemetrySessionBuilder).addAttribute("usingNonDefaultConfigurationFileName", true)231 }232 it("reports that a config variables file is being used") {233 verify(telemetrySessionBuilder).addAttribute("usingConfigVariablesFile", true)234 }235 it("reports the requested output style") {236 verify(telemetrySessionBuilder).addAttribute("requestedOutputStyle", "fancy")237 }238 it("reports that color output has been disabled") {239 verify(telemetrySessionBuilder).addAttribute("colorOutputDisabled", true)240 }241 it("reports that update notifications have been disabled") {242 verify(telemetrySessionBuilder).addAttribute("updateNotificationsDisabled", true)243 }244 it("reports that wrapper cache cleanup has been disabled") {245 verify(telemetrySessionBuilder).addAttribute("wrapperCacheCleanupDisabled", true)246 }247 it("reports that cleanup after success has been disabled") {248 verify(telemetrySessionBuilder).addAttribute("cleanupAfterSuccessDisabled", true)249 }250 it("reports that cleanup after failure has been disabled") {251 verify(telemetrySessionBuilder).addAttribute("cleanupAfterFailureDisabled", true)252 }253 it("reports that proxy environment variable propagation has been disabled") {254 verify(telemetrySessionBuilder).addAttribute("proxyEnvironmentVariablePropagationDisabled", true)255 }256 it("reports the number of additional task command arguments") {257 verify(telemetrySessionBuilder).addAttribute("additionalTaskCommandArgumentCount", 2)258 }259 it("reports the number of command line config variable overrides") {260 verify(telemetrySessionBuilder).addAttribute("commandLineConfigVariableOverrideCount", 2)261 }262 it("reports the number of command line image overrides") {263 verify(telemetrySessionBuilder).addAttribute("commandLineImageOverrideCount", 1)264 }265 it("reports that TLS is being used for the connection to Docker") {266 verify(telemetrySessionBuilder).addAttribute("usingTLSForDockerConnection", true)267 }268 it("reports that TLS is being verified for the connection to Docker") {269 verify(telemetrySessionBuilder).addAttribute("verifyingTLSForDockerConnection", true)270 }271 it("reports that an existing Docker network is being used") {272 verify(telemetrySessionBuilder).addAttribute("usingExistingDockerNetwork", true)273 }274 it("reports that prerequisites are being skipped") {275 verify(telemetrySessionBuilder).addAttribute("skippingPrerequisites", true)276 }277 it("reports the configured maximum level of parallelism") {278 verify(telemetrySessionBuilder).addAttribute("maximumLevelOfParallelism", 3)279 }280 }281 }282 given("the BATECT_WRAPPER_DID_DOWNLOAD environment variable is set to 'false'") {283 val didDownload = "false"284 val hostEnvironmentVariables = HostEnvironmentVariables("SHELL" to shell, "TERM" to term, "BATECT_WRAPPER_DID_DOWNLOAD" to didDownload)285 val environmentCollector by createEnvironmentCollector(hostEnvironmentVariables)286 beforeEachTest { environmentCollector.collect(commandType) }287 it("reports that the wrapper did not download the JAR for this invocation") {288 verify(telemetrySessionBuilder).addAttribute("wrapperDidDownload", false)289 }290 }291 given("the BATECT_WRAPPER_DID_DOWNLOAD environment variable is not set to 'true' or 'false'") {292 val didDownload = "blah"293 val hostEnvironmentVariables = HostEnvironmentVariables("SHELL" to shell, "TERM" to term, "BATECT_WRAPPER_DID_DOWNLOAD" to didDownload)294 val environmentCollector by createEnvironmentCollector(hostEnvironmentVariables)295 beforeEachTest { environmentCollector.collect(commandType) }296 it("reports the download status as unknown") {297 verify(telemetrySessionBuilder).addNullAttribute("wrapperDidDownload")298 }299 }300 given("the BATECT_WRAPPER_DID_DOWNLOAD environment variable is not set") {301 val hostEnvironmentVariables = HostEnvironmentVariables("SHELL" to shell, "TERM" to term)302 val environmentCollector by createEnvironmentCollector(hostEnvironmentVariables)303 beforeEachTest { environmentCollector.collect(commandType) }304 it("reports the download status as unknown") {305 verify(telemetrySessionBuilder).addNullAttribute("wrapperDidDownload")306 }307 }308 }309 given("the TERM environment variable is not set") {310 val hostEnvironmentVariables = HostEnvironmentVariables("SHELL" to shell)311 val environmentCollector by createEnvironmentCollector(hostEnvironmentVariables)312 beforeEachTest { environmentCollector.collect(commandType) }313 it("reports the user's terminal as unknown") {314 verify(telemetrySessionBuilder).addAttribute("terminal", null as String?)315 }316 }317 }318 given("the SHELL environment variable is not set") {319 val hostEnvironmentVariables = HostEnvironmentVariables("TERM" to "something")320 val environmentCollector by createEnvironmentCollector(hostEnvironmentVariables)321 beforeEachTest { environmentCollector.collect(commandType) }322 it("reports the user's shell as unknown") {323 verify(telemetrySessionBuilder).addAttribute("shell", null as String?)324 }325 }326 }327})...

Full Screen

Full Screen

ApplicationSpec.kt

Source:ApplicationSpec.kt Github

copy

Full Screen

...25import batect.os.SystemInfo26import batect.telemetry.AttributeValue27import batect.telemetry.CommonAttributes28import batect.telemetry.CommonEvents29import batect.telemetry.EnvironmentTelemetryCollector30import batect.telemetry.TelemetryManager31import batect.telemetry.TelemetrySessionBuilder32import batect.testutils.createForEachTest33import batect.testutils.given34import batect.testutils.logging.InMemoryLogSink35import batect.testutils.logging.hasMessage36import batect.testutils.logging.withException37import batect.testutils.logging.withSeverity38import batect.testutils.on39import batect.testutils.runForEachTest40import batect.testutils.withPlatformSpecificLineSeparator41import batect.ui.Console42import batect.ui.text.Text43import batect.wrapper.WrapperCache44import com.natpryce.hamkrest.and45import com.natpryce.hamkrest.assertion.assertThat46import com.natpryce.hamkrest.equalTo47import org.kodein.di.DI48import org.kodein.di.bind49import org.kodein.di.instance50import org.mockito.kotlin.any51import org.mockito.kotlin.doReturn52import org.mockito.kotlin.doThrow53import org.mockito.kotlin.inOrder54import org.mockito.kotlin.mock55import org.mockito.kotlin.verify56import org.mockito.kotlin.whenever57import org.spekframework.spek2.Spek58import org.spekframework.spek2.style.specification.describe59import java.io.ByteArrayOutputStream60import java.io.PrintStream61object ApplicationSpec : Spek({62 describe("an application") {63 val errorStream by createForEachTest { ByteArrayOutputStream() }64 val commandLineOptionsParser by createForEachTest { mock<CommandLineOptionsParser>() }65 val systemInfo by createForEachTest { mock<SystemInfo>() }66 val telemetrySessionBuilder by createForEachTest { mock<TelemetrySessionBuilder>() }67 val dependencies by createForEachTest {68 DI.direct {69 bind<PrintStream>(StreamType.Error) with instance(PrintStream(errorStream))70 bind<CommandLineOptionsParser>() with instance(commandLineOptionsParser)71 bind<SystemInfo>() with instance(systemInfo)72 bind<TelemetrySessionBuilder>() with instance(telemetrySessionBuilder)73 }74 }75 val application by createForEachTest { Application(dependencies) }76 val args = listOf("some-command", "some-param")77 given("the application is running on a supported operating system") {78 beforeEachTest { whenever(systemInfo.isSupportedOperatingSystem).thenReturn(true) }79 given("parsing the command line arguments succeeds") {80 val applicationInfoLogger by createForEachTest { mock<ApplicationInfoLogger>() }81 val logSink by createForEachTest { InMemoryLogSink() }82 val loggerFactory by createForEachTest {83 mock<LoggerFactory> {84 on { createLoggerForClass(Application::class) } doReturn Logger("application", logSink)85 }86 }87 val commandFactory by createForEachTest { mock<CommandFactory>() }88 val consoleManager by createForEachTest { mock<ConsoleManager>() }89 val errorConsole by createForEachTest { mock<Console>() }90 val wrapperCache by createForEachTest { mock<WrapperCache>() }91 val telemetryManager by createForEachTest { mock<TelemetryManager>() }92 val environmentTelemetryCollector by createForEachTest { mock<EnvironmentTelemetryCollector>() }93 val extendedDependencies by createForEachTest {94 DI.direct {95 bind<ApplicationInfoLogger>() with instance(applicationInfoLogger)96 bind<LoggerFactory>() with instance(loggerFactory)97 bind<CommandFactory>() with instance(commandFactory)98 bind<Console>(StreamType.Error) with instance(errorConsole)99 bind<ConsoleManager>() with instance(consoleManager)100 bind<WrapperCache>() with instance(wrapperCache)101 bind<TelemetryManager>() with instance(telemetryManager)102 bind<EnvironmentTelemetryCollector>() with instance(environmentTelemetryCollector)103 }104 }105 val options by createForEachTest {106 mock<CommandLineOptions> {107 on { extend(dependencies) } doReturn extendedDependencies108 }109 }110 beforeEachTest {111 whenever(commandLineOptionsParser.parse(args)).thenReturn(CommandLineOptionsParsingResult.Succeeded(options))112 }113 given("the command executes normally") {114 val command by createForEachTest {115 mock<Command> {116 on { run() } doReturn 123117 }118 }119 beforeEachTest {120 whenever(commandFactory.createCommand(options, extendedDependencies)).thenReturn(command)121 }122 on("running the application") {123 val exitCode by runForEachTest { application.run(args) }124 it("does not print anything to the error stream") {125 assertThat(errorStream.toString(), equalTo(""))126 }127 it("returns the exit code from the command") {128 assertThat(exitCode, equalTo(123))129 }130 it("logs information about the application, enables console escape sequences, updates the last used time for the wrapper script and collects information about the environment before running the command") {131 inOrder(consoleManager, applicationInfoLogger, wrapperCache, environmentTelemetryCollector, command) {132 verify(applicationInfoLogger).logApplicationInfo(args)133 verify(consoleManager).enableConsoleEscapeSequences()134 verify(wrapperCache).setLastUsedForCurrentVersion()135 verify(environmentTelemetryCollector).collect(command::class)136 verify(command).run()137 }138 }139 it("finishes the telemetry session after running the command") {140 inOrder(command, telemetryManager) {141 verify(command).run()142 verify(telemetryManager).finishSession(telemetrySessionBuilder)143 }144 }145 it("reports the exit code as part of the telemetry session") {146 verify(telemetrySessionBuilder).addAttribute("exitCode", 123)147 }148 }149 }...

Full Screen

Full Screen

SpecificationStyleTest.kt

Source:SpecificationStyleTest.kt Github

copy

Full Screen

...38 at com.example.spek.SpecificationStyleTest$1$2.invoke(SpecificationStyleTest.kt:34)39 at com.example.spek.SpecificationStyleTest$1$2.invoke(SpecificationStyleTest.kt:9)40 at org.spekframework.spek2.style.specification.SpecificationStyleKt$createSuite$1.invoke(specificationStyle.kt:88)41 at org.spekframework.spek2.style.specification.SpecificationStyleKt$createSuite$1.invoke(specificationStyle.kt)42 at org.spekframework.spek2.runtime.Collector.group(Collectors.kt:91)43 at org.spekframework.spek2.dsl.GroupBody$DefaultImpls.group$default(dsl.kt:24)44 at org.spekframework.spek2.style.specification.SpecificationStyleKt.createSuite(specificationStyle.kt:87)45 at org.spekframework.spek2.style.specification.SpecificationStyleKt.describe(specificationStyle.kt:77)46 at org.spekframework.spek2.style.specification.SpecificationStyleKt.describe$default(specificationStyle.kt:76)47 at com.example.spek.SpecificationStyleTest$1.invoke(SpecificationStyleTest.kt:33)48 at com.example.spek.SpecificationStyleTest$1.invoke(SpecificationStyleTest.kt:9)49 */50 beforeEachTest {51 add("beforeEachTest-desc-1")52 logger.info("beforeEach in desc 1, memoized: {}, list: {}", items, list)53 }54 afterEachTest {55 add("afterEachTest-desc-1")56 logger.info("afterEachTest in desc 1, memoized: {}, list: {}", items, list)57 }58 it("is foo") {59 add("foo")60 logger.info("foo, memoized: {}, list: {}", items, list)61 }62 it("fails") {63 add("fail")64 logger.info("fail, memoized: {}, list: {}", items, list)65 fail { "fail: $items, $list" }66 }67 it("is bar") {68 add("bar")69 logger.info("bar, memoized: {}, list: {}", items, list)70 }71 describe("inner") {72 // cannot access items73// add("inner")74// logger.info("desc-1-inner, memoized: {}, list: {}", items, list)75/*76Caused by: java.lang.AssertionError: 'items' can not be accessed in this context.77 at org.spekframework.spek2.runtime.lifecycle.MemoizedValueAdapter.get(MemoizedValueAdapter.kt:33)78 at org.spekframework.spek2.runtime.lifecycle.MemoizedValueAdapter.getValue(MemoizedValueAdapter.kt:22)79 at com.example.spek.SpecificationStyleTest$1$1.invoke(SpecificationStyleTest.kt:16)80 at com.example.spek.SpecificationStyleTest$1$2$5.invoke(SpecificationStyleTest.kt:76)81 at com.example.spek.SpecificationStyleTest$1$2$5.invoke(SpecificationStyleTest.kt:9)82 at org.spekframework.spek2.style.specification.SpecificationStyleKt$createSuite$1.invoke(specificationStyle.kt:88)83 at org.spekframework.spek2.style.specification.SpecificationStyleKt$createSuite$1.invoke(specificationStyle.kt)84 at org.spekframework.spek2.runtime.Collector.group(Collectors.kt:91)85 at org.spekframework.spek2.dsl.GroupBody$DefaultImpls.group$default(dsl.kt:24)86 at org.spekframework.spek2.style.specification.SpecificationStyleKt.createSuite(specificationStyle.kt:87)87 at org.spekframework.spek2.style.specification.SpecificationStyleKt.access$createSuite(specificationStyle.kt:1)88 at org.spekframework.spek2.style.specification.Suite.describe(specificationStyle.kt:20)89 at org.spekframework.spek2.style.specification.Suite.describe$default(specificationStyle.kt:19)90 at com.example.spek.SpecificationStyleTest$1$2.invoke(SpecificationStyleTest.kt:75)91 at com.example.spek.SpecificationStyleTest$1$2.invoke(SpecificationStyleTest.kt:9)92 */93 beforeEachTest {94 add("beforeEachTest-inner")95 logger.info("beforeEachTest in inner, memoized: {}, list: {}", items, list)96 }97 it("inner") {98 add("inner-test")...

Full Screen

Full Screen

BundleSpec.kt

Source:BundleSpec.kt Github

copy

Full Screen

...60 }61 When("deleting the value of the property") {62 bundle.delete(prop)63 }64 with(ExceptionCollector()) {65 When("then querying the value") {66 execute { bundle[prop] }67 }68 Then("it should throw an exception") {69 expect<NoSuchElementException>()70 }71 }72 }73 @Suppress("UNCHECKED_CAST")74 Scenario("illegal get") {75 testFailsWith<ClassCastException>("getting the value of a wrongly cast property") {76 bundle[prop] = 177 println(bundle[prop as PublicProperty<Boolean>])78 }...

Full Screen

Full Screen

Collectors.kt

Source:Collectors.kt Github

copy

Full Screen

...6import org.spekframework.spek2.runtime.lifecycle.LifecycleManager7import org.spekframework.spek2.runtime.lifecycle.MemoizedValueCreator8import org.spekframework.spek2.runtime.lifecycle.MemoizedValueReader9import org.spekframework.spek2.runtime.scope.*10class Collector(11 val root: GroupScopeImpl,12 private val lifecycleManager: LifecycleManager,13 private val fixtures: FixturesAdapter,14 override val defaultCachingMode: CachingMode,15 override var defaultTimeout: Long16) : Root {17 private val ids = linkedMapOf<String, Int>()18 override fun <T> memoized(mode: CachingMode, factory: () -> T): MemoizedValue<T> = memoized(mode, factory) { }19 override fun <T> memoized(mode: CachingMode, factory: () -> T, destructor: (T) -> Unit): MemoizedValue<T> {20 return MemoizedValueCreator(21 root,22 mode,23 factory,24 destructor25 )26 }27 override fun <T> memoized(): MemoizedValue<T> {28 return MemoizedValueReader(root)29 }30 override fun registerListener(listener: LifecycleListener) {31 lifecycleManager.addListener(listener)32 }33 override fun group(description: String, skip: Skip, defaultCachingMode: CachingMode, preserveExecutionOrder: Boolean, failFast: Boolean, body: GroupBody.() -> Unit) {34 val group = GroupScopeImpl(35 idFor(description),36 root.path.resolve(description),37 root,38 skip,39 lifecycleManager,40 preserveExecutionOrder,41 failFast42 )43 root.addChild(group)44 val cachingMode = if (defaultCachingMode == CachingMode.INHERIT) {45 this.defaultCachingMode46 } else {47 defaultCachingMode48 }49 val collector = Collector(group, lifecycleManager, fixtures, cachingMode, defaultTimeout)50 try {51 body.invoke(collector)52 } catch (e: Throwable) {53 collector.beforeGroup { throw e }54 group.addChild(55 TestScopeImpl(56 idFor("Group Failure"),57 root.path.resolve("Group Failure"),58 root,59 defaultTimeout,60 {},61 skip,62 lifecycleManager63 )...

Full Screen

Full Screen

SpekRuntime.kt

Source:SpekRuntime.kt Github

copy

Full Screen

...38 } else {39 className40 }41 val classScope = GroupScopeImpl(ScopeId(ScopeType.Class, qualifiedName), path, null, Skip.No, lifecycleManager, false)42 val collector = Collector(classScope, lifecycleManager, fixtures, CachingMode.TEST, DEFAULT_TIMEOUT)43 try {44 instance.root.invoke(collector)45 } catch (e: Exception) {46 collector.beforeGroup { throw e }47 classScope.addChild(TestScopeImpl(48 ScopeId(ScopeType.Scope, "Discovery failure"),49 path.resolve("Discovery failure"),50 classScope,51 DEFAULT_TIMEOUT,52 {},53 Skip.No,54 lifecycleManager55 ))56 }...

Full Screen

Full Screen

Collector

Using AI Code Generation

copy

Full Screen

1import org.spekframework.spek2.runtime.execution.AbstractSpekRuntime2import org.spekframework.spek2.runtime.execution.ExecutionListener3import org.spekframework.spek2.runtime.execution.ExecutionResult4import org.spekframework.spek2.runtime.execution.ExecutionResult.Failure5import org.spekframework.spek2.runtime.execution.ExecutionResult.Success6import org.spekframework.spek2.runtime.scope.Path7import org.spekframework.spek2.runtime.scope.TestScopeImpl8import org.spekframework.spek2.runtime.scope.TestStatus9import org.spekframework.spek2.runtime.scope.TestStatus.Failed10import org.spekframework.spek2.runtime.scope.TestStatus.Ignored11import org.spekframework.spek2.runtime.scope.TestStatus.Skipped12import org.spekframework.spek2.runtime.scope.TestStatus.Successful13import org.spekframework.spek2.runtime.scope.TestStatus.Unknown14import org.spekframework.spek2.runtime.scope.toPath15import java.util.concurrent.ConcurrentHashMap16import java.util.concurrent.ConcurrentLinkedQueue17import java.util.concurrent.atomic.AtomicInteger18class MySpekRuntime : AbstractSpekRuntime() {19 override fun execute(executionListener: ExecutionListener) {20 val collector = Collector()21 addExecutionListener(collector)22 super.execute(executionListener)23 collector.printResult()24 }25}26class Collector : ExecutionListener {27 private val map = ConcurrentHashMap<Path, TestStatus>()28 private val ignored = ConcurrentLinkedQueue<Path>()29 private val skipped = ConcurrentLinkedQueue<Path>()30 private val failed = ConcurrentLinkedQueue<Path>()31 private val success = ConcurrentLinkedQueue<Path>()32 private val unknown = ConcurrentLinkedQueue<Path>()33 private val total = AtomicInteger()34 private val ignoredCount = AtomicInteger()35 private val skippedCount = AtomicInteger()36 private val failedCount = AtomicInteger()37 private val successCount = AtomicInteger()38 private val unknownCount = AtomicInteger()39 override fun executionStart() {40 }41 override fun executionFinish() {42 }43 override fun testExecutionStart(test: TestScopeImpl) {44 total.incrementAndGet()45 }46 override fun testExecutionFinish(test: TestScopeImpl, result: ExecutionResult) {47 map[test.path] = when (result) {48 is Success -> {

Full Screen

Full Screen

Collector

Using AI Code Generation

copy

Full Screen

1val collector = Collector()2val runner = SpekRuntime(collector)3runner.execute(specs)4val runner = Runner()5runner.execute(specs)6val runner = JUnitPlatform()7runner.execute(specs)8val runner = JUnitPlatform()9runner.execute(specs)10val runner = JUnitPlatform()11runner.execute(specs)12val runner = JUnitPlatform()13runner.execute(specs)14val runner = JUnitPlatform()15runner.execute(specs)16val runner = JUnitPlatform()17runner.execute(specs)18val runner = JUnitPlatform()19runner.execute(specs)20val runner = JUnitPlatform()21runner.execute(specs)22val runner = JUnitPlatform()23runner.execute(specs)24val runner = JUnitPlatform()25runner.execute(specs)26val runner = JUnitPlatform()27runner.execute(specs)28val runner = JUnitPlatform()29runner.execute(specs)

Full Screen

Full Screen

Collector

Using AI Code Generation

copy

Full Screen

1import org.spekframework.spek2.runtime.Collector 2import org.spekframework.spek2.runtime.SpekRuntime 3import org.spekframework.spek2.runtime.scope.Path4fun main() { 5val collector = Collector() 6val runtime = SpekRuntime(collector) 7runtime.execute() 8testCases.forEach { println(it.path) } 9}

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