-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
33 lines (24 loc) · 2.99 KB
/
README
File metadata and controls
33 lines (24 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Sock: when the spec generates the mock
HERE BE DRAGONS.
This is an initial experiment. Think about it. Talk about it. But if you use it
in anger, expect it to make you angry.
HERE BE DRAGONS.
Consider the following test, for a calculator class:
it "returns 6 for inputs 3 and 2" do
calculator = Calculator.new
calculator.push(2)
calculator.push(3)
calculator.mul.should == 6
end
And this one, for something that uses the calculator class:
it "uses the calculator to multiply 3 and 2" do
calculator.should_receive(:push).with(2)
calculator.should_receive(:push).with(3)
calculator.should_receive(:mul).and_return(6)
CalculatorDriver.run(calculator)
end
But in the real world, eventually the calculator class will change and all its
consumers will break in real code, but the consumer's tests will keep right on
passing. Bad. If only the mock for the latter test could be generated by the
former...
Oh look. It can.