Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 18:10

    github-actions[bot] on gh-pages

    Publish docs/2.1-SNAPSHOT (compare)

  • 18:10

    github-actions[bot] on gh-pages

    Publish javadoc/2.1-SNAPSHOT (compare)

  • 17:59
    szpak commented #1416
  • 17:59

    szpak on master

    Bump up Gradle plugin dependenc… (compare)

  • 17:59
    szpak closed #1416
  • 17:59
    codecov[bot] commented #1416
  • 17:59
    codecov[bot] commented #1416
  • 17:58
    codecov[bot] commented #1416
  • 17:55
    szpak auto_merge_enabled #1416
  • 10:01
    jprinet opened #1416
  • Jan 16 06:01
    kriegaex commented #1412
  • Jan 16 06:00
    moqimoqidea commented #1412
  • Jan 16 05:59
    moqimoqidea commented #1412
  • Jan 16 05:58
    kriegaex commented #1412
  • Jan 16 05:54
    moqimoqidea commented #1412
  • Jan 16 05:42
    kriegaex commented #1412
  • Jan 16 05:39
    kriegaex commented #1412
  • Jan 16 04:54
    kriegaex commented #1412
  • Jan 16 04:53
    kriegaex commented #1412
  • Jan 16 04:53
    kriegaex commented #1412
Leonard Brünings
@leonard84
yes
kwangomango
@kwangomango
:thumbsup:
Leonard Brünings
@leonard84
You can't have external mock interactions though
kwangomango
@kwangomango
That's fine, i'm mostly using Spock for integration tests on apis.
If i make the external helper a closure, rather than a method, then it works just like a local method on Specification. Why is that?
class ClosureTest extends Specification {

    Helper helper = new Helper()

    void "testy"() {

        expect:
            verify.call()
    }

}

class Helper {

    Closure verify= { assert 1 == 2 }

}
Vahid Pazirandeh
@vahidpaz
What http client normally blends well with Spock website functional testing? I've looked at a few (httpbuilder, httpbuilder-ng) and I like their syntax (httpbuilder is nice) bit those projects are either abandoned or dormant. I'd like to use something actively support. thx
Leonard Brünings
@leonard84
you could use https://rest-assured.io/ although it has its own when-then methods
Vahid Pazirandeh
@vahidpaz
Yes I noticed it does. It looks to be an all-inclusive library, even allowing groovy syntax in strings (I guess that it eval()'s on). I'll play around and see if there's a happy middle-ground
Vahid Pazirandeh
@vahidpaz
@leonard84 - thank you for all the time/effort you put in for Spock. It's a real blessing for people around the world.
Leonard Brünings
@leonard84
thanks
Björn Kautler
@Vampire
@vahidpaz I heard and read very good things about Geb and it is nicely integrated with Spock too.
Leonard Brünings
@leonard84
Geb is for browser testing, I assumed the question was geared towards REST API testing
Björn Kautler
@Vampire
Which part of "website functional testing" makes you think so?
"i'm mostly using Spock for integration tests on apis" was a different user one message earlier
Leonard Brünings
@leonard84
Well, since the listed frameworks where http clients and not selenium/webdriver, I assumed testing should be done on the http/rest layer.
If you want browser tests, then sure Geb is the best choice for Spock.
Vahid Pazirandeh
@vahidpaz
@Vampire thank you for the info. Yes I was referring to rest api testing but when the time comes to sprinkle some web app UI testing (some call it user acceptance tests?) I will take a look at Geb. thx again
Luke Last
@lukelast
How do I set defaultExecutionMode=SAME_THREAD?
For spock 2.0
Alexander Kriegisch
@kriegaex
Copy from the linked test:
      runner {
        parallel {
          enabled true
          defaultSpecificationExecutionMode ExecutionMode.SAME_THREAD
          defaultExecutionMode ExecutionMode.SAME_THREAD
        }
      }
Leonard Brünings
@leonard84
Luke Last
@lukelast
Thank you Alexander! I hadn't found that example config. What ended up working for me was defaultExecutionMode org.spockframework.runtime.model.parallel.ExecutionMode.SAME_THREAD
Also, yay spock 2.0 and congrats!
sma-ops
@sma-ops
Hi. After seting up the pock project for idea (via ./gradlew cleanIdea idea), I try to run some tests, e.g., ./gradlew spock-core:test. But there does not seem to happen anything.

DESKTOP-CIDB3LU MINGW64 /e/projects/spock (master)
$ ./gradlew spock-core:test

Configure project :spock-core
[versioning] WARNING - the working copy has unstaged or uncommitted changes.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 1s
5 actionable tasks: 5 up-to-date

A build scan was not published as you have not authenticated with server 'ge.spockframework.org'.

let me know if the question should be put somewhere else (its probably not a bug, but too specific for stackoverflow)
Leonard Brünings
@leonard84
spock uses build caching, so if you didn't change anything it will not execute any tasks that are already cached
you can try cleaning and then running with --no-build-cache, or change some code locally
sma-ops
@sma-ops
That does not help. I also changed some test files.
but it does not seem to pick up the change
wait, yes that worked. I was just changing things in the wrong test folder - thanks!
Nick Bensema
@unbibium
is there a clean way to write a "where" block that loads all combinations of two variables, given only the two lists? like a way to do "foo << [1,1,1,2,2,2,3,3,3]" "bar << [4,5,6,4,5,6,4,5,6]" without repeating the numbers?
a cartesian product, if you will. Maybe even with 3 properties.
Leonard Brünings
@leonard84
Nick Bensema
@unbibium
ah, ok. that should be pretty close.
all I needed was something like [foo,bar] << [ [1,2,3] , [4,5,6] ].combinations
Nick Bensema
@unbibium
i do wish i could change the order of loops so that the 1,2,3 column is the outer loop, but this will get me most of the way
Alexander Kriegisch
@kriegaex
You should not rely on the order of features or order of iterations within a feature. But would something like this do?
[[1,2,3], [4,5,6]].combinations()
# [[1, 4], [2, 4], [3, 4], [1, 5], [2, 5], [3, 5], [1, 6], [2, 6], [3, 6]]

[[1,2,3], [4,5,6]].combinations().sort()
# [[1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6]]
For illustration:
[3, [1], [2], 1, [1,2], [1,1], [1,2,3], [1,2], 2, [1,2,2], [3]].sort()
# [1, 2, 3, [1], [2], [3], [1, 1], [1, 2], [1, 2], [1, 2, 2], [1, 2, 3]]
Alexander Kriegisch
@kriegaex
Otherwise you can call sort with a custom comparator, if you think it is worth the effort.
woodgiraffe
@woodgiraffe
hi, I'm looking for a way to pass a list of closures that are expected to all throw the same type of exception and verify this behavior without writing feature methods for every single one, I'd welcome any pointers that can put me in the right direction
Alexander Kriegisch
@kriegaex
Please post your code, explain what you tried and what is different from your expectation.
Did you search stackoverflow.com? I answered similar questions there before, even very recently.
Simon Temple
@simon-temple

Hi all, I have a newbie question about Script bindings... I am running a test via the EmbeddedSpecRunner()

import spock.util.EmbeddedSpecRunner
def esr = new EmbeddedSpecRunner()
esr.runClass(SpockTestClass.class)

This is my groovy Script class. Before I run my Script I bind an instance of a class called myDsl to it.
I would like to use myDsl from within SpockTestClass but cannot figure out a way to supply it via the EmbeddedSpecRunner
I have tried creating a @Singleton and referencing it from within the Specification but I'm guessing classloaders stop me seeing this externally created .instance
How can I supply a pre-built Object(s) for use within a Specification?

Alexander Kriegisch
@kriegaex
@simon-temple, maybe someone more "groovy" than I can make sense of this snippet out of context, but as far as I am concerned, I would be glad to see the full picture. Could you please provide the test and, if necessary to run it, also a class under test? I just need the tiniest versions of both which reproduce your problem, then I can look into it. I would like to understand what you mean exactly by "bind an instance". Bind how? Bind where?
Simon Temple
@simon-temple

@kriegaex, thank you for looking at this... the code snippet is an instance of the Groovy Script class which has a set/get Binding method (https://docs.groovy-lang.org/latest/html/api/groovy/lang/Script.html) Before I run the Script I add an object called myDsl via a Binding (https://docs.groovy-lang.org/latest/html/api/groovy/lang/Binding.html). For example, myDsl has a log() method so I can do this:

import spock.util.EmbeddedSpecRunner
def esr = new EmbeddedSpecRunner()
myDsl.log("About to run the test")
esr.runClass(SpockTestClass.class)

However I cannot access the Binding of the Script from within my SpockTestClass as I cannot find a way to pass any pre-instantiated object into a test when using the EmbeddedSpecRunner(). I think the Binding is perhaps confusing my question. A simpler question might be :

import spock.util.EmbeddedSpecRunner

def esr = new EmbeddedSpecRunner()

def myMap = [:]
myMap['hello'] = 'world'

esr.runClass(SpockTestClass.class)

The test class looks like:

import spock.lang.*

class SpockTestClass extends Specification {

    def "hello must be world"() {
        given:
        def value = myMap['hello']

        expect:
        value == 'world'
    }
}

The results are:

groovy.lang.MissingPropertyException: No such property: myMap for class: io.platform6.app.core.scripts.rd_spockmain.SpockTestClass
    at SpockTestClass.hello must be world(SpockTestClass:10)

How can I supply a pre-built Object(s) for use within a Specification?

Alexander Kriegisch
@kriegaex

Ugh, that's ugly, depending on a binding not present in the spec itself during feature execution. But I understand what you are trying to do. I know that my recommendation not to do it like that, because the test also cannot run stand-alone like that and forever depends on the calling script, does not solve your problem. The Groovy guys like Leonard and Björn probably know if and how this can be achieved.

My recommendation would be to fetch the values you need in a where: block, maybe using a custom data provider. You can read them from a file, a database, a website or wherever.

Simon Temple
@simon-temple
Yes I take your point, relying on external side-effects is not a good unit testing approach. However, I'm trying to push the use of Spock a little further and introduce its use as a functional testing tool. To do this I'd like to execute the tests within a provided environment (with some pre instantiated objects). Perhaps I'm trying to use Spock in a way it was not designed for?
Simon Temple
@simon-temple

BTW: I found an example using Spring:

class SampleSpringSpec extends Specification {
       @Autowired
        private WebController webController
        def "when context is loaded then controller bean is created"() {
               expect: "the WebController is created"
               webController != null
       }
}

Maybe I need to look at developing our version of the Autowire annotation ?