Always Execute - Change the way you test!
Always Execute extends RSpec or Shoulda by adding an execute block, which is the natural home for the actual code you are testing. Why would you ever need that? The answer is simple, the execute block provides a clear separation of concerns in your test structure making it easier to read and write.
All good tests have 3 separate and equally important steps:
- Setup the environment in a known state
- Execute the code you want to test
- Assert that your code changed the environment in the way you expected
Both RSpec and Shoulda by default provide blocks to encapsulate the setup and assert steps with the before
/ setup
and it
/ should
blocks, but there is no built-in block for the execute step. This leads to muddled blocks for your assertions that often contain bits of setup, execute, and assert code, making the test difficult to understand.
Checkout the examples:
Credits
Always Execute was developed by Michael Pearce in conjunction with Philippe Huibonhoa and is funded by Rafter.
Copyright
Copyright (c) 2011-2012 Michael Pearce, Rafter.com. See LICENSE.txt for further details.