3 import groovy
.lang
.Binding
;
4 import groovy
.lang
.Closure
;
5 import groovy
.lang
.ExpandoMetaClass
;
6 import groovy
.lang
.ExpandoMetaClassCreationHandle
;
7 import groovy
.lang
.GroovySystem
;
8 import groovy
.lang
.MetaClassRegistry
;
10 import org
.tspec
.closure
.AfterClosure
;
11 import org
.tspec
.closure
.BeforeClosure
;
12 import org
.tspec
.closure
.ScenarioClosure
;
13 import org
.tspec
.closure
.SubjectClosure
;
14 import org
.tspec
.dom
.Story
;
15 import org
.tspec
.runtime
.MustObject
;
16 import org
.tspec
.runtime
.ShouldObject
;
17 import org
.tspec
.runtime
.ErrorListener
;
20 public class ThaiSpecBinding
extends Binding
{
22 private ErrorListener el
;
24 public ThaiSpecBinding(ErrorListener el
) {
31 Story root
= new Story();
32 setVariable("เรื่อง", new SubjectClosure(root
));
33 setVariable("อธิบาย", new ScenarioClosure(root
));
34 setVariable("ก่อน", new BeforeClosure(root
));
35 setVariable("หลัง", new AfterClosure(root
));
39 private void setupShouldAndMust() {
40 ExpandoMetaClassCreationHandle
.enable();
41 MetaClassRegistry mr
= GroovySystem
.getMetaClassRegistry();
42 ExpandoMetaClass mc
= (ExpandoMetaClass
)mr
.getMetaClass(Object
.class);
43 Closure shouldClosure
= new Closure(null){
44 @SuppressWarnings("unused")
45 public ShouldObject
doCall() {
46 ShouldObject obj
= new ShouldObject(this.getDelegate());
51 /* Closure mustClosure = new Closure(null){
52 @SuppressWarnings("unused")
53 public MustObject doCall() {
54 return new MustObject(this.getDelegate());
57 Closure shouldBe
= new Closure(null){
58 @SuppressWarnings("unused")
59 public Object
doCall(Object o
) {
60 // System.out.println("=================== >>> I'm being called");
61 // System.out.println("so what's it : " + this.getDelegate());
62 ShouldObject obj
= new ShouldObject(this.getDelegate(), true);
67 Closure shouldNotBe
= new Closure(null){
68 @SuppressWarnings("unused")
69 public Object
doCall(Object o
) {
70 ShouldObject obj
= new ShouldObject(this.getDelegate());
75 mc
.setProperty("getShould", shouldClosure
);
76 // mc.setProperty("getMust", mustClosure);
77 mc
.setProperty("shouldBe", shouldBe
);
78 mc
.setProperty("shouldNotBe", shouldNotBe
);