예제 #1
0
파일: spec.php 프로젝트: rstuven/pecs
            expect($expect->spec)->to_be($spec);
        });
        it('should pass if no assertion is expected', function () {
            $spec = new pecs\Spec(null, function ($s) {
                $s->expectAssertions()->to_be(0);
            });
            $spec->run($spec);
            expect($spec->passed())->to_be_true();
            expect($spec->failed())->to_be_false();
        });
        it('should pass if some assertions are expected', function () {
            $spec = new pecs\Spec(null, function ($s) {
                $s->expect(0)->to_be(0);
                $s->expect(true)->to_be(true);
                $s->expectAssertions()->to_be(2);
            });
            $spec->run($spec);
            expect($spec->passed())->to_be_true();
            expect($spec->failed())->to_be_false();
        });
        it('should fail if assertions expectation is not fulfilled', function () {
            $spec = new pecs\Spec(null, function ($s) {
                $s->expectAssertions()->to_be(1);
            });
            $spec->run($spec);
            expect($spec->passed())->to_be_false();
            expect($spec->failed())->to_be_true();
            expect($spec->failures)->to_have_count(1);
        });
    });
});
예제 #2
0
파일: spec.php 프로젝트: eugeneware/pecs
            $called = 0;
            $spec = new pecs\Spec(null, function () use(&$called) {
                $called += 1;
            });
            expect($called)->to_be(0);
            $spec->run();
            expect($called)->to_be(1);
            $spec->run();
            expect($called)->to_be(2);
        });
        it("should catch exceptions when invoking the function", function () {
            $exception = new Exception('failsauce');
            $spec = new pecs\Spec(null, function () use($exception) {
                throw $exception;
            });
            expect($spec->failures)->to_be_empty();
            expect(function () use($spec) {
                $spec->run();
            })->not_to_throw();
            expect($spec->failures)->to_have_count(1);
            expect($spec->failures[0])->to_be($exception);
        });
        it("should return a new expect object", function () {
            $spec = new pecs\Spec();
            $expect = $spec->expect('foo');
            expect($expect)->to_be_a('pecs\\Expect');
            expect($expect->actual)->to_be('foo');
            expect($expect->spec)->to_be($spec);
        });
    });
});