Skip to content
janeiro 14, 2009 / cassiomarques

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")

2 Comentários

Deixe um comentário
  1. Sascha Konietzke / mar 27 2009 4:43 pm

    I was looking for a solution to that problem for a long time! Thanks!

  2. Jeff Dallien / abr 22 2009 11:55 pm

    This post also proved helpful for me, thanks.

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do

Você está comentando utilizando sua conta Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s

%d blogueiros gostam disto: