[rspec-users] Spec rendering xml.erb suspectly doen't work

Peter Ehrenberg pe at dipe.de
Tue Nov 25 11:09:00 EST 2008

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|

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"

  $ spec spec
  'PostsController should render xml' FAILED
  expected: "XML",
       got: " " (using ==)

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?


More information about the rspec-users mailing list