Testing content blocks in views with Rspec 1.1.12
I upgraded my Rspec to the 1.1.12 version and it started to give some warning messages when testing my views:
(name) as an alias for capture(name) (TestResponse extension in rspec-rails) is deprecated and will be removed in the rspec-rails release that follows the rails-2.3.0 release.
Researching for that took me to this Rspec commit which explains what was done. Still I wasn’t able to know exactly what was wrong. Using grep to search for ‘response’ at my view specs gave some clue. The problem is that because of some new stuff in Rails Edge (2.3 soon) there will be some incompatibilities with rspec-rails, which forced David Chelimsky to deprecate code like the following:
response[:left_column].should_not have_tag("a", "Delete")
where :left_column indicates some content block that we added to our views doing something like
<% content_for :left_column do %> ... <% end %>
For now we can still test like shown above, but it is deprecated and when we run our specs we’ll see a lot of ugly warning messages. the solution is to use the capture method, which was already there in older versions of Rspec, being the [ ] just an alias for it.
response.capture(:left_column).should_not have_tag("a", "Delete")