Joshua Muheim
2007-Apr-26 10:31 UTC
Tests: Can''t use items(:fixture_name) in setup method!
Hi all I don''t know what happened, but since some time I can''t run my tests anymore because I''m getting the following error: chraftbuech:~/Webwork/pgbookings josh$ ruby test/functional/admin/music_labels_ controller_test.rb Loaded suite test/functional/admin/music_labels_controller_test Started EEEEEEEE Finished in 0.156566 seconds. 1) Error: test_create(Admin::MusicLabelsControllerTest): 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.[] /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:498:in `music_labels'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.rb:496:in `music_labels'' test/functional/admin/music_labels_controller_test.rb:17:in `setup'' .....etc.... My setup method looks like that: def setup @controller = Admin::MusicLabelsController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @bionics_records_id = music_labels(:bionics_records).id end I tracked the error down to the following line (line 17): @bionics_records_id = music_labels(:bionics_records).id It seems that music_labels() does not return the corresponding object anymore! But in my fixtures everything seems ok: music_labels.yml: bionics_records: id: 1 name: Bionics Records origin_country_id: 4 index_records: id: 2 name: Index Records origin_country_id: 1 Can anyone give me a hint what''s the problem? When replacing @bionics_records_id = music_labels(:bionics_records).id with @bionics_records_id = 1 everything works again... Thanks a lot Josh -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Did you remember to call "fixtures :music_labels" ? On Apr 26, 11:31 am, Joshua Muheim <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all > > I don''t know what happened, but since some time I can''t run my tests > anymore because I''m getting the following error: > > chraftbuech:~/Webwork/pgbookings josh$ ruby > test/functional/admin/music_labels_ > controller_test.rb > Loaded suite test/functional/admin/music_labels_controller_test > Started > EEEEEEEE > Finished in 0.156566 seconds. > > 1) Error: > test_create(Admin::MusicLabelsControllerTest): > 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.[] > /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures. rb:498:in > `music_labels'' > /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures. rb:496:in > `music_labels'' > test/functional/admin/music_labels_controller_test.rb:17:in `setup'' > .....etc.... > > My setup method looks like that: > > def setup > @controller = Admin::MusicLabelsController.new > @request = ActionController::TestRequest.new > @response = ActionController::TestResponse.new > > @bionics_records_id = music_labels(:bionics_records).id > end > > I tracked the error down to the following line (line 17): > > @bionics_records_id = music_labels(:bionics_records).id > > It seems that music_labels() does not return the corresponding object > anymore! But in my fixtures everything seems ok: > > music_labels.yml: > bionics_records: > id: 1 > name: Bionics Records > origin_country_id: 4 > index_records: > id: 2 > name: Index Records > origin_country_id: 1 > > Can anyone give me a hint what''s the problem? When replacing > > @bionics_records_id = music_labels(:bionics_records).id > > with > > @bionics_records_id = 1 > > everything works again... > > Thanks a lot > Josh > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joshua Muheim
2007-Apr-26 11:29 UTC
Re: Tests: Can''t use items(:fixture_name) in setup method!
Jon wrote:> Did you remember to call "fixtures :music_labels" ? > > > On Apr 26, 11:31 am, Joshua Muheim <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Yes, that''s not the problem. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---