doFile("context.io") context("single word chain", setup( object := Object clone addWordyMethods( f := method(42) ) ) specify("should work as normal method", object f should be(42) ) ) context("literal single word chain", setup( object := Object clone addWordyMethods(c := 42) ) specify("should not be mangled", object c should be(42) ) ) context("three single word chains", setup( object := Object clone addWordyMethods( f := method(42) g := method(39) h := method(18) ) ) specify("should create each method", object f should be(42) object g should be(39) object h should be(18) ) ) context("single word chain which uses self", setup( object := Object clone addWordyMethods( f := method(self x) g := method(x) ) object x := 42 ) specify("should be able to access self", object f should be(42) ) specify("should be able to automatically access slots on self", object g should be(42) ) ) context("empty wordy builder", setup( builder := WordyBuilder clone ) specify("should lazily add builders", builder get("a") get("b") get("c") ) specify("should return same lazily created builder on subsequent calls to get", builder get("a") should be(builder get("a")) ) specify("should be empty", builder isEmpty should be(true) ) specify("should not have children", builder hasChildren should be(false) ) specify("should store a value without evaluating", builder TestException := Exception clone builder setValue(method(TestException raise("Testing..."))) try(builder value) should not raise(TestException) ) specify("should not have value by default", builder hasValue should be(false) ) specify("should allow setValue to be chained", a := builder get("a") a setValue(13) should be(a) ) ) context("WordyBuilder with value", setup( builder := WordyBuilder clone builder setValue(42) ) specify("should return true for hasValue", builder hasValue should be(true) ) ) context("Nested WordyBuilder", setup( builder := WordyBuilder clone adam := builder get("adam") bill := adam get("bill") clark := bill get("clark") ) specify("should set depth correctly", adam depth should be(1) bill depth should be(2) clark depth should be(3) ) specify("should create messageNames", adam messageName should equal("adam") bill messageName should equal("adamBill") clark messageName should equal("adamBillClark") ) specify("should be named", adam name should equal("adam") bill name should equal("bill") clark name should equal("clark") ) ) context("leaf builder", setup( builder := WordyBuilder clone a := builder get("a") setValue(method(42)) b := builder get("b1") get("b2") setValue(method(assertFail)) c := builder get("c1") get("c2") get("c3") setValue(method(assertFail)) ) specify("level 1 handler should return value", f := a handlerMethod f should be(42) ) specify("level 2 handler should return value", f := b handlerMethod target := Object clone do( b1B2 := method(39) ) f should be(39) ) specify("level 3 handler should return value", f := c handlerMethod target := Object clone do( c1C2C3 := method(18) ) f should be(18) ) ) context("level 1 inner builder", setup( builder := WordyBuilder clone a := builder get("a") a get("b1") setValue(method(assertFail)) a get("b2") setValue(method(assertFail)) ) specify("should return object with next methods", f := a handlerMethod f hasSlot("b1") should equal(true) f hasSlot("b2") should equal(true) ) specify("should setup child handlers on scope", aB1 := method(1) aB2 := method(2) f := a handlerMethod f b1 should be(1) f b2 should be(2) ) ) context("nested builders with values on leaves", setup( builder := WordyBuilder clone a := builder get("a") builder get("a") get("b") get("c") setValue(method(assertFail)) builder get("a") get("b") get("d") setValue(method(assertFail)) builder get("a") get("e") get("g") get("l") setValue(method(assertFail)) builder get("a") get("h") setValue(method(assertFail)) ) specify("should recursivly setup child handlers", aBC := method("c") aBD := method("d") aEGL := method("l") aH := method("h") f := a handlerMethod f b c should equal("c") f b d should equal("d") f e g l should equal("l") f h should equal("h") ) ) context("first builder with children and no value", setup( builder := WordyBuilder clone a := builder get("a") a get("b") setValue(method(assertFail)) a get("c") setValue(method(assertFail)) ) specify("should return wordyScope", aB := method(1) aC := method(2) f := a handlerMethod f b should be(1) f c should be(2) ) ) context("first builder with children and value", setup( builder := WordyBuilder clone a := builder get("a") setValue(method(x, x + 1)) a get("b") setValue(method(assertFail)) a get("c") setValue(method(assertFail)) ) specify("should call value when passed arguments", f := a handlerMethod(thisContext) f(13) should be(14) ) specify("should return wordyScope when not passed arguments", aB := method(1) aC := method(2) f := a handlerMethod f b should be(1) f c should be(2) ) ) context("inner builder with children and value", setup( builder := WordyBuilder clone b := builder get("a") get("b") setValue(method(1)) b get("c") setValue(method(assertFail)) b get("d") setValue(method(assertFail)) ) specify("should call value when passed arguments", f := b handlerMethod target := Object clone do( aB := method(x, x + 1) ) f(13) should be(14) ) specify("should return wordyScope when not passed arguments", f := b handlerMethod target := Object clone do( aBC := method(3) aBD := method(4) ) f c should be(3) f d should be(4) ) ) context("simple two word chain", setup( object := Object clone addWordyMethods( a b := method(42) ) ) specify("should be able to invoke method", object a b should be(42) ) ) context("simple two word chain that uses self", setup( object := Object clone addWordyMethods( a b := method(x) ) object x := 42 ) specify("should be able to use slots on self automatically", object a b should be(42) ) ) context("list with wordy methods", setup( MyList := List clone addWordyMethods( should contain := method(value, assertTrue(contains(value))) should not contain := method(value, assertFalse(contains(value))) should have := method(expectedSize, assertEquals(expectedSize, size)) should not have := method(expectedSize, assertNotEquals(expectedSize, size)) should have at least := method(minSize, assertTrue(size >= minSize)) should have at most := method(maxSize, assertTrue(size <= maxSize)) ) l := MyList clone ) specify("should not contain 13", l should not contain(13) ) )