この単純なドメインを指定して grails 2.2.0 を使用する
class Order {
static mapping = {table "ticket_order"}
String foo
}
および関連するスポック テスト
@TestFor(Order)
class OrderSpec extends Specification {
def "sensible constraints for order class"() {
setup:
mockForConstraintsTests(Order)
when:
def order = new Order(
foo : foo
)
order.validate()
then:
!order.errors.hasFieldErrors("foo")
where:
foo = "bar"
}
}
私はこの出力を得る
grails> test-app unit: Order -echoOut
| Running 1 spock test... 1 of 1
--Output from sensible constraints for order class--
| Failure: sensible constraints for order class(uk.co.seoss.presscm.OrderSpec)
| Condition not satisfied:
!order.errors.hasFieldErrors("foo")
|| | |
|| | true
|| org.codehaus.groovy.grails.plugins.testing.GrailsMockErrors: 1 errors
|| Field error in object 'uk.co.seoss.presscm.Order' on field 'foo': rejected value [null];
なぜ私がそのnullを取得しているのか、誰かが説明してもらえますか?プロパティを正しく設定していませんか? 私はこれのより簡単な定式化をいくつか試しましたが、喜びはありませんでした. 標準の単体テストでは問題なく動作します。