Skip to content

doWithConfig in unit test merges map instead of replacing #10188

@rlovtangen

Description

@rlovtangen

Steps to Reproduce

Add config to application.groovy:

foobar.foo = "1"
foobar.bar = ["1"]
foobar.baz = ["1" : "1"]
baz = ["1" : "1"]

grails create-service Foo and add these tests:

@TestFor(FooService)
class FooServiceSpec extends Specification {

    static doWithConfig(c) {
        c.foobar.foo = "2"
        c.foobar.bar = ["2"]
        c.foobar.baz = ["2": "2"]
        c.baz = ["2": "2"]
    }

    void "test string"() {
        expect:
            grailsApplication.config.foobar.foo == "2"
    }

    void "test list"() {
        expect:
            grailsApplication.config.foobar.bar == ["2"]
    }

    void "test map one level"() {
        expect:
            grailsApplication.config.baz == ["2": "2"]
    }

    void "test map two levels"() {
        expect:
            grailsApplication.config.foobar.baz == ["2": "2"]
    }

}

Expected Behaviour

All tests should pass

Actual Behaviour

The test "test map two levels" fails:

grailsApplication.config.foobar.baz == ["2": "2"]
|                 |      |      |   |
|                 |      |      |   false
|                 |      |      [1:1, 2:2]
|                 |      [foo:2, bar:[2], baz:[1:1, 2:2]]

Note that the test "test map one level" runs fine, which means there are differences based on how deep the property is nested.

Environment Information

  • Operating System: OS X El Capitan
  • Grails Version: 3.2.0
  • JDK Version: 1.8.0_77
  • Container Version (If Applicable):

Example Application

https://github.com/rlovtangen/bugreport-grails-core-doWithConfig

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions