Example #1
0
"""
Specification for the ``describe`` function.

The rest of the specification is written as a pyUnit test case (in the
``tests``) directory, since nested ``describe``s are a bit confusing.

"""

from ivoire.standalone import ExampleGroup, describe
from ivoire.spec.util import ExampleWithPatch, mock
import ivoire

with describe(describe, Example=ExampleWithPatch) as it:

    @it.before
    def before(test):
        test.describes = mock.Mock(__name__="DescribedThing")
        test.it = describe(test.describes)

    with it("returns the described object's name as its str") as test:
        test.assertEqual(str(test.it), test.it.describes.__name__)

    with it("shows its name and examples as its repr") as test:
        test.assertEqual(
            repr(test.it),
            "<{0.__class__.__name__} examples={0.examples}>".format(test.it),
        )

    with it("sets the described object") as test:
        test.assertEqual(test.it.describes, test.describes)
Example #2
0
 def before(test):
     test.describes = mock.Mock(__name__="DescribedThing")
     test.it = describe(test.describes)
Example #3
0
 def before(test):
     test.describes = mock.Mock(__name__="DescribedThing")
     test.it = describe(test.describes)
Example #4
0
"""
Specification for the ``describe`` function.

The rest of the specification is written as a pyUnit test case (in the
``tests``) directory, since nested ``describe``s are a bit confusing.

"""

from ivoire.standalone import ExampleGroup, describe
from ivoire.spec.util import ExampleWithPatch, mock
import ivoire


with describe(describe, Example=ExampleWithPatch) as it:
    @it.before
    def before(test):
        test.describes = mock.Mock(__name__="DescribedThing")
        test.it = describe(test.describes)

    with it("returns the described object's name as its str") as test:
        test.assertEqual(str(test.it), test.it.describes.__name__)

    with it("shows its name and examples as its repr") as test:
        test.assertEqual(
            repr(test.it),
            "<{0.__class__.__name__} examples={0.examples}>".format(test.it),
        )

    with it("sets the described object") as test:
        test.assertEqual(test.it.describes, test.describes)
Example #5
0
 def setUp(self):
     self.result = self.patch("ivoire.current_result", shouldStop=False)
     self.describes = describe
     self.it = describe(self.describes)
Example #6
0
from ivoire.standalone import Example, describe
from ivoire.spec.util import ExampleWithPatch, mock


with describe(Example, Example=ExampleWithPatch) as it:
    @it.before
    def before(test):
        test.name = "the name of the Example"
        test.example_group = mock.Mock()
        test.example = Example(test.name, test.example_group)

    with it("shows its name as its str") as test:
        test.assertEqual(str(test.example), test.name)

    with it("shows its class and name in its repr") as test:
        test.assertEqual(
            repr(test.example),
            "<{0.__class__.__name__}: {0}>".format(test.example),
        )

    with it("knows its group") as test:
        test.assertEqual(test.example.group, test.example_group)

    with it("prevents group from being accidentally set") as test:
        with test.assertRaises(AttributeError):
            test.example.group = 12

    with it("has the same hash for the same name and group") as test:
        same = Example(test.name, test.example_group)
        test.assertEqual(hash(test.example), hash(same))
Example #7
0
 def setUp(self):
     self.result = self.patch("ivoire.current_result", shouldStop=False)
     self.describes = describe
     self.it = describe(self.describes)