Repository: cdent/gabbi

Issue:
If the test value for a response header is not treated by yaml as a string there is an error
```
File "/Users/cdent/src/enamel/.tox/functional/lib/python2.7/site-packages/gabbi/handlers.py", line 149, in action
        if header_value.startswith('/') and header_value.endswith('/'):
    AttributeError: 'float' object has no attribute 'startswith'
```

when:

```yaml
    - name: default version
      desc: no header sent
      GET: /
      request_headers:
        content-type: application/json
      response_headers:
        vary: /openstack-enamel-api-version/
        openstack-enamel-api-version: 0.1
```

Discussion:

Patch:
diff --git a/gabbi/handlers.py b/gabbi/handlers.py
index 33a4175..6de7f5b 100644
--- a/gabbi/handlers.py
+++ b/gabbi/handlers.py
@@ -128,6 +128,8 @@ class HeadersResponseHandler(ResponseHandler):
 
     If a header value is wrapped in ``/`` it is treated as a raw
     regular expression.
+
+    Headers values are always treated as strings.
     """
 
     test_key_suffix = 'headers'
@@ -137,10 +139,10 @@ class HeadersResponseHandler(ResponseHandler):
         header = header.lower()  # case-insensitive comparison
 
         response = test.response
-        header_value = test.replace_template(value)
+        header_value = test.replace_template(str(value))
 
         try:
-            response_value = response[header]
+            response_value = str(response[header])
         except KeyError:
             raise AssertionError(
                 "'%s' header not present in response: %s" % (
@@ -153,6 +155,6 @@ class HeadersResponseHandler(ResponseHandler):
                 'Expect header %s to match /%s/, got %s' %
                 (header, header_value, response_value))
         else:
-            test.assertEqual(header_value, response[header],
+            test.assertEqual(header_value, response_value,
                              'Expect header %s with value %s, got %s' %
                              (header, header_value, response[header]))


Test patch:
diff --git a/gabbi/tests/test_handlers.py b/gabbi/tests/test_handlers.py
index a92d53e..d5688b8 100644
--- a/gabbi/tests/test_handlers.py
+++ b/gabbi/tests/test_handlers.py
@@ -173,6 +173,17 @@ class HandlersTest(unittest.TestCase):
         self.assertIn("'location' header not present in response:",
                       str(failure.exception))
 
+    def test_resonse_headers_stringify(self):
+        handler = handlers.HeadersResponseHandler(self.test_class)
+        self.test.test_data = {'response_headers': {
+            'x-alpha-beta': 2.0,
+        }}
+        self.test.response = {'x-alpha-beta': '2.0'}
+        self._assert_handler(handler)
+
+        self.test.response = {'x-alpha-beta': 2.0}
+        self._assert_handler(handler)
+
     def _assert_handler(self, handler):
         # Instantiate our contained test class by naming its test
         # method and then run its tests to confirm.