Rails 3 rspec 2 rendering XML repsonse.should contain(<hash>.to_xml)

Hi all,

Is there an issue with Rails 3 or rspec 2 that the
repond_with({“success” => “test”) where the response is not an xml
text?

I have almost converted an old Rails 2 app to Rails 3 and having an
issue with the rspec tests and the response content for xml. It works
for json, but not xml.

Say I have something like this.

SimpleController < ActionController::Base

respond_to :html, :xml, :json

def test_action
@foo = { “success” => “test” }
respond_with(@foo) do |format|
format.html { render :text => “success”}
end
end
end

When I tested the xml rendering, I check the response contains
(have_text in rails 2) for the content. In the past (rails 2 and
rspec 1.x), I would test this as:
response.should have_text("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
\n\n test\n\n")

I converted the ‘have_text’ to ‘contain’ to read:
response.should contain("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
\n\n test\n\n")

This spec fails with on xml and not json:

 Failure/Error: response.should contain(success_text)
 expected the following element's content to include "<?xml

version=“1.0” encoding=“UTF-8”?>

xml

":
test

It looks like, the response is only “test” which is the value of the
hash.

On json the response is as expected: {“success”:“test”}.

Sorry for the lame example, but I really did not want to go into big
long explanation of the “real” test code. Basically, I test the
response and it should contain valid xml or json based on the format.
I even tried response.body and it fails. Is this a rspec issue? I
did a pp of the response and the body does look like the expected
result.

Has anyone come across this?

Thanks,

GregD

On Nov 29, 2:58pm, GregD [email protected] wrote:

Say I have something like this.
end
\n\n test\n\n")
The contain matcher comes from either webrat or capybara, and is
designed to specify content that is visible in a browser in an HTML
page (i.e. not tags).

I’d go with have_xpath instead, which is supported by both webrat and
capybara, though with slightly different APIs for each (check their
docs).

HTH,
David