What’s new in pyDoubles 1.3?

  1. times statement is also available in spies, not only mocks
  2. stubs ignoring arguments can live together with stubs defined with arguments
  3. a new matcher: obj_with_fields

1: This sintax is now possible:

assert_that_method(spy_obj.some_method).was_called().times(2)
or
assert_that_method(spy_obj.some_method).was_called(
     ).with_args(SOME_VALUE).times(2)

2: The most precise matching condition will be used:

when(spy_obj.some_method).then_return(SOME_VALUE)
when(spy_obj.some_method).with_args(10
    ).then_return(OTHER_VALUE)

The two lines above inside a test would mean the objet will return OTHER_VALUE when the input parameter will be 10 and SOME_VALUE in any other case. In previous releases, it would return SOME_VALUE always because stubs ignoring arguments use to override any other stub definition.

3: obj_with_fields matcher:

assert_that_method(spy_obj.some_method).was_called(
    ).with_args(obj_with_fields({'id': 20, 'name': 'Carlos'}))

Which means the object passed in as a parameter, should have fields id and name with those values.