Friday, May 13, 2011

RSpec 2 matcher to test layout rendering in Rails 3

In Rails 3 there seems to be no way to determine which layout(s) were rendered. There is assert_template but it doesn't seem to accept the :layout option like the source code would suggest. And where do you call that method anyway? So I wrote a custom matcher along with a bit that integrates into ActionView so that we can detect when a layout is rendered and store a reference to it on the controller.

Not that this doesn't support multiple layout rendering. Only the last layout rendered is stored.

Take a look at the Example Usage in the comments above the matcher for usage information.

No comments: