Currently the way open_session
works requires you to change your test code to call everything on the passed in session in the block. I found this to be confusing and the documentation around how this work was a bit thin.
I ended up overriding open_session
in our project so that it allowed for a block that takes no arguments and calls it as an instance_eval’d block on the session. I’ve linked to a gist with the code below and how it works.
I think this helps improve the consistency of the test code inside and outside of open_session
blocks which was a sticking point for me while converting our old controller tests.
https://gist.github.com/chrisnicola/597725f548287f7e6f129567e8ab6f62
I’d be curious what people think of this approach. It also maintains the option of supplying an argument in the block and having it work the old way. This is similar to how the Sequel gem does blocks with virtual rows.