[rspec-users] Render template not matching absolute path

David Chelimsky dchelimsky at gmail.com
Tue Aug 21 09:26:39 EDT 2007


On 8/21/07, Ashley Moran <work at ashleymoran.me.uk> wrote:
> Hi
>
> I have a simple controller method like this:
>
> class StylesheetsController < ApplicationController
>    layout  nil
>    session :off
>
>    def gap
>      site = Site.find_by_hostname(request.host)
>      @colours = site.colours
>      respond_to do |accepts|
>        accepts.css { render :file => "#{RAILS_ROOT}/app/views/
> stylesheets/gap.rcss" }
>      end
>    end
> end
>
> And I want to test that it renders the gap.rcss file, but my spec,
>
>      it "should render the gap.rcss template" do
>        do_get
>        response.should render_template("gap.rcss")
>      end
>
> fails with this error:
>
> Expected "gap.rcss", got "/Users/ashleymoran/Documents/Development/
> YourMoney/trunk/src/config/../app/views/stylesheets/gap.rcss"
>
> I don't remember this failing in 1.0.5, but it's been a while since I
> worked on this project so might be just be my bad memory.  Am I doing
> something wrong or can you not spec "render :file" with render_template?

This changed in 1.0.0, but not since.

Take a look at render_template.rb. render_template supports either a
file name, in which case it prepends the controller-based path (i.e.
if the controller is 'foo' and you say 'bar', it will match
'foo/bar'), or a path. In either case it matches against
response.rendered_file - it does not do any real path resolution -
it's just matching strings.

HTH,
David



>
> Thanks
> Ashley
>
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list