1/* 2 * Copyright 2001-2008 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._ 23import scala.reflect.BeanProperty 24 25trait CustomFileBePropertyMatchers { 26 27 class FileBePropertyMatcher extends BePropertyMatcher[java.io.File] { 28 def apply(left: java.io.File) = BePropertyMatchResult(left.isFile, "file") 29 } 30 31 class DirectoryBePropertyMatcher extends BePropertyMatcher[java.io.File] { 32 def apply(left: java.io.File) = BePropertyMatchResult(left.isDirectory, "directory") 33 } 34 35 val file = new FileBePropertyMatcher 36 val directory = new DirectoryBePropertyMatcher 37} 38 39class ShouldFileBePropertyMatcherSpec extends Spec with ShouldMatchers with CustomFileBePropertyMatchers { 40 41 describe("A temp file") { 42 43 it("should be a file, not a directory") { 44 45 val tempFile = java.io.File.createTempFile("delete", "me") 46 47 try { 48 tempFile should be a (file) 49 tempFile should not be a (directory) 50 } 51 finally { 52 tempFile.delete() 53 } 54 } 55 } 56} 57