From: Thiago Arrais Date: 2006-03-21T21:50:47+09:00 Subject: Re: Library for Mocking On 3/20/06, Jim Weirich wrote: > Actually, you still need to specify the behavior of the mock. The "use" > module method just ensures that that mock_verify is properly called at > the end of the test. Hmm... I knew I was wrong at some point. I think I got fooled by the docs at http://onestepback.org/software/flexmock/ Somewhere in the simple example, you can read FlexMock.use("temp") do |sensor| sensor = FlexMock.new sensor.should_receive(:read_temperature).and_return { readings.shift } sampler = TemperatureSampler.new(sensor) assert_equal 12, sampler.average_temp Because of indentation it seems that the "should_receive" methods (i.e. the setup phase) go inside the block that gets passed to the use method and the stimuling calls go outside. In that sense, after the use method returns, the mock is ready for usage. But now I can see they are really at the same level and the setup phase really precedes the usage phase as multiple calls and not one method call. I don't know if I made myself clear, but that was pretty much my previous understanding. > (1) how are arguments to the mock method validated? (exact match, > constraints, no validation?) Well, you pretty much answered this one yourself on you next post :-) > (2) is the order of the messages important? At least in my original example it is. However, I see that we may often need to specify that order is not important, specially when we use the repetition modifiers (like once and twice). I definitely need some experimenting in order to clear my mind on this topic. How does JMock handles that? > If there is sufficient interest in a recording interface to MockFlex, I > am willing to consider it for inclusion in the library. You can find at least one person. Anyway, I know I am patching my MockFlex (or is it called FlexMock?). Cheers, Thiago Arrais