Created
October 5, 2012 06:05
-
-
Save svs/3838340 to your computer and use it in GitHub Desktop.
authorised_index
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd recommend against code like this:
The problem is that the records are being created when the examples are being defined, which may happen long before the examples are actually run. Furthermore, the records are being created outside of the usual transaction management...which may leave your DB in an inconsistent state, and which may cause the records to no longer be there when the examples do run. Finally, the time it takes to create these records won't be reflected in the times rspec reports since it does it based on the time it takes each example to run.
Instead, you can pass a block to
it_behaves_like
and expose the records vialet
:Passing arguments to
it_behaves_like
works great for static values like strings, symbols and numbers, but not so great for database records that are in a global resource modified by many tests.