Harry Bishop
2008-Oct-18 22:10 UTC
[rspec-users] Why @controller is nil error on loading fixtures in model?
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 -- Posted via http://www.ruby-forum.com/.
Zach Dennis
2008-Oct-19 01:32 UTC
[rspec-users] Why @controller is nil error on loading fixtures in model?
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 http://www.continuousthinking.com http://www.mutuallyhuman.com
Harry Bishop
2008-Oct-19 14:12 UTC
[rspec-users] Why @controller is nil error on loading fixtures in model?
Zach Dennis wrote:> On Sat, Oct 18, 2008 at 6:10 PM, Harry Bishop <lists at ruby-forum.com> > 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 Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.comyes that was the problem. That d*** dyslexia again. Thanks very much, as frustration had set in. HR -- Posted via http://www.ruby-forum.com/.