Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better error handling on matcher change

  • Loading branch information...
commit cca84449f91e19bdcfafb46f32ad340249146858 1 parent adfb605
@rodrigomanhaes rodrigomanhaes authored
Showing with 11 additions and 4 deletions.
  1. +6 −0 should_dsl/doctests/change.txt
  2. +5 −4 should_dsl/matchers.py
View
6 should_dsl/doctests/change.txt
@@ -12,6 +12,12 @@
... self.items = []
>>> box = Box()
+
+>>> (box.add_items, 1) |should| change(box.items)
+Traceback (most recent call last):
+ ...
+TypeError: parameter passed to change must be a callable or a iterable having a callable as its first element
+
>>> (lambda: box.add_items(1)) |should| change(box.item_count)
>>> (lambda: box.add_items(1)) |should_not| change(box.item_count)
View
9 should_dsl/matchers.py
@@ -532,10 +532,11 @@ def to(self, to_value):
def _to_callable(self, objekt):
if callable(objekt):
return objekt
- type_error_message = 'parameter passed to change must be a callable or a iterable having a callable as its first element'
- if not getattr(objekt, '__getitem__', False) or not callable(objekt[0]):
- raise TypeError(type_error_message)
- return lambda *params: objekt[0](*objekt[1:])
+ if getattr(objekt, '__getitem__', False) and len(objekt) >= 2 and callable(objekt[0]):
+ return lambda *params: objekt[0](*objekt[1:])
+ else:
+ raise TypeError('parameter passed to change must be a callable ' +
+ 'or a iterable having a callable as its first element')
class _By(object):
def __init__(self, comparison, name=''):
Please sign in to comment.
Something went wrong with that request. Please try again.