render_template bug with rspec 1.1.12

4 views
Skip to first unread message

joakim...@gmail.com

unread,
Mar 4, 2009, 8:30:49 AM3/4/09
to resource_controller
Hi,

I just upgraded to rspec 1.1.12 and started to get this error in my
controller specs when 'render :action' is used.

NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/
text_helper.rb:42:in `concat'
...

This happens both when I customize the new and update controller
method with wants.html and when it's just the standard generated
controller method for new and update.

My controller specs look like this:

describe "handling PUT /db_instances/1" do

before(:each) do
@db_instance = mock_model(DbInstance, :to_param => "1")
DbInstance.stub!(:find).and_return(@db_instance)
end

describe "with successful update" do

def do_put
@db_instance.should_receive(:update_attributes).and_return
(true)
put :update, :id => "1"
end

it "should find the db_instance requested" do
DbInstance.should_receive(:find).with("1").and_return
(@db_instance)
do_put
end

it "should update the found db_instance" do
do_put
assigns(:db_instance).should equal(@db_instance)
end

it "should assign the found db_instance for the view" do
do_put
assigns(:db_instance).should equal(@db_instance)
end

it "should redirect to the db_instance" do
do_put
response.should redirect_to(db_instance_url("1"))
end

end

describe "with failed update" do

def do_put
@db_instance.should_receive(:update_attributes).and_return
(false)
put :update, :id => "1"
end

it "should re-render 'edit'" do
do_put
response.should render_template('edit')
end

end
end

Is this a known bug or am I doing something wrong in my spec or
controller?

/Joakim

joakim...@gmail.com

unread,
Mar 5, 2009, 1:05:50 PM3/5/09
to resource_controller
More information about this problem is available at runcoderun:

http://runcoderun.com/jbripley/brazil/builds/eeb52426f2c6f16a5758b024e247e608ff4c088b/1/ruby18

/Joakim

Moises

unread,
Mar 10, 2009, 12:59:56 PM3/10/09
to resource_controller
Hi,

I'm having the same problem with my rspec tests. The controller test
pass when using the controller made by the rails scaffold generator.
It also works when removing the layout used by the controller (none
valid solutions but might give a hint of where the problem is
ocurring).

Moises

Moises

unread,
Mar 17, 2009, 5:36:41 PM3/17/09
to resource_controller
Fixed. I just updated to rspec 1.2.0 and now every test passes.
Reply all
Reply to author
Forward
0 new messages