Gaelyk 2 and Spock

66 views
Skip to first unread message

Alex Garrett

unread,
May 28, 2013, 8:38:53 AM5/28/13
to gae...@googlegroups.com
Hi

I couldn't get Gaelyk 2 and gaelyk-spock to function as per the examples.

Essentially the GaelykBindings were not being automatically injected into my test groovlet, 
so 'datastore' etc weren't in the binding, nor was the call mechanism to the test code activated.

I had to adorn the test with @GaelykBindings, meaning I also had to make the test a class, 
and then added a static get method, also not automatically added.

With that I could then call my get method, on the class, from the Spec to make the complete test succeed. 

// THE TEST  addProviderTest.groovy
//------------------------------------------------------
import groovyx.gaelyk.GaelykBindings

@GaelykBindings
class AddProviderTest {
    static void get() { 
       // create an entity and populate it here
    }

}
 

// THE SPEC 
//------------------
class AddProvidersSpec extends GaelykUnitSpec {
    def setup(){
        groovlet 'addProviderTest.groovy'
    }

    void 'groovlet adds provider'() {
        given: "the initialised groovlet is invoked and data is persisted"
        AddProviderTest.get()

        when: "the datastore is queried for data"
        // query the entity created

        then: "the persisted data is found in the datastore"
        // test that the entity retrieved contains data we set
     }
}


OK so all is well, this works for me, but

NB either my build.gradle (which replicates what is now in the new Gaelyk 2 template's build.gradle) is wrong,

OR the Gaelyk tutorial samples will need some updating, to reflect that they no longer work as is!

Either way, anyone with greater insight, I'd love to know which is the case!  

Thanks
Alex

Alex Garrett

unread,
May 28, 2013, 11:31:33 PM5/28/13
to gae...@googlegroups.com
In the Gaelyk spock source, I see GaelykSpec has datastore created (from factory),
and GaelykUnitSpec extends this class.

The groovlet closure, that I do call, seems to assign datastore to the instance! So I'm not sure whether it does / should work based on this snippet!
 
def groovlet = { it, dir = groovletsDir ->
groovletInstance = new GroovletUnderSpec("$it", dir)

['sout', 'out', 'response', 'datastore', 'memcache', 'mail', 'urlFetch', 'images', 'users', 'user', 'defaultQueue', 'queues', 'xmpp',
'blobstore', 'files', 'oauth', 'channel', 'capabilities', 'namespace', 'localMode', 'app', 'backends', 'lifecycle'
].each { groovletInstance."$it" = this."$it" }
this.metaClass."${it.tokenize('.').first().tokenize('/').last()}" = groovletInstance
}

Guillaume Laforge

unread,
May 29, 2013, 8:34:29 AM5/29/13
to gae...@googlegroups.com
I'll let Spock experts help... I didn't implement the Gaelyk / Spock support, so I'm not too familiar with how it's working.
Anyone can help here?

Guillaume



--
--
You've received this message because you've subscribed to the Gaelyk Google Group.
To send an email to the group, please write to: gae...@googlegroups.com
To unsuscribe from this group: gaelyk+un...@googlegroups.com
To show more options: http://groups.google.fr/group/gaelyk?hl=en
 
---
You received this message because you are subscribed to the Google Groups "Gaelyk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gaelyk+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Guillaume Laforge
Groovy Project Manager
SpringSource, a division of VMware

Vladimír Oraný

unread,
May 29, 2013, 8:51:04 AM5/29/13
to gae...@googlegroups.com

Thats my work but I need some time to have look at. I keep you posted how should you update your spec.

Dne 29.5.2013 14:34 "Guillaume Laforge" <glaf...@gmail.com> napsal(a):

Vladimír Oraný

unread,
Jun 3, 2013, 3:18:58 AM6/3/13
to gae...@googlegroups.com
This is weird. As you posted later most of the gaelyk shortcuts are injected by the spec.

could you remove that class and post the original stack trace. also what version of Gaelyk Spock are you using? (0.4 is the latest)

V.


2013/5/29 Vladimír Oraný <vlad...@orany.cz>

Alex Garrett

unread,
Jun 16, 2013, 9:33:55 PM6/16/13
to gae...@googlegroups.com, vlad...@orany.cz
Good grief, I responded to this and yet I seem to have clicked the wrong button, there's no trace of it :(

In a nutshell

    def "TEST - the datastore is present in the groovlet binding"(){
        given: "the initialised groovlet"

        expect: "the datastore in the binding"
        test.datastore != null
        test.datastore instanceof com.google.appengine.api.datastore.DatastoreService
    }


that test generates

TEST - the datastore is present in the groovlet binding

groovy.lang.MissingPropertyException: No such property: datastore for class: test
	at testSpec.TEST - the datastore is present in the groovlet binding(testSpec.groovy:30)
i.e. no injection of datastore.

Oh, and   testCompile 'org.gaelyk:gaelyk-spock:0.4' with regards Spock

Apologies for this atrociously late response.

Alex

Vladimír Oraný

unread,
Jun 25, 2013, 7:10:13 PM6/25/13
to Alex Garrett, gae...@googlegroups.com
do you get the same result if you use "groovletInstance" instead of "test"?


2013/6/17 Alex Garrett <alex.g...@lexecorp.com>
Reply all
Reply to author
Forward
0 new messages