org.scalatest.NonImplicitAssertions.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalatest_2.11.0-M3 Show documentation
Show all versions of scalatest_2.11.0-M3 Show documentation
ScalaTest is a free, open-source testing toolkit for Scala and Java
programmers.
/*
* Copyright 2001-2011 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalatest
/**
* Trait that can be mixed into a Suite
to disable the lone implicit conversion provided by default in trait
* Assertions
, which trait Suite
extends.
*
*
* Currently there is just one implicit conversion provided by default in Suite
, the one that adds a ===
method to
* anything. If more default implicits are added to Suite
in future versions of ScalaTest, they will be added here as well so that
* this trait will disable all of them.
*
*
*
* This trait can be used to quickly solve a problem in which ScalaTest's default implicit conversion is clashing with those of some other library
* you need to use in your tests. After mixing in this trait, like this:
*
*
*
* class MySuite extends FunSuite with NonImplicitAssertions {
* // ...
* }
*
*
*
* You can write tests using assert
(without triple equals), expect
, and intercept
:
*
*
*
* assert(a < 7)
*
* expect(2) { 1 + 1 }
*
* intercept[IndexOutOfBoundsException] {
* "hi".charAt(-1)
* }
*
*
* @author Chua Chee Seng
* @author Bill Venners
*/
trait NonImplicitAssertions extends Assertions {
/**
* Overrides the super
implementation of convertToEqualizer
, turning off the implicit
* modifier (if present) to remove the method from the space of implicit conversions.
*
* @param left the object whose type to convert to Equalizer
.
* @throws NullPointerException if left
is null
.
*/
override def convertToEqualizer(right: Any): Equalizer = super.convertToEqualizer(right)
// override def convertToEqualizer(right: Any): Equalizer = new Equalizer(right)
}
/**
* Companion object that facilitates the importing of the members of trait Assertions
without importing the implicit conversions
* it provides by default. One use case for this object is to import the non-implicit Assertions
members so you can use
* them in the Scala interpreter along with another library whose implicits conflict with those provided by Assertions
:
*
*
* $ scala -cp scalatest-1.7.jar
* Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
* Type in expressions to have them evaluated.
* Type :help for more information.
*
* scala> import org.scalatest._
* import org.scalatest._
*
* scala> import NonImplicitAssertions._
* import NonImplicitAssertions._
*
* scala> assert(1 + 1 === 2)
* <console>:14: error: value === is not a member of Int
* assert(1 + 1 === 2)
* ^
*
* scala> assert(1 + 1 == 2)
*
* scala> expect(2) { 1 + 1 }
*
* scala> expect(2) { 1 + 1 + 1 }
* org.scalatest.TestFailedException: Expected 2, but got 3
* at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:318)
* at org.scalatest.NonImplicitAssertions$.newAssertionFailedException(NonImplicitAssertions.scala:73)
* ...
*
* scala> intercept[IndexOutOfBoundsException] { "hi".charAt(-1) }
* res3: IndexOutOfBoundsException = java.lang.StringIndexOutOfBoundsException: String index out of range: -1
*
*/
object NonImplicitAssertions extends NonImplicitAssertions