Forum: RSpec RSpec-Rails bug with to_xml?

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.
439c401f95ee2fac0be4c1727dd74dea?d=identicon&s=25 Bira (Guest)
on 2008-10-20 13:31
(Received via mailing list)
Hello, everyone. I've been lurking here for a while, but this is my
first post.

I think I've run into a RSpec bug in a Rails project I'm working on. I
was working on a few REST controllers, and started getting failures on
a specific spec that verified whether a certain action returned XML
output. I spent quite a lot of time checking my code to see if it was
something I did wrong, but it works when I test it manually.

So I created an empty Rails app, and wrote the bare minimum of code
necessary to reproduce this problem. I'm using Rails 2.1.1, with
rspec-1.1.8 and rspec-rails-1.1.8, all installed as gems.

I started by creating a dead-simple model with two string attributes
and no validations, along with this fixture:

# spec/fixtures/users.yml
one:
  name: Name
  email: email

Then I created a simple controller, and its corresponding spec.

class UsersController < ApplicationController

  def index
    respond_to do |format|
      format.xml { render :xml => User.find(:all).to_xml}
    end
  end

end

# spec

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe UsersController do

  fixtures :users

  it "should return a XML user list" do
    get :index, :format => :xml
    response.body.should == User.find(:all).to_xml
  end


end

It all looks straightforward enough - I use the same call on both the
controller and the spec, so the two results should indeed be the same.
However, when I run the spec I get this failure:

1)
'UsersController should return a XML user list' FAILED
expected: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<users
type=\"array\">\n  <user>\n    <created-at
type=\"datetime\">2008-10-20T11:24:28Z</created-at>\n
<email>email</email>\n    <id type=\"integer\">953125641</id>\n
<name>Name</name>\n    <updated-at
type=\"datetime\">2008-10-20T11:24:28Z</updated-at>\n
</user>\n</users>\n",
     got: " " (using ==)
./spec/controllers/users_controller_spec.rb:10:
/usr/lib64/ruby/1.8/timeout.rb:53:in `timeout'

Finished in 0.256981 seconds


This happens both when using "rake spec" and when running only that
spec file. Firing up the app and accessing localhost:3000/users.xml
returns the correct result. In the "real" project, it's even weirder:
the "expected" site of the assertion shows a string composed of the
XML out put concatenated to itself, and the "got" side has the correct
output. Something like "Expected 'aa' but got 'a'".

What could the problem be? Is it really a RSpec bug, or is it
something I did wrong?


--
Bira
http://compexplicita.wordpress.com
http://compexplicita.tumblr.com
F86901feca747abbb5c6c020362ef2e7?d=identicon&s=25 Zach Dennis (zdennis)
on 2008-10-20 15:20
(Received via mailing list)
On Mon, Oct 20, 2008 at 7:30 AM, Bira <u.alberton@gmail.com> wrote:
> rspec-1.1.8 and rspec-rails-1.1.8, all installed as gems.
>
> # spec
>  end
> expected: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<users
> Finished in 0.256981 seconds
> something I did wrong?
Look up  "integrate_views" on the rspec-rails docs:
   http://rspec.rubyforge.org/rspec-rails/1.1.8/

Also there is a section called "Integration Model". Read that. If you
have any further questions don't hesitate to ask. HTH,


--
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (Guest)
on 2008-10-20 17:23
(Received via mailing list)
On 2008-10-20, at 09:19, Zach Dennis wrote:
> Look up  "integrate_views" on the rspec-rails docs:
>   http://rspec.rubyforge.org/rspec-rails/1.1.8/
>
> Also there is a section called "Integration Model". Read that. If you
> have any further questions don't hesitate to ask. HTH,

Hi Zach. I searched for "integration" on that page, searched Google,
and did a Google site-search on rspec.info and rspec.rubyforge.org for
"integration model", but no relevant hits came up. When you have a
minute, would you mind sending a link our way, please?

Thanks,
Nick
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-10-20 17:24
(Received via mailing list)
On Mon, Oct 20, 2008 at 10:21 AM, Nick Hoffman <nick@deadorange.com>
wrote:
> model", but no relevant hits came up. When you have a minute, would you mind
> sending a link our way, please?

It's Integration Mode, not Model :)

http://rspec.rubyforge.org/rspec-rails/1.1.8/class...

Cheers,
David
F86901feca747abbb5c6c020362ef2e7?d=identicon&s=25 Zach Dennis (zdennis)
on 2008-10-20 17:25
(Received via mailing list)
On Mon, Oct 20, 2008 at 11:24 AM, David Chelimsky <dchelimsky@gmail.com>
wrote:
>> a Google site-search on rspec.info and rspec.rubyforge.org for "integration
>> model", but no relevant hits came up. When you have a minute, would you mind
>> sending a link our way, please?
>
> It's Integration Mode, not Model :)

Sorry about that Nick, typo on my end!

>
> 
http://rspec.rubyforge.org/rspec-rails/1.1.8/class...
>
> Cheers,
> David
>


--
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (Guest)
on 2008-10-20 17:28
(Received via mailing list)
On 2008-10-20, at 11:24, David Chelimsky wrote:
> It's Integration Mode, not Model :)
>
> 
http://rspec.rubyforge.org/rspec-rails/1.1.8/class...

Ah! Thanks for the clarification, David.

No worries about the typo, Zach. My fingers often have a mind of their
own, too.
-Nick
This topic is locked and can not be replied to.