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<hash>\n <success>test</success>\n</hash>\n")
I converted the 'have_text' to 'contain' to read: response.should contain("<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n<hash>\n <success>test</success>\n</hash>\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"?> <hash> <success>xml</success> </hash> ": 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