Quantcast

mockConfig with Grails 2.0.0.M1 and Spock

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

mockConfig with Grails 2.0.0.M1 and Spock

jlust
Hi,

I have a number of unit tests that use mockConfig(String). The tests succeed with Grails 1.3.7 and Spock plugin 0.5, however they fail after converting the tests to Grails 2.0.0.M1 and Spock 0.6, they fail, saying the mockConfig() does not exist. I no longer extend UnitSpec, but spock.lang.Specification, and the new test mixins, so it makes sense that this method is no longer found, since it's in GrailsUnitTestCase. The question is, how do I get mockConfig() back? Extending UnitSpec again is not an option, because then mockDomain does not work.

Jurgen
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: mockConfig with Grails 2.0.0.M1 and Spock

pledbrook
> I have a number of unit tests that use mockConfig(String). The tests succeed with Grails 1.3.7 and Spock plugin 0.5, however they fail after converting the tests to Grails 2.0.0.M1 and Spock 0.6, they fail, saying the mockConfig() does not exist. I no longer extend UnitSpec, but spock.lang.Specification, and the new test mixins, so it makes sense that this method is no longer found, since it's in GrailsUnitTestCase. The question is, how do I get mockConfig() back? Extending UnitSpec again is not an option, because then mockDomain does not work.

In what way is your code accessing the application configuration?

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: mockConfig with Grails 2.0.0.M1 and Spock

jlust
What I'm testing is the default value for a file location if nothing is configured in the Grails configuration, and whether a configured value is correctly picked up.

The code I'm testing looks like this:

>     File getStorageDirectory() {
>         File storageDirectory = new File(System.getProperty("user.home"))
>         def config = ConfigurationHolder.config
>         if (config.beeworks.files.storage.dir) {
>             storageDirectory = new File(config.beeworks.files.storage.dir)
>         }
>         …
>     }

My test look likes this:

>     def validFileDescription() {
>         new FileDescription(name: 'example file', contentType: "image/jpeg", fileSize: 1, timeToLive: -1)
>     }
>
>     def "storage directory should be the user home if not configured"() {
>         given:
>             mockConfig("")
>         when:
>             def storageDirectory = validFileDescription().storageDirectory
>         then:
>             storageDirectory.absolutePath == System.getProperty("user.home")
>     }
>
>     def "storage directory can be configured using property beeworks files storage dir"() {
>         given:
>             def tempDir = new File(System.getProperty("java.io.tmpdir"))
>             mockConfig("""
>                 beeworks.files.storage.dir = '${tempDir.absolutePath}'
>             """)
>         when:
>             def storageDirectory = validFileDescription().storageDirectory
>         then:
>             storageDirectory.absolutePath == tempDir.absolutePath
>     }


Jurgen


Op 12-aug.-2011, om 10:45 heeft Peter Ledbrook het volgende geschreven:

>> I have a number of unit tests that use mockConfig(String). The tests succeed with Grails 1.3.7 and Spock plugin 0.5, however they fail after converting the tests to Grails 2.0.0.M1 and Spock 0.6, they fail, saying the mockConfig() does not exist. I no longer extend UnitSpec, but spock.lang.Specification, and the new test mixins, so it makes sense that this method is no longer found, since it's in GrailsUnitTestCase. The question is, how do I get mockConfig() back? Extending UnitSpec again is not an option, because then mockDomain does not work.
>
> In what way is your code accessing the application configuration?
>
> Peter
>
> --
> Peter Ledbrook
> Grails Advocate
> SpringSource - A Division of VMware
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: mockConfig with Grails 2.0.0.M1 and Spock

pledbrook
>>     File getStorageDirectory() {
>>         File storageDirectory = new File(System.getProperty("user.home"))
>>         def config = ConfigurationHolder.config

Do you need to use ConfigurationHolder? It's deprecated in 2.0. You
should be injecting 'grailsApplication' and accessing its 'config'
property if possible.

If you really must use ConfigurationHolder, you will need to
initialise it manually at the start of the test and clear it
afterwards. You can initialise it with:

   ConfigurationHolder.config = config

from any instance method in your test case.

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: mockConfig with Grails 2.0.0.M1 and Spock

rlovtangen
Why is mockConfig removed? I know that in 1.3.x it was kind of broken, in the sense that it only worked for config accessed through ConfigurationHolder.config, and not through grailsApplication.config.
Shouldn't mockConfig rather be fixed to mock config for grailsApplication.config? Or is there a better way to mock config?

Ronny

On Aug 12, 2011, at 11:13 AM, Peter Ledbrook wrote:

>>>     File getStorageDirectory() {
>>>         File storageDirectory = new File(System.getProperty("user.home"))
>>>         def config = ConfigurationHolder.config
>
> Do you need to use ConfigurationHolder? It's deprecated in 2.0. You
> should be injecting 'grailsApplication' and accessing its 'config'
> property if possible.
>
> If you really must use ConfigurationHolder, you will need to
> initialise it manually at the start of the test and clear it
> afterwards. You can initialise it with:
>
>   ConfigurationHolder.config = config
>
> from any instance method in your test case.
>
> Peter
>
> --
> Peter Ledbrook
> Grails Advocate
> SpringSource - A Division of VMware
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: mockConfig with Grails 2.0.0.M1 and Spock

pledbrook
> Why is mockConfig removed? I know that in 1.3.x it was kind of broken, in the sense that it only worked for config accessed through ConfigurationHolder.config, and not through grailsApplication.config.
> Shouldn't mockConfig rather be fixed to mock config for grailsApplication.config? Or is there a better way to mock config?

I believe it's been removed because it's not needed if you're using
grailsApplication.config in your classes. I'll be honest and admit I
haven't tested this, so if someone has time to verify, that would be
great.

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: mockConfig with Grails 2.0.0.M1 and Spock

rlovtangen

On Aug 12, 2011, at 11:56 AM, Peter Ledbrook wrote:

>> Why is mockConfig removed? I know that in 1.3.x it was kind of broken, in the sense that it only worked for config accessed through ConfigurationHolder.config, and not through grailsApplication.config.
>> Shouldn't mockConfig rather be fixed to mock config for grailsApplication.config? Or is there a better way to mock config?
>
> I believe it's been removed because it's not needed if you're using
> grailsApplication.config in your classes.

As long as ConfigurationHolder is deprecated, not removed, I think mockConfig should remain, and be deprecated. Or not deprecated, if it were to support mocking of grailsApplication.config as well.

Ronny
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: mockConfig with Grails 2.0.0.M1 and Spock

jlust
It's not removed, it's still in GrailsUnitTestCase, but with Spock 0.6 you can no longer extend that class, because then you get exceptions with mockDomain. You have to use the new mixins, and there mockConfig is not available.

Jurgen

Op 12-aug.-2011 om 12:02 heeft Ronny Løvtangen <[hidden email]> het volgende geschreven:

>
> On Aug 12, 2011, at 11:56 AM, Peter Ledbrook wrote:
>
>>> Why is mockConfig removed? I know that in 1.3.x it was kind of broken, in the sense that it only worked for config accessed through ConfigurationHolder.config, and not through grailsApplication.config.
>>> Shouldn't mockConfig rather be fixed to mock config for grailsApplication.config? Or is there a better way to mock config?
>>
>> I believe it's been removed because it's not needed if you're using
>> grailsApplication.config in your classes.
>
> As long as ConfigurationHolder is deprecated, not removed, I think mockConfig should remain, and be deprecated. Or not deprecated, if it were to support mocking of grailsApplication.config as well.
>
> Ronny
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: mockConfig with Grails 2.0.0.M1 and Spock

rlovtangen
ok, maybe mockConfig should be added to the new mixins then

Ronny

On Aug 12, 2011, at 12:23 PM, Jurgen Lust wrote:

> It's not removed, it's still in GrailsUnitTestCase, but with Spock 0.6 you can no longer extend that class, because then you get exceptions with mockDomain. You have to use the new mixins, and there mockConfig is not available.
>
> Jurgen
>
> Op 12-aug.-2011 om 12:02 heeft Ronny Løvtangen <[hidden email]> het volgende geschreven:
>
>>
>> On Aug 12, 2011, at 11:56 AM, Peter Ledbrook wrote:
>>
>>>> Why is mockConfig removed? I know that in 1.3.x it was kind of broken, in the sense that it only worked for config accessed through ConfigurationHolder.config, and not through grailsApplication.config.
>>>> Shouldn't mockConfig rather be fixed to mock config for grailsApplication.config? Or is there a better way to mock config?
>>>
>>> I believe it's been removed because it's not needed if you're using
>>> grailsApplication.config in your classes.
>>
>> As long as ConfigurationHolder is deprecated, not removed, I think mockConfig should remain, and be deprecated. Or not deprecated, if it were to support mocking of grailsApplication.config as well.
>>
>> Ronny
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>   http://xircles.codehaus.org/manage_email
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...