It seems that later versions of Midje provide this functionality pretty well.
-, , (, , Stuart Sierra ). , , , , , stand-in, :
Mockito , , .
, , Midje , ... :
(defrecord-openly SideEffectThing [connection]
ISideEffect
(persist [this thing] :unfinished)
(read [this] :unfinished)
)
. Midje , , , .
defrecord-openly, "" Midje:
(fact "you can test in terms of a record methods"
(let [obj (->SideEffectThing :fake-connection)]
(user-of-side-effect-thing obj) => 0
(provided
(read obj) => -1)
)
)
, ( ), defrecord- . SideEffectThing ( ) . , .
, Java Mockito . Java:
interface ISideEffect { int read(); void write(Object something); }
class SideEffectThing implements ISideEffect { ... }
public class SomeOtherComponentSpec {
private ISideEffect obj;
@Before
public void setup() { obj = mock(ISideEffect.class); }
@Test
public void does_something_useful() {
when(obj.read()).thenReturn(-1);
OtherComponent comp = new OtherComponent(obj);
int actual = comp.doSomethingUseful();
assertEquals(0, actual);
verify(obj).read();
}
Java , , , , read() - . Mockito ( ), , , .
Midje . ( ), , , . , ( ), . , , 3 :
(fact "you can test in terms of a record methods"
(let [obj (->SideEffectThing :fake-connection)]
(user-of-side-effect-thing obj) => 0
(provided
(read obj) => -1
(read obj) => 6
(read obj) => 99
)
)
)
, , . . , , .