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 25class ShouldBePropertyMatcherSpec extends Spec with ShouldMatchers with Checkers with ReturnsNormallyThrowsAssertion with BookPropertyMatchers { 26 27 // Checking for a specific size 28 describe("The be (BePropertyMatcher) syntax") { 29 30 case class MyFile( 31 val name: String, 32 val file: Boolean, 33 val isDirectory: Boolean 34 ) 35 36 class FileBePropertyMatcher extends BePropertyMatcher[MyFile] { 37 def apply(file: MyFile) = { 38 new BePropertyMatchResult(file.file, "file") 39 } 40 } 41 42 class DirectoryBePropertyMatcher extends BePropertyMatcher[MyFile] { 43 def apply(file: MyFile) = { 44 new BePropertyMatchResult(file.isDirectory, "directory") 45 } 46 } 47 48 def file = new FileBePropertyMatcher 49 def directory = new DirectoryBePropertyMatcher 50 51 val myFile = new MyFile("temp.txt", true, false) 52 53 val book = new Book("A Tale of Two Cities", "Dickens", 1859, 45, true) 54 val badBook = new Book("A Tale of Two Cities", "Dickens", 1859, 45, false) 55 56 it("should do nothing if the property is true") { 57 book should be (goodRead) 58 book should be a (goodRead) 59 book should be an (goodRead) 60 } 61 62 it("should throw TestFailedException if the property is false") { 63 64 val caught1 = intercept[TestFailedException] { 65 badBook should be (goodRead) 66 } 67 assert(caught1.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,false) was not goodRead") 68 69 val caught2 = intercept[TestFailedException] { 70 badBook should be a (goodRead) 71 } 72 assert(caught2.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,false) was not a goodRead") 73 74 val caught3 = intercept[TestFailedException] { 75 badBook should be an (goodRead) 76 } 77 assert(caught3.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,false) was not an goodRead") 78 } 79 80 it("should do nothing if the property is false, when used with not") { 81 badBook should not be (goodRead) 82 badBook should not be a (goodRead) 83 badBook should not be an (goodRead) 84 } 85 86 it("should throw TestFailedException if the property is true, when used with not") { 87 88 val caught1 = intercept[TestFailedException] { 89 book should not be (goodRead) 90 } 91 assert(caught1.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,true) was goodRead") 92 93 val caught2 = intercept[TestFailedException] { 94 book should not be a (goodRead) 95 } 96 assert(caught2.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,true) was a goodRead") 97 98 val caught3 = intercept[TestFailedException] { 99 book should not be an (goodRead) 100 } 101 assert(caught3.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,true) was an goodRead") 102 103 val caught4 = intercept[TestFailedException] { 104 book should not (be (goodRead)) 105 } 106 assert(caught4.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,true) was goodRead") 107 108 val caught5 = intercept[TestFailedException] { 109 book should not (be a (goodRead)) 110 } 111 assert(caught5.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,true) was a goodRead") 112 113 val caught6 = intercept[TestFailedException] { 114 book should not (be an (goodRead)) 115 } 116 assert(caught6.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,true) was an goodRead") 117 118 val caught7 = intercept[TestFailedException] { 119 book should (not (be (goodRead))) 120 } 121 assert(caught7.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,true) was goodRead") 122 123 val caught8 = intercept[TestFailedException] { 124 book should (not (be a (goodRead))) 125 } 126 assert(caught8.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,true) was a goodRead") 127 128 val caught9 = intercept[TestFailedException] { 129 book should (not (be an (goodRead))) 130 } 131 assert(caught9.getMessage === "Book(A Tale of Two Cities,Dickens,1859,45,true) was an goodRead") 132 } 133 134 it("should do nothing if the the property returns true, when used in a logical-and expression") { 135 136 myFile should ((be (file)) and (be (file))) 137 myFile should (be (file) and (be (file))) 138 myFile should (be (file) and be (file)) 139 140 myFile should ((be a (file)) and (be a (file))) 141 myFile should (be a (file) and (be a (file))) 142 myFile should (be a (file) and be a (file)) 143 144 myFile should ((be an (file)) and (be an (file))) 145 myFile should (be an (file) and (be an (file))) 146 myFile should (be an (file) and be an (file)) 147 } 148 149 it("should throw TestFailedException if at least one of the properties returns false, when used in a logical-and expression") { 150 151 // first false 152 val caught1 = intercept[TestFailedException] { 153 myFile should ((be (directory)) and (be (file))) 154 } 155 assert(caught1.getMessage === "MyFile(temp.txt,true,false) was not directory") 156 157 val caught2 = intercept[TestFailedException] { 158 myFile should (be (directory) and (be (file))) 159 } 160 assert(caught2.getMessage === "MyFile(temp.txt,true,false) was not directory") 161 162 val caught3 = intercept[TestFailedException] { 163 myFile should (be (directory) and be (file)) 164 } 165 assert(caught3.getMessage === "MyFile(temp.txt,true,false) was not directory") 166 167 168 val caught4 = intercept[TestFailedException] { 169 myFile should ((be a (directory)) and (be a (file))) 170 } 171 assert(caught4.getMessage === "MyFile(temp.txt,true,false) was not a directory") 172 173 val caught5 = intercept[TestFailedException] { 174 myFile should (be a (directory) and (be a (file))) 175 } 176 assert(caught5.getMessage === "MyFile(temp.txt,true,false) was not a directory") 177 178 val caught6 = intercept[TestFailedException] { 179 myFile should (be a (directory) and be a (file)) 180 } 181 assert(caught6.getMessage === "MyFile(temp.txt,true,false) was not a directory") 182 183 184 val caught7 = intercept[TestFailedException] { 185 myFile should ((be an (directory)) and (be an (file))) 186 } 187 assert(caught7.getMessage === "MyFile(temp.txt,true,false) was not an directory") 188 189 val caught8 = intercept[TestFailedException] { 190 myFile should (be an (directory) and (be an (file))) 191 } 192 assert(caught8.getMessage === "MyFile(temp.txt,true,false) was not an directory") 193 194 val caught9 = intercept[TestFailedException] { 195 myFile should (be an (directory) and be an (file)) 196 } 197 assert(caught9.getMessage === "MyFile(temp.txt,true,false) was not an directory") 198 199 200 // second false 201 val caught10 = intercept[TestFailedException] { 202 myFile should ((be (file)) and (be (directory))) 203 } 204 assert(caught10.getMessage === "MyFile(temp.txt,true,false) was file, but MyFile(temp.txt,true,false) was not directory") 205 206 val caught11 = intercept[TestFailedException] { 207 myFile should (be (file) and (be (directory))) 208 } 209 assert(caught11.getMessage === "MyFile(temp.txt,true,false) was file, but MyFile(temp.txt,true,false) was not directory") 210 211 val caught12 = intercept[TestFailedException] { 212 myFile should (be (file) and be (directory)) 213 } 214 assert(caught12.getMessage === "MyFile(temp.txt,true,false) was file, but MyFile(temp.txt,true,false) was not directory") 215 216 217 val caught13 = intercept[TestFailedException] { 218 myFile should ((be a (file)) and (be a (directory))) 219 } 220 assert(caught13.getMessage === "MyFile(temp.txt,true,false) was a file, but MyFile(temp.txt,true,false) was not a directory") 221 222 val caught14 = intercept[TestFailedException] { 223 myFile should (be a (file) and (be a (directory))) 224 } 225 assert(caught14.getMessage === "MyFile(temp.txt,true,false) was a file, but MyFile(temp.txt,true,false) was not a directory") 226 227 val caught15 = intercept[TestFailedException] { 228 myFile should (be a (file) and be a (directory)) 229 } 230 assert(caught15.getMessage === "MyFile(temp.txt,true,false) was a file, but MyFile(temp.txt,true,false) was not a directory") 231 232 233 val caught16 = intercept[TestFailedException] { 234 myFile should ((be an (file)) and (be an (directory))) 235 } 236 assert(caught16.getMessage === "MyFile(temp.txt,true,false) was an file, but MyFile(temp.txt,true,false) was not an directory") 237 238 val caught17 = intercept[TestFailedException] { 239 myFile should (be an (file) and (be an (directory))) 240 } 241 assert(caught17.getMessage === "MyFile(temp.txt,true,false) was an file, but MyFile(temp.txt,true,false) was not an directory") 242 243 val caught18 = intercept[TestFailedException] { 244 myFile should (be an (file) and be an (directory)) 245 } 246 assert(caught18.getMessage === "MyFile(temp.txt,true,false) was an file, but MyFile(temp.txt,true,false) was not an directory") 247 248 249 // both false 250 val caught19 = intercept[TestFailedException] { 251 myFile should ((be (directory)) and (be (directory))) 252 } 253 assert(caught19.getMessage === "MyFile(temp.txt,true,false) was not directory") 254 255 val caught20 = intercept[TestFailedException] { 256 myFile should (be (directory) and (be (directory))) 257 } 258 assert(caught20.getMessage === "MyFile(temp.txt,true,false) was not directory") 259 260 val caught21 = intercept[TestFailedException] { 261 myFile should (be (directory) and be (directory)) 262 } 263 assert(caught21.getMessage === "MyFile(temp.txt,true,false) was not directory") 264 265 266 val caught22 = intercept[TestFailedException] { 267 myFile should ((be a (directory)) and (be a (directory))) 268 } 269 assert(caught22.getMessage === "MyFile(temp.txt,true,false) was not a directory") 270 271 val caught23 = intercept[TestFailedException] { 272 myFile should (be a (directory) and (be a (directory))) 273 } 274 assert(caught23.getMessage === "MyFile(temp.txt,true,false) was not a directory") 275 276 val caught24 = intercept[TestFailedException] { 277 myFile should (be a (directory) and be a (directory)) 278 } 279 assert(caught24.getMessage === "MyFile(temp.txt,true,false) was not a directory") 280 281 282 val caught25 = intercept[TestFailedException] { 283 myFile should ((be an (directory)) and (be an (directory))) 284 } 285 assert(caught25.getMessage === "MyFile(temp.txt,true,false) was not an directory") 286 287 val caught26 = intercept[TestFailedException] { 288 myFile should (be an (directory) and (be an (directory))) 289 } 290 assert(caught26.getMessage === "MyFile(temp.txt,true,false) was not an directory") 291 292 val caught27 = intercept[TestFailedException] { 293 myFile should (be an (directory) and be an (directory)) 294 } 295 assert(caught27.getMessage === "MyFile(temp.txt,true,false) was not an directory") 296 } 297 298 it("should do nothing if the property returns true, when used in a logical-or expression") { 299 300 // second true 301 myFile should ((be (directory)) or (be (file))) 302 myFile should (be (directory) or (be (file))) 303 myFile should (be (directory) or be (file)) 304 305 myFile should ((be a (directory)) or (be a (file))) 306 myFile should (be a (directory) or (be a (file))) 307 myFile should (be a (directory) or be a (file)) 308 309 myFile should ((be an (directory)) or (be an (file))) 310 myFile should (be an (directory) or (be an (file))) 311 myFile should (be an (directory) or be an (file)) 312 313 // first true 314 myFile should ((be (file)) or (be (directory))) 315 myFile should (be (file) or (be (directory))) 316 myFile should (be (file) or be (directory)) 317 318 myFile should ((be a (file)) or (be a (directory))) 319 myFile should (be a (file) or (be a (directory))) 320 myFile should (be a (file) or be a (directory)) 321 322 myFile should ((be an (file)) or (be an (directory))) 323 myFile should (be an (file) or (be an (directory))) 324 myFile should (be an (file) or be an (directory)) 325 326 // both true 327 myFile should ((be (file)) or (be (file))) 328 myFile should (be (file) or (be (file))) 329 myFile should (be (file) or be (file)) 330 331 myFile should ((be a (file)) or (be a (file))) 332 myFile should (be a (file) or (be a (file))) 333 myFile should (be a (file) or be a (file)) 334 335 myFile should ((be an (file)) or (be an (file))) 336 myFile should (be an (file) or (be an (file))) 337 myFile should (be an (file) or be an (file)) 338 } 339 340 it("should throw TestFailedException if the both properties return false, when used in a logical-or expression") { 341 342 val caught1 = intercept[TestFailedException] { 343 myFile should ((be (directory)) or (be (directory))) 344 } 345 assert(caught1.getMessage === "MyFile(temp.txt,true,false) was not directory, and MyFile(temp.txt,true,false) was not directory") 346 347 val caught2 = intercept[TestFailedException] { 348 myFile should (be (directory) or (be (directory))) 349 } 350 assert(caught2.getMessage === "MyFile(temp.txt,true,false) was not directory, and MyFile(temp.txt,true,false) was not directory") 351 352 val caught3 = intercept[TestFailedException] { 353 myFile should (be (directory) or be (directory)) 354 } 355 assert(caught3.getMessage === "MyFile(temp.txt,true,false) was not directory, and MyFile(temp.txt,true,false) was not directory") 356 357 358 val caught4 = intercept[TestFailedException] { 359 myFile should ((be a (directory)) or (be a (directory))) 360 } 361 assert(caught4.getMessage === "MyFile(temp.txt,true,false) was not a directory, and MyFile(temp.txt,true,false) was not a directory") 362 363 val caught5 = intercept[TestFailedException] { 364 myFile should (be a (directory) or (be a (directory))) 365 } 366 assert(caught5.getMessage === "MyFile(temp.txt,true,false) was not a directory, and MyFile(temp.txt,true,false) was not a directory") 367 368 val caught6 = intercept[TestFailedException] { 369 myFile should (be a (directory) or be a (directory)) 370 } 371 assert(caught6.getMessage === "MyFile(temp.txt,true,false) was not a directory, and MyFile(temp.txt,true,false) was not a directory") 372 373 374 val caught7 = intercept[TestFailedException] { 375 myFile should ((be an (directory)) or (be an (directory))) 376 } 377 assert(caught7.getMessage === "MyFile(temp.txt,true,false) was not an directory, and MyFile(temp.txt,true,false) was not an directory") 378 379 val caught8 = intercept[TestFailedException] { 380 myFile should (be an (directory) or (be an (directory))) 381 } 382 assert(caught8.getMessage === "MyFile(temp.txt,true,false) was not an directory, and MyFile(temp.txt,true,false) was not an directory") 383 384 val caught9 = intercept[TestFailedException] { 385 myFile should (be an (directory) or be an (directory)) 386 } 387 assert(caught9.getMessage === "MyFile(temp.txt,true,false) was not an directory, and MyFile(temp.txt,true,false) was not an directory") 388 } 389 390 it("should do nothing if the property returns false, when used in a logical-and expression with not") { 391 392 myFile should (not (be (directory)) and not (be (directory))) 393 myFile should ((not be (directory)) and (not be (directory))) 394 myFile should (not be (directory) and not be (directory)) 395 396 myFile should (not (be a (directory)) and not (be a (directory))) 397 myFile should ((not be a (directory)) and (not be a (directory))) 398 myFile should (not be a (directory) and not be a (directory)) 399 400 myFile should (not (be an (directory)) and not (be an (directory))) 401 myFile should ((not be an (directory)) and (not be an (directory))) 402 myFile should (not be an (directory) and not be an (directory)) 403 } 404 405 it("should throw TestFailedException if at least one property returns false, when used in a logical-and expression with not") { 406 407 // second false 408 val caught1 = intercept[TestFailedException] { 409 myFile should (not (be (directory)) and not (be (file))) 410 } 411 assert(caught1.getMessage === "MyFile(temp.txt,true,false) was not directory, but MyFile(temp.txt,true,false) was file") 412 413 val caught2 = intercept[TestFailedException] { 414 myFile should ((not be (directory)) and (not be (file))) 415 } 416 assert(caught2.getMessage === "MyFile(temp.txt,true,false) was not directory, but MyFile(temp.txt,true,false) was file") 417 418 val caught3 = intercept[TestFailedException] { 419 myFile should (not be (directory) and not be (file)) 420 } 421 assert(caught3.getMessage === "MyFile(temp.txt,true,false) was not directory, but MyFile(temp.txt,true,false) was file") 422 423 424 val caught4 = intercept[TestFailedException] { 425 myFile should (not (be a (directory)) and not (be a (file))) 426 } 427 assert(caught4.getMessage === "MyFile(temp.txt,true,false) was not a directory, but MyFile(temp.txt,true,false) was a file") 428 429 val caught5 = intercept[TestFailedException] { 430 myFile should ((not be a (directory)) and (not be a (file))) 431 } 432 assert(caught5.getMessage === "MyFile(temp.txt,true,false) was not a directory, but MyFile(temp.txt,true,false) was a file") 433 434 val caught6 = intercept[TestFailedException] { 435 myFile should (not be a (directory) and not be a (file)) 436 } 437 assert(caught6.getMessage === "MyFile(temp.txt,true,false) was not a directory, but MyFile(temp.txt,true,false) was a file") 438 439 440 val caught7 = intercept[TestFailedException] { 441 myFile should (not (be an (directory)) and not (be an (file))) 442 } 443 assert(caught7.getMessage === "MyFile(temp.txt,true,false) was not an directory, but MyFile(temp.txt,true,false) was an file") 444 445 val caught8 = intercept[TestFailedException] { 446 myFile should ((not be an (directory)) and (not be an (file))) 447 } 448 assert(caught8.getMessage === "MyFile(temp.txt,true,false) was not an directory, but MyFile(temp.txt,true,false) was an file") 449 450 val caught9 = intercept[TestFailedException] { 451 myFile should (not be an (directory) and not be an (file)) 452 } 453 assert(caught9.getMessage === "MyFile(temp.txt,true,false) was not an directory, but MyFile(temp.txt,true,false) was an file") 454 455 456 // first false 457 val caught10 = intercept[TestFailedException] { 458 myFile should (not (be (file)) and not (be (directory))) 459 } 460 assert(caught10.getMessage === "MyFile(temp.txt,true,false) was file") 461 462 val caught11 = intercept[TestFailedException] { 463 myFile should ((not be (file)) and (not be (directory))) 464 } 465 assert(caught11.getMessage === "MyFile(temp.txt,true,false) was file") 466 467 val caught12 = intercept[TestFailedException] { 468 myFile should (not be (file) and not be (directory)) 469 } 470 assert(caught12.getMessage === "MyFile(temp.txt,true,false) was file") 471 472 473 val caught13 = intercept[TestFailedException] { 474 myFile should (not (be a (file)) and not (be a (directory))) 475 } 476 assert(caught13.getMessage === "MyFile(temp.txt,true,false) was a file") 477 478 val caught14 = intercept[TestFailedException] { 479 myFile should ((not be a (file)) and (not be a (directory))) 480 } 481 assert(caught14.getMessage === "MyFile(temp.txt,true,false) was a file") 482 483 val caught15 = intercept[TestFailedException] { 484 myFile should (not be a (file) and not be a (directory)) 485 } 486 assert(caught15.getMessage === "MyFile(temp.txt,true,false) was a file") 487 488 489 val caught16 = intercept[TestFailedException] { 490 myFile should (not (be an (file)) and not (be an (directory))) 491 } 492 assert(caught16.getMessage === "MyFile(temp.txt,true,false) was an file") 493 494 val caught17 = intercept[TestFailedException] { 495 myFile should ((not be an (file)) and (not be an (directory))) 496 } 497 assert(caught17.getMessage === "MyFile(temp.txt,true,false) was an file") 498 499 val caught18 = intercept[TestFailedException] { 500 myFile should (not be an (file) and not be an (directory)) 501 } 502 assert(caught18.getMessage === "MyFile(temp.txt,true,false) was an file") 503 504 505 // both false 506 val caught19 = intercept[TestFailedException] { 507 myFile should (not (be (file)) and not (be (file))) 508 } 509 assert(caught19.getMessage === "MyFile(temp.txt,true,false) was file") 510 511 val caught20 = intercept[TestFailedException] { 512 myFile should ((not be (file)) and (not be (file))) 513 } 514 assert(caught20.getMessage === "MyFile(temp.txt,true,false) was file") 515 516 val caught21 = intercept[TestFailedException] { 517 myFile should (not be (file) and not be (file)) 518 } 519 assert(caught21.getMessage === "MyFile(temp.txt,true,false) was file") 520 521 522 val caught22 = intercept[TestFailedException] { 523 myFile should (not (be a (file)) and not (be a (file))) 524 } 525 assert(caught22.getMessage === "MyFile(temp.txt,true,false) was a file") 526 527 val caught23 = intercept[TestFailedException] { 528 myFile should ((not be a (file)) and (not be a (file))) 529 } 530 assert(caught23.getMessage === "MyFile(temp.txt,true,false) was a file") 531 532 val caught24 = intercept[TestFailedException] { 533 myFile should (not be a (file) and not be a (file)) 534 } 535 assert(caught24.getMessage === "MyFile(temp.txt,true,false) was a file") 536 537 538 val caught25 = intercept[TestFailedException] { 539 myFile should (not (be an (file)) and not (be an (file))) 540 } 541 assert(caught25.getMessage === "MyFile(temp.txt,true,false) was an file") 542 543 val caught26 = intercept[TestFailedException] { 544 myFile should ((not be an (file)) and (not be an (file))) 545 } 546 assert(caught26.getMessage === "MyFile(temp.txt,true,false) was an file") 547 548 val caught27 = intercept[TestFailedException] { 549 myFile should (not be an (file) and not be an (file)) 550 } 551 assert(caught27.getMessage === "MyFile(temp.txt,true,false) was an file") 552 } 553 554 it("should do nothing if the property returns false, when used in a logical-or expression with not") { 555 556 // first true 557 myFile should (not (be (directory)) or not (be (file))) 558 myFile should ((not be (directory)) or (not be (file))) 559 myFile should (not be (directory) or not be (file)) 560 561 myFile should (not (be a (directory)) or not (be a (file))) 562 myFile should ((not be a (directory)) or (not be a (file))) 563 myFile should (not be a (directory) or not be a (file)) 564 565 myFile should (not (be an (directory)) or not (be an (file))) 566 myFile should ((not be an (directory)) or (not be an (file))) 567 myFile should (not be an (directory) or not be an (file)) 568 569 // second true 570 myFile should (not (be (file)) or not (be (directory))) 571 myFile should ((not be (file)) or (not be (directory))) 572 myFile should (not be (file) or not be (directory)) 573 574 myFile should (not (be a (file)) or not (be a (directory))) 575 myFile should ((not be a (file)) or (not be a (directory))) 576 myFile should (not be a (file) or not be a (directory)) 577 578 myFile should (not (be an (file)) or not (be an (directory))) 579 myFile should ((not be an (file)) or (not be an (directory))) 580 myFile should (not be an (file) or not be an (directory)) 581 582 // both true 583 myFile should (not (be (directory)) or not (be (directory))) 584 myFile should ((not be (directory)) or (not be (directory))) 585 myFile should (not be (directory) or not be (directory)) 586 587 myFile should (not (be a (directory)) or not (be a (directory))) 588 myFile should ((not be a (directory)) or (not be a (directory))) 589 myFile should (not be a (directory) or not be a (directory)) 590 591 myFile should (not (be an (directory)) or not (be an (directory))) 592 myFile should ((not be an (directory)) or (not be an (directory))) 593 myFile should (not be an (directory) or not be an (directory)) 594 } 595 596 it("should throw TestFailedException if both properties return false, when used in a logical-or expression with not") { 597 598 val caught1 = intercept[TestFailedException] { 599 myFile should (not (be (file)) or not (be (file))) 600 } 601 assert(caught1.getMessage === "MyFile(temp.txt,true,false) was file, and MyFile(temp.txt,true,false) was file") 602 603 val caught2 = intercept[TestFailedException] { 604 myFile should ((not be (file)) or (not be (file))) 605 } 606 assert(caught2.getMessage === "MyFile(temp.txt,true,false) was file, and MyFile(temp.txt,true,false) was file") 607 608 val caught3 = intercept[TestFailedException] { 609 myFile should (not be (file) or not be (file)) 610 } 611 assert(caught3.getMessage === "MyFile(temp.txt,true,false) was file, and MyFile(temp.txt,true,false) was file") 612 613 614 val caught4 = intercept[TestFailedException] { 615 myFile should (not (be a (file)) or not (be a (file))) 616 } 617 assert(caught4.getMessage === "MyFile(temp.txt,true,false) was a file, and MyFile(temp.txt,true,false) was a file") 618 619 val caught5 = intercept[TestFailedException] { 620 myFile should ((not be a (file)) or (not be a (file))) 621 } 622 assert(caught5.getMessage === "MyFile(temp.txt,true,false) was a file, and MyFile(temp.txt,true,false) was a file") 623 624 val caught6 = intercept[TestFailedException] { 625 myFile should (not be a (file) or not be a (file)) 626 } 627 assert(caught6.getMessage === "MyFile(temp.txt,true,false) was a file, and MyFile(temp.txt,true,false) was a file") 628 629 630 val caught7 = intercept[TestFailedException] { 631 myFile should (not (be an (file)) or not (be an (file))) 632 } 633 assert(caught7.getMessage === "MyFile(temp.txt,true,false) was an file, and MyFile(temp.txt,true,false) was an file") 634 635 val caught8 = intercept[TestFailedException] { 636 myFile should ((not be an (file)) or (not be an (file))) 637 } 638 assert(caught8.getMessage === "MyFile(temp.txt,true,false) was an file, and MyFile(temp.txt,true,false) was an file") 639 640 val caught9 = intercept[TestFailedException] { 641 myFile should (not be an (file) or not be an (file)) 642 } 643 assert(caught9.getMessage === "MyFile(temp.txt,true,false) was an file, and MyFile(temp.txt,true,false) was an file") 644 } 645 } 646 describe("the compose method on BePropertyMatcher") { 647 it("should return another BePropertyMatcher") { 648 val book1 = new Book("A Tale of Two Cities", "Dickens", 1859, 45, true) 649 val book2 = new Book("The Handmaid's Tail", "Atwood", 1985, 200, true) 650 val badBook = new Book("Some Bad Book", "Bad Author", 1999, 150, false) 651 case class Library(books: List[Book]) 652 val goodLibrary = Library(List(book1, book2)) 653 val badLibrary = Library(List(badBook, book1, book2)) 654 val filledWithGoodReads = goodRead compose { (lib: Library) => lib.books.head } 655 goodLibrary should be (filledWithGoodReads) 656 badLibrary should not be (filledWithGoodReads) 657 } 658 } 659 describe("A factory method on BePropertyMatcher's companion object") { 660 it("should produce a be-property-matcher that executes the passed function when its apply is called") { 661 val f = { (s: String) => BePropertyMatchResult(s.isEmpty, "empty") } 662 val empty = BePropertyMatcher(f) 663 "" should be (empty) 664 "x" should not be (empty) 665 "xx" should not be (empty) 666 "xxx" should not be (empty) 667 "xxxx" should not be (empty) 668 } 669 } 670} 671