[Rspec-devel] Mock the krufty bits, don't complicate the framework (was Re: use case for: setup_once, teardown_once)

Kent R. Spillner sl4mmy at zerosphere.org
Mon May 29 01:24:10 EDT 2006


Hi, "itsme213"-

itsme213 wrote:
> Sometimes the setup can be very expensive (e.g. establish a ssh or ftp 
> session) and the number of specs large.

Use mocks instead.

> In an empty home
>   - the security system should be enabled
>   When a door is opened
>     - the system should beep
>     - the display should highlight the door
>     When the password is entered on time
>       - the beeping should stop
>       - the system should be disabled
>       - the display should highlight the door
>     When the password is not entered on time
>       - the alarm should go off
>       - the monitoring company should be notified
> 
> How would you suggest this one be written in rspec?

Using mocks (mock home, mock open door...)

>  - the remote directory structure should satisfy ...
>  - remote file time stamps should be ...
>  - remote access controls should be ...
> 
> How would mocks help with this?

Refer to what David wrote:

>> This should never be done.  You never want your specifications
>> dependant on a) externsl, b) expensive, and c) nondeterministic/
>> uncontrollable resources.

So, mocks would help by eliminating dependecies on a) external, b)
expensive, and c) nondeterministic/uncontrollable resources.  That's
win-win-win, dude! :D

Best,
Kent


More information about the Rspec-devel mailing list