[rspec-users] Why @controller is nil error on loading fixtures in model?

Zach Dennis zach.dennis at gmail.com
Sat Oct 18 21:32:15 EDT 2008

On Sat, Oct 18, 2008 at 6:10 PM, Harry Bishop <lists at ruby-forum.com> wrote:
> Hi,
>  I'm new to rspec and working on catching up my app with rspec testing.
> I'm running OSX 10.5.5 with Rails 2.1.0 and Rspec 1.1.8.
> Most things I've tried work except loading fixtures.  I setup a describe
> block for the model as
> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
> require File.expand_path(File.dirname(__FILE__) +
> '/../helpers/motions_spec_helper')
> require File.expand_path(File.dirname(__FILE__) +
> '/../helpers/votes_spec_helper')
> describe "description" do
>    fixtures :motions
>  it "reads from fixtures" do
>    put "#{motions(:one).inspect}"
>  end
> end
> I receive @controller is nil: make sure you set it in your test's setup
> method.
> as the error when running the example test in rspec.  I know it is
> finding the fixture because it balked at duplicate id entries with
> SQLite.  I fixed that and now receive the above message.
> I tried various setting changes in spec_helper.rb but nothing seems to
> work.
> After searching around I tried various terminal entries like
> rake spec:db:fixtures:load
> but no change.
> I would appreciate some assistance here to get this off the ground.

It's being you are calling "put" and I believe you want "puts". The
method "put" is a Rails testing method which tries to invoke a PUT
http request on a given controller action. That is why you are getting
@controller is nil.

Zach Dennis

More information about the rspec-users mailing list