Permalink
Browse files

Added toHaveSlot matcher (non-recursive)

  • Loading branch information...
1 parent 40b9aac commit aef55f2b1ec847de5127daafecc8587d3a71b026 @johshoff committed Aug 24, 2012
Showing with 20 additions and 0 deletions.
  1. +6 −0 jasmine.io
  2. +14 −0 matcher_spec.io
View
@@ -54,6 +54,12 @@ Matcher toThrow := method(
)
)
+Matcher toHaveSlot := method(expected,
+ if ((actual slotNames) contains(expected), return true)
+ self message := "Expected object to have slot " .. expected .. ", but it didn't."
+ false
+)
+
Matcher message := method(inverted,
"Expected " .. actual .. if(inverted, " not ", " ") .. expectiation fromCamelCaseToSentence .. " " .. expected
)
View
@@ -124,6 +124,20 @@ describe("List matcher",
)
)
+describe("toHaveSlot matcher",
+ it("can find a slot on an object",
+ obj := Object clone
+ obj foo := nil
+ expect(obj) toHaveSlot("foo")
+ ),
+
+ it("should fail to find a non-existing slot on an object",
+ obj := Object clone
+ ex := try(expect(obj) toHaveSlot("foo"))
+ expect(ex error) toBe("Expected object to have slot foo, but it didn't.")
+ )
+)
+
describe("Not matcher",
it("inverts expectation",
result := expect(1) not toEqual(2)

0 comments on commit aef55f2

Please sign in to comment.