[203] r407@phpspec (orig r203): padraic.brady | 2008-01-16 10:34:03 -0700

1 view
Skip to first unread message

nor...@domain51.com

unread,
Jan 16, 2008, 12:35:15 PM1/16/08
to phpspec...@googlegroups.com
Revision
203
Author
phpspec
Date
2008-01-16 10:35:15 -0700 (Wed, 16 Jan 2008)

Log Message

 r407@phpspec (orig r203):  padraic.brady | 2008-01-16 10:34:03 -0700
 * Adding haveText Matcher for Context Zend
 * Needs work to operate on HTML output or conversion to simple str*

Modified Paths

Added Paths

Property Changed

Diff

Property changes:


Name: svk:merge
   - d6e91ea2-e33a-0410-98df-1d493bd67c58:/:202
   + d6e91ea2-e33a-0410-98df-1d493bd67c58:/:203

Modified: branches/zend/specs/ContextZendSpec.php (202 => 203)


--- branches/zend/specs/ContextZendSpec.php	2008-01-16 16:42:46 UTC (rev 202)
+++ branches/zend/specs/ContextZendSpec.php	2008-01-16 17:35:15 UTC (rev 203)
@@ -158,6 +158,15 @@
         $response->shouldNot->beSuccess();
     }
 
+    public function itShouldAttachHavetextMatcherToResponse() 
+    {
+        $context = new DescribeFooController;
+        $response = new PHPSpec_Context_Zend_Response;
+        $response->setContext($context);
+        $response->setBody('I Am Text');
+        $response->should->haveText('I Am Text');
+    }
+
     public function after()
     {
         PHPSpec_Context_Zend::clearModuleDirectories();

Added: branches/zend/src/PHPSpec/Context/Zend/Matcher/HaveText.php (0 => 203)


--- branches/zend/src/PHPSpec/Context/Zend/Matcher/HaveText.php	                        (rev 0)
+++ branches/zend/src/PHPSpec/Context/Zend/Matcher/HaveText.php	2008-01-16 17:35:15 UTC (rev 203)
@@ -0,0 +1,51 @@
+<?php
+/**
+ * PHPSpec
+ *
+ * LICENSE
+ *
+ * This file is subject to the GNU Lesser General Public License Version 3
+ * that is bundled with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://www.gnu.org/licenses/lgpl-3.0.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to lic...@phpspec.org so we can send you a copy immediately.
+ *
+ * @category   PHPSpec
+ * @package    PHPSpec
+ * @copyright  Copyright (c) 2007 Pádraic Brady, Travis Swicegood
+ * @license    http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ */
+
+/**
+ * @category   PHPSpec
+ * @package    PHPSpec
+ * @copyright  Copyright (c) 2007 Pádraic Brady, Travis Swicegood
+ * @license    http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ */
+class PHPSpec_Context_Zend_Matcher_HaveText extends PHPSpec_Matcher_Match
+{
+
+    public function __construct($expected)
+    {
+        // this is of course total bullshit for HTML but first things first
+        $this->_expected = "/" . str_replace('/', '\/', $expected) . "/";
+    }
+
+    public function getFailureMessage()
+    {
+        return 'expected match for /' . strval($this->_expected) . '/, but got no matching text (using haveText())';
+    }
+
+    public function getNegativeFailureMessage()
+    {
+        return 'expected no match for /' . strval($this->_expected) . '/, but got matching text (using haveText())';
+    }
+
+    public function getDescription()
+    {
+        return 'have text of ' . strval($this->_expected);
+    }
+
+}
\ No newline at end of file

Modified: branches/zend/src/PHPSpec/Specification.php (202 => 203)


--- branches/zend/src/PHPSpec/Specification.php	2008-01-16 16:42:46 UTC (rev 202)
+++ branches/zend/src/PHPSpec/Specification.php	2008-01-16 17:35:15 UTC (rev 203)
@@ -124,7 +124,7 @@
         $matchers = array(
             'equal', 'be', 'beEqualTo', 'beAnInstanceOf', 'beGreaterThan', 'beTrue', 'beFalse', 'beEmpty', 'beLessThan', 'beGreaterThanOrEqualTo', 'beLessThanOrEqualTo', 'beSet', 'beNull', 'beOfType', 'beIdenticalTo', 'match', 'throw',
 
-            'beSuccess'
+            'beSuccess', 'haveText'
         );
         if (in_array($method, $matchers)) {
             $this->setExpectedValue(array_shift($args));
Reply all
Reply to author
Forward
0 new messages