def test_with_args_validator(self): subject = InstanceDouble('doubles.testing.User') expect(subject).method_with_varargs.with_args_validator( lambda *args: args[0] == 'Bob Barker' ) subject.method_with_varargs('Bob Barker', 'Drew Carey')
def test_raises_if_method_is_called_with_wrong_arguments(self): subject = InstanceDouble('doubles.testing.User') allow(subject).method_with_varargs.with_args('bar') with raises(UnallowedMethodCallError) as e: subject.method_with_varargs('baz') assert re.match( r"Received unexpected call to 'method_with_varargs' on " r"<InstanceDouble of <class '?doubles.testing.User'?" r"(?: at 0x[0-9a-f]{9})?> object at .+>\." r" The supplied arguments \('baz'\)" r" do not match any available allowances.", str(e.value))
def test_matches_most_specific_allowance(self): subject = InstanceDouble('doubles.testing.User') allow(subject).method_with_varargs.and_return('bar') allow(subject).method_with_varargs.with_args('baz').and_return('blah') assert subject.method_with_varargs('baz') == 'blah'
def test_returns_result_of_a_callable_with_positional_vargs(self, stubber): subject = InstanceDouble('doubles.testing.User') stubber(subject).method_with_varargs.and_return_result_of(lambda *x: x) result = subject.method_with_varargs('bob', 'barker') assert result == ('bob', 'barker')
def test_raises_if_method_is_called_with_wrong_arguments(self): subject = InstanceDouble('doubles.testing.User') allow(subject).method_with_varargs.with_args('bar') with raises(UnallowedMethodCallError) as e: subject.method_with_varargs('baz') assert re.match( r"Received unexpected call to 'method_with_varargs' on " r"<InstanceDouble of <class '?doubles.testing.User'?" r"(?: at 0x[0-9a-f]{9})?> object at .+>\." r" The supplied arguments \('baz'\)" r" do not match any available allowances.", str(e.value) )