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
On Mon, Oct 20, 2008 at 7:30 AM, Bira <u.alberton at gmail.com> wrote:> 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?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
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
On Mon, Oct 20, 2008 at 10:21 AM, Nick Hoffman <nick at deadorange.com> wrote:> 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?It''s Integration Mode, not Model :) http://rspec.rubyforge.org/rspec-rails/1.1.8/classes/Spec/Rails/Example/ControllerExampleGroup.html Cheers, David> > Thanks, > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Mon, Oct 20, 2008 at 11:24 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Mon, Oct 20, 2008 at 10:21 AM, Nick Hoffman <nick at deadorange.com> wrote: >> 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? > > It''s Integration Mode, not Model :)Sorry about that Nick, typo on my end!> > http://rspec.rubyforge.org/rspec-rails/1.1.8/classes/Spec/Rails/Example/ControllerExampleGroup.html > > Cheers, > David >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
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/classes/Spec/Rails/Example/ControllerExampleGroup.htmlAh! Thanks for the clarification, David. No worries about the typo, Zach. My fingers often have a mind of their own, too. -Nick