From c3f30eb807931d4fc7c1ea148801f2dff6a3ece9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20Br=C3=BCnings?= Date: Fri, 10 Mar 2023 11:57:50 +0100 Subject: [PATCH] Add interaction example AstSpec --- .../smoke/ast/mock/MocksAstSpec.groovy | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 spock-specs/src/test/groovy/org/spockframework/smoke/ast/mock/MocksAstSpec.groovy diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/ast/mock/MocksAstSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/ast/mock/MocksAstSpec.groovy new file mode 100644 index 0000000000..b8a6b17965 --- /dev/null +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/ast/mock/MocksAstSpec.groovy @@ -0,0 +1,41 @@ +package org.spockframework.smoke.ast.mock + +import org.spockframework.EmbeddedSpecification + +class MocksAstSpec extends EmbeddedSpecification { + + def "simple interaction"() { + when: + def result = compiler.transpileFeatureBody(""" + given: + List list = Mock() + + when: + list.add(1) + + then: + 1 * list.add(1) +""") + then: + result.source == '''\ +@org.spockframework.runtime.model.FeatureMetadata(name = 'a feature', ordinal = 0, line = 1, blocks = [@org.spockframework.runtime.model.BlockMetadata(kind = org.spockframework.runtime.model.BlockKind.SETUP, texts = []), @org.spockframework.runtime.model.BlockMetadata(kind = org.spockframework.runtime.model.BlockKind.WHEN, texts = []), @org.spockframework.runtime.model.BlockMetadata(kind = org.spockframework.runtime.model.BlockKind.THEN, texts = [])], parameterNames = []) +public void $spock_feature_0_0() { + try { + org.spockframework.runtime.SpockRuntime.callEnterBlock(this.getSpecificationContext(), new org.spockframework.runtime.model.BlockInfo(org.spockframework.runtime.model.BlockKind.SETUP, [])) + java.util.List list = this.MockImpl('list', java.util.List) + org.spockframework.runtime.SpockRuntime.callExitBlock(this.getSpecificationContext(), new org.spockframework.runtime.model.BlockInfo(org.spockframework.runtime.model.BlockKind.SETUP, [])) + this.getSpecificationContext().getMockController().enterScope() + this.getSpecificationContext().getMockController().addInteraction(new org.spockframework.mock.runtime.InteractionBuilder(8, 5, '1 * list.add(1)').setFixedCount(1).addEqualTarget(list).addEqualMethodName('add').setArgListKind(true, false).addEqualArg(1).build()) + org.spockframework.runtime.SpockRuntime.callEnterBlock(this.getSpecificationContext(), new org.spockframework.runtime.model.BlockInfo(org.spockframework.runtime.model.BlockKind.WHEN, [])) + list.add(1) + org.spockframework.runtime.SpockRuntime.callExitBlock(this.getSpecificationContext(), new org.spockframework.runtime.model.BlockInfo(org.spockframework.runtime.model.BlockKind.WHEN, [])) + this.getSpecificationContext().getMockController().leaveScope() + org.spockframework.runtime.SpockRuntime.callEnterBlock(this.getSpecificationContext(), new org.spockframework.runtime.model.BlockInfo(org.spockframework.runtime.model.BlockKind.THEN, [])) + org.spockframework.runtime.SpockRuntime.callExitBlock(this.getSpecificationContext(), new org.spockframework.runtime.model.BlockInfo(org.spockframework.runtime.model.BlockKind.THEN, [])) + this.getSpecificationContext().getMockController().leaveScope() + } + finally { + org.spockframework.runtime.SpockRuntime.clearCurrentBlock(this.getSpecificationContext())} +}''' + } +}