Forum: RSpec Spec rendering xml.erb suspectly doen't work

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C4228db54c76deba18a92bf7560ea493?d=identicon&s=25 Peter Ehrenberg (Guest)
on 2008-11-25 17:09
(Received via mailing list)
I have to spec an contoller action witch is (only) rendering an
xml.erb template.
The action looks like this:

  def index
    respond_to do |format|
      format.xml
    end
  end

The "index.xml.erb" template includes (for now) only the string "XML".

This works fine if I requests the action with curl -H "ACCEPT: text/xml"
...
It also running fine, if I write a conventional rails functional test.

But specing this, it render nothing but a single blank.

  describe PostsController do
    it "should render xml" do
      request.env["HTTP_ACCEPT"] = "application/xml"
      get :index
      response.body.should == "XML"
    end
  end

  $ spec spec
  1)
  'PostsController should render xml' FAILED
  expected: "XML",
       got: " " (using ==)
  /home/petehr/Project/test/spec/controllers/posts_controller_spec.rb:7:

I've done some puts-debugging like this

  format.xml { puts ">>>#{render_to_string}<<<" }

in the actions respond_to block. Running the curl command or the
functional
test shows the expected result ">>>XML<<<". But runing the spec again
shows only a blank: '>>> <<<'.

Any hints?

/Peter
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2008-11-25 17:23
(Received via mailing list)
"Peter Ehrenberg" <pe@dipe.de> writes:

> The "index.xml.erb" template includes (for now) only the string "XML".
>       response.body.should == "XML"
> I've done some puts-debugging like this
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

By default, controller specs don't actually render the views.  You need
to call integrate_views from within your example group to make them
render.

Pat
C4228db54c76deba18a92bf7560ea493?d=identicon&s=25 Peter Ehrenberg (Guest)
on 2008-11-25 17:50
(Received via mailing list)
> By default, controller specs don't actually render the views.

Ah. Ok thanks.

/Peter
This topic is locked and can not be replied to.