spek icon indicating copy to clipboard operation
spek copied to clipboard

After creating an extension function for it the Spek Plugin crash and does not let you run tests

Open danielgomezrico opened this issue 4 years ago • 4 comments

Hi

My use case was that I have some common behaviour in all of my views in the app, so I wanted to reuse an it that checks for the same thing over those.

  1. Created a Suite extension that creates an it normally, this extension receives a builder function to avoid calling the instance in the wrong memoized context.

  2. Use it everywhere.

But when I use it in the test I get a crash from android studio and if I click the green arrow it says "Nothing here", after I clean and build, the green arrows are gone.

Dependencies

  • spek: 2.0.10
    • "org.spekframework.spek2:spek-dsl-jvm:$spek"
    • "org.spekframework.spek2:spek-runner-junit5:$spek"
  • Spek Framework Plugin: 2.0.10-Studio3.6

Extension

My view interface:

interface DataLoadView  {
    fun setProgressVisibility(isVisible: Boolean)
}

The extension:

fun Suite.itShouldShowProgress(buildView: () -> DataLoadView) =
    it("should show and hide progress in order") {
        val view = buildView()

        inOrder(view) {
            verify(view).setProgressVisibility(true)
            verify(view).setProgressVisibility(false)
        }
    }

The test that use it:

describe("when on option click") {
	beforeGroup {
		presenter.onOptionClick()
	}

	itShouldShowProgress { view }
}

Error

org.spekframework.intellij.SpekAndroidConfigurationFactory@48e65fda produced wrong type

java.lang.ClassCastException: org.jetbrains.kotlin.asJava.elements.KtLightPsiLiteral cannot be cast to com.intellij.psi.PsiAnnotation
	at org.spekframework.intellij.domain.PsiDescriptions$sources$2.invoke(synonym.kt:65)
	at org.spekframework.intellij.domain.PsiDescriptions$sources$2.invoke(synonym.kt:60)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at org.spekframework.intellij.domain.PsiDescriptions.getSources(synonym.kt)
	at org.spekframework.intellij.domain.SynonymContext.constructDescription(synonym.kt:83)
	at org.spekframework.intellij.domain.ScopeDescriptorCache.buildScopes(ScopeDescriptorCache.kt:90)
	at org.spekframework.intellij.domain.ScopeDescriptorCache.buildScopes(ScopeDescriptorCache.kt:104)
	at org.spekframework.intellij.domain.ScopeDescriptorCache.buildDescriptor(ScopeDescriptorCache.kt:71)
	at org.spekframework.intellij.domain.ScopeDescriptorCache.fromClassOrObject(ScopeDescriptorCache.kt:43)
	at org.spekframework.intellij.SpekRunConfigurationProducer.setupConfigurationFromContext(SpekRunConfigurationProducer.kt:87)
	at org.spekframework.intellij.SpekRunConfigurationProducer.setupConfigurationFromContext(SpekRunConfigurationProducer.kt:27)
	at com.intellij.execution.actions.RunConfigurationProducer.createLightConfiguration(RunConfigurationProducer.java:278)
	at com.intellij.execution.lineMarker.ExecutorAction$Companion.computeConfigurations(ExecutorAction.kt:66)
	at com.intellij.execution.lineMarker.ExecutorAction$Companion.getConfigurations(ExecutorAction.kt:51)
	at com.intellij.execution.lineMarker.ExecutorAction$Companion.access$getConfigurations(ExecutorAction.kt:32)
	at com.intellij.execution.lineMarker.ExecutorAction.getActionName(ExecutorAction.kt:101)
	at com.intellij.execution.lineMarker.ExecutorAction.update(ExecutorAction.kt:76)
	at com.intellij.execution.lineMarker.LineMarkerActionWrapper.update(LineMarkerActionWrapper.java:85)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:176)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.doUpdate(ActionUpdater.java:379)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$null$1(ActionUpdater.java:79)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.callAction(ActionUpdater.java:107)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$new$2(ActionUpdater.java:80)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.update(ActionUpdater.java:365)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandGroupChild(ActionUpdater.java:232)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroup$19(ActionUpdater.java:216)
	at com.intellij.util.containers.ContainerUtil.concat(ContainerUtil.java:1609)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.doExpandActionGroup(ActionUpdater.java:216)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandActionGroup(ActionUpdater.java:140)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandActionGroup(ActionUpdater.java:132)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$expandActionGroupWithTimeout$11(ActionUpdater.java:149)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$3(CoreProgressManager.java:185)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:169)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:591)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:537)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:59)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:156)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:185)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.withTimeout(ProgressIndicatorUtils.java:260)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandActionGroupWithTimeout(ActionUpdater.java:148)
	at com.intellij.openapi.actionSystem.impl.Utils.fillMenu(Utils.java:66)
	at com.intellij.openapi.actionSystem.impl.ActionPopupMenuImpl$MyMenu.show(ActionPopupMenuImpl.java:114)
	at com.intellij.openapi.editor.impl.EditorGutterComponentImpl.invokePopup(EditorGutterComponentImpl.java:2022)
	at com.intellij.openapi.editor.impl.EditorGutterComponentImpl.mousePressed(EditorGutterComponentImpl.java:1747)
	at com.intellij.openapi.editor.impl.EditorImpl$MyMouseAdapter.processMousePressed(EditorImpl.java:3895)
	at com.intellij.openapi.editor.impl.EditorImpl$MyMouseAdapter.lambda$runMousePressedCommand$0(EditorImpl.java:3762)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
	at com.intellij.openapi.editor.impl.EditorImpl$MyMouseAdapter.runMousePressedCommand(EditorImpl.java:3767)
	at com.intellij.openapi.editor.impl.EditorImpl$MyMouseAdapter.mousePressed(EditorImpl.java:3696)
	at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:280)
	at java.awt.Component.processMouseEvent(Component.java:6547)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3325)
	at java.awt.Component.processEvent(Component.java:6315)
	at java.awt.Container.processEvent(Container.java:2239)
	at java.awt.Component.dispatchEventImpl(Component.java:4899)
	at java.awt.Container.dispatchEventImpl(Container.java:2297)
	at java.awt.Component.dispatchEvent(Component.java:4721)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4532)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
	at java.awt.Container.dispatchEventImpl(Container.java:2283)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4721)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
	at java.awt.EventQueue$4.run(EventQueue.java:739)
	at java.awt.EventQueue$4.run(EventQueue.java:737)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:736)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:878)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:823)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:466)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:704)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:465)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

danielgomezrico avatar Mar 30 '20 21:03 danielgomezrico

How can I reuse a check? or it is a try to over-engineer the tests?

danielgomezrico avatar Mar 31 '20 19:03 danielgomezrico

Definitely a bug with the idea plugin, thanks for reporting! I guess for now, just re-use the check. Although you can re-use some parts of it:

fun verifyProgressBarShowing(view: View) {
  inOrder(view) {
    verify(view).setProgressVisibility(true)
    verify(view).setProgressVisibility(false)
  }
}

Then call verifyProgressBarShowing in the duplicated its.

raniejade avatar Mar 31 '20 22:03 raniejade

@raniejade got it, thanks

danielgomezrico avatar Apr 01 '20 02:04 danielgomezrico

Moving this to 2.1.0, as I'm planning a revisit and a big refactor to the IJ plugin.

raniejade avatar May 30 '20 01:05 raniejade