change should == to shouldBe
[tspec.git] / src / java / org / tspec / ThaiSpecBinding.java
blob8d10911f0a3fc10ade68aaf9826b598aab321b69
1 package org.tspec;
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) {
25 super();
26 this.el = el;
27 init();
30 private void init() {
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));
36 setupShouldAndMust();
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());
47 obj.setEl(el);
48 return obj;
51 /* Closure mustClosure = new Closure(null){
52 @SuppressWarnings("unused")
53 public MustObject doCall() {
54 return new MustObject(this.getDelegate());
56 }; */
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);
63 obj.setEl(el);
64 return obj.equals(o);
67 Closure shouldNotBe = new Closure(null){
68 @SuppressWarnings("unused")
69 public Object doCall(Object o) {
70 ShouldObject obj = new ShouldObject(this.getDelegate());
71 obj.setEl(el);
72 return obj.equals(o);
75 mc.setProperty("getShould", shouldClosure);
76 // mc.setProperty("getMust", mustClosure);
77 mc.setProperty("shouldBe", shouldBe);
78 mc.setProperty("shouldNotBe", shouldNotBe);