Details
Description
I have these tests:
@TestFor(Book)
class BookTests {
void testMetaClassOnce() {
assert !Book.metaClass.hasMetaMethod('foo')
Book.metaClass."static".foo = {-> 'bar' }
assert Book.metaClass.hasMetaMethod('foo')
assert Book.foo() == 'bar'
}
void testMetaClassTwice() {
assert !Book.metaClass.hasMetaMethod('foo')
Book.metaClass."static".foo = {-> 'bar' }
assert Book.metaClass.hasMetaMethod('foo')
assert Book.foo() == 'bar'
}
}
When run from the command line, they pass every time. When run from grails interactive mode using "test-app unit:", they both pass the first time but fail the second time. The failure points to the first line of the test, indicating that the meta methods are still present.
grails> test-app unit: | Completed 2 unit tests, 0 failed in 2526ms | Tests PASSED - view reports in target/test-reports grails> test-app unit: | Running 2 unit tests... 1 of 2 | Failure: testMetaClassOnce(metaclasstest.BookTests) | Assertion failed: assert !Book.metaClass.hasMetaMethod('foo') | | | false | true groovy.lang.ExpandoMetaClass@241ee2c5[class metaclasstest.Book] at metaclasstest.BookTests.testMetaClassOnce(BookTests.groovy:9) | Running 2 unit tests... 2 of 2 | Failure: testMetaClassTwice(metaclasstest.BookTests) | Assertion failed: assert !Book.metaClass.hasMetaMethod('foo') | | | false | true groovy.lang.ExpandoMetaClass@241ee2c5[class metaclasstest.Book] at metaclasstest.BookTests.testMetaClassTwice(BookTests.groovy:18) | Completed 2 unit tests, 2 failed in 186ms | Tests FAILED - view reports in target/test-reports
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits