Forum: RSpec Why @controller is nil error on loading fixtures in model?

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.
Harry B. (Guest)
on 2008-10-19 02:10
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.
TIA,
HR
Zach D. (Guest)
on 2008-10-19 07:41
(Received via mailing list)
On Sat, Oct 18, 2008 at 6:10 PM, Harry B. <removed_email_address@domain.invalid>
wrote:
> '/../helpers/votes_spec_helper')
>
> 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 D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com
Harry B. (Guest)
on 2008-10-19 18:12
Zach D. wrote:
> On Sat, Oct 18, 2008 at 6:10 PM, Harry B. <removed_email_address@domain.invalid>
> wrote:
>> '/../helpers/votes_spec_helper')
>>
>> 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 D.
> http://www.continuousthinking.com
> http://www.mutuallyhuman.com

yes that was the problem.  That d*** dyslexia again.
Thanks very much, as frustration had set in.
HR
This topic is locked and can not be replied to.