1/*
2 * Copyright 2001-2009 Artima, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.scalatest.matchers
17
18import org.scalatest._
19import org.scalatest.prop.Checkers
20import org.scalacheck._
21import Arbitrary._
22import Prop._
23
24class ShouldBehaveLikeSpec extends Spec {
25
26  def myFirstBehavior(i: Int) {
27    it("This one is should blow up") {}
28  }
29
30  describe("The 'should behave like' syntax should throw an exception inside an it clause") {
31    it("the code in here should fail with an exception") {
32      intercept[TestRegistrationClosedException] {
33        it should behave like myFirstBehavior(1)
34      }
35    }
36  }
37
38  // Checking for a specific size
39/*
40  describe("The 'should behave like' syntax should work in a describe") {
41
42    it should behave like nonEmptyStack(lastValuePushed)(stackWithOneItem)
43
44    describe(", and in a nested describe") {
45
46      it should behave like nonEmptyStack(lastValuePushed)(stackWithOneItem)
47    }
48  }
49*/
50
51  def myBehavior(i: Int) {
52    it("This one is solo") {}
53  }
54  it should behave like myBehavior(1)
55
56  // TODO: Make these into real tests. I looked at it and heck they work. So I can indeed put describe clauses in
57  // the shared behaviors. Cool.
58  def myNestedBehavior(i: Int) {
59    describe("and this is the shared describe") {
60      it("This one is nested") {}
61    }
62  }
63
64  it should behave like myNestedBehavior(1)
65  describe("And outer describe...") {
66    it should behave like myNestedBehavior(1)
67  }
68
69/* Correct, none of these compiled
70  describe("'should not behave like' should not compile") {
71
72    stackWithOneItem should not behave like (nonEmptyStack(lastValuePushed))
73  }
74  describe("The 'should behave like' syntax in an and or or clause, with or without not, should not compile") {
75    stackWithOneItem should (behave like (nonEmptyStack(lastValuePushed)) or behave like (nonFullStack))
76    stackWithOneItem should (behave like (nonEmptyStack(lastValuePushed)) or (behave like (nonFullStack)))
77    stackWithOneItem should (behave like (nonEmptyStack(lastValuePushed)) or not behave like (nonFullStack))
78    stackWithOneItem should (behave like (nonEmptyStack(lastValuePushed)) or (not behave like (nonFullStack)))
79    stackWithOneItem should (behave like (nonEmptyStack(lastValuePushed)) and behave like (nonFullStack))
80    stackWithOneItem should (behave like (nonEmptyStack(lastValuePushed)) and (behave like (nonFullStack)))
81    stackWithOneItem should (behave like (nonEmptyStack(lastValuePushed)) and not behave like (nonFullStack))
82    stackWithOneItem should (behave like (nonEmptyStack(lastValuePushed)) and (not behave like (nonFullStack)))
83  }
84*/
85}
86