[rspec-users] render_template expectation - surprising pattern matching issue

Timo Rößner dark.red.and.yellow at googlemail.com
Mon Jul 26 12:12:59 EDT 2010

Hey guys,

we just found out by accident that rspec seems to apply a pretty
confusing mechanism to ensure that a certain template is rendered.

To clarify, consider this standard controller spec:

  # working
  it 'GET edit' do
    get :edit, :id => '37'
    response.should render_template(:edit)

So far, so good. Now to the surprising part:

  # NOT working
  it 'GET edit' do
    get :edit, :id => '37'
    response.should render_template(:eda)

  # -> here's the surprise:  working
  it 'GET edit' do
    get :edit, :id => '37'
    response.should render_template(:edi)

Apparently rspec uses a pretty generous pattern matching to ensure
that a certain template is rendered.

If I had to guess, I'd say that's because rspec wants to ignore path /
namespacing / different file endings (html.haml, html.erb and so on).

I still think this approach is suboptimal for two reasons:

1.) It violates the principle of least suprise, this behaviour is more
like "the biggest surprise possible" - who would have thought that
example nr.3 is working?

2.) I can easily imagine a situation where 2 or more actions start
with the same letters. In this case, what would happen if you changed
the "render_template"-call (i.e. shortening the template name) and
remove one action.
Wouldnt the specs still be green although one view would be completely

2 questions:

1.) Is this a bug or a feature?

2.) Why not change the pattern matching that it still ignores paths
and file endings, but at least tries to match the expected template
exactly to the rendered template?

More information about the rspec-users mailing list