DEPRECATION WARNING: Passing a template handler in the template name is deprecated. (rspec + haml)

I upgraded a small project that I had created on 3.1.3 to 3.2.0.rc2.

Running rspec on it brings about a large amount of these messages:

DEPRECATION WARNING: Passing a template handler in the template name is deprecated. You can simply remove the handler name or pass render :handlers => [:haml] instead. (called from block (2 levels) in <top (required)> at /home/peterv/data/backed_up/projects/code/contact_app/spec/views/contacts/new.html.haml_spec.rb:12)

The offending code seems to be:

spec/views/contacts$ cat -n new.html.haml_spec.rb
1 require ‘spec_helper’
3 describe “contacts/new.html.haml” do
4 before(:each) do
5 assign(:contact, stub_model(Contact,
6 :email => “MyString”,
7 :person_id => 1
8 ).as_new_record)
9 end
11 it “renders new contact form” do
12 render ####### this render seems to trigger it
14 # Run the generator again with the --webrat flag if you want to use webrat matchers
15 assert_select “form”, :action => contacts_path, :method => “post” do
16 assert_select “input#contact_email”, :name => “contact[email]”
17 assert_select “input#contact_person_id”, :name => “contact[person_id]”
18 end
19 end
20 end

These are the view files (with .haml extensions)

app/views/contacts$ ls -l
total 20
-rw-rw-r-- 1 peterv peterv 100 2012-01-15 20:12 edit.html.haml
-rw-rw-r-- 1 peterv peterv 416 2012-01-15 20:12 _form.html.haml
-rw-rw-r-- 1 peterv peterv 404 2012-01-15 20:12 index.html.haml
-rw-rw-r-- 1 peterv peterv 66 2012-01-15 20:12 new.html.haml
-rw-rw-r-- 1 peterv peterv 171 2012-01-15 20:12 show.html.haml

app/views/contacts$ cat -n new.html.haml
1 %h1 New contact
3 = render ‘form’
5 = link_to ‘Back’, contacts_path

I just did a bundle update a few hours ago. I show the Gemfile and
Gemfile.lock below.

I presume this is associated with this commit

Is there a way I can fix this myself? I do not really understand what the problem
and the proposed solution is …



Does it go away if you change this to "contacts/new.html"?

--Matt Jones

Thanks for the accurate reply :slight_smile:

With the change you suggested, I still get a deprecation (but it already changed)

$ rspec spec/views/contacts/new.html.haml_spec.rb

DEPRECATION WARNING: Passing the format in the template name is deprecated. Please pass render with :formats => [:html] instead. (called from block (2 levels) in <top (required)> at /home/peterv/data/backed_up/customers/DDS/contact_app/spec/views/contacts/new.html.haml_spec.rb:12)

So, I went 1 step further, and moved to this:

-describe “contacts/new.html.haml” do

+describe “contacts/new” do

And now the result is OK:

contact_app$ rspec spec/views/contacts/new.html.haml_spec.rb


Finished in 0.18224 seconds

1 example, 0 failures

I assume it was clear that this is all “auto-generated” test code by rspec

initializer (that was 2.7 if I see correctly).

Now with rspec 2.8.x I added a new resource (foo), and I see that rspec

does it the correct way:

describe “foos/new” do

So, I presume this also shows the way towards the solution.

I now replaced all occurences of this {new|edit|index|show}.html.haml

into {new|edit|index|show} and all the deprecations are gone and all

tests remain green.

This is fixed in rspec 2.8 , I believe with this commit:

I presume other users that have autogenerated rspec scaffold

tests will be hit by this? Anything can be done there (I asked the question as

a comment on that patch on Github).

Thanks again,