Ich habe gerade begonnen, Factory Girl zu verwenden, um Fixtures zu ersetzen, wenn ich teste. Ich arbeite an einem Twitter-Client und ich versuche Factory Girl zu verwenden, um die Twitter-Objekte zum Testen zu erstellen. Wenn ich sie individuell erstelle, ist das in Ordnung. Aber wenn ich versuche, sie zu verbinden, erhalte ich den Fehler unten.Problem mit nicht activerecord Assoziationen in Fabrik Mädchen
Factory.define :status, :class => Twitter::Status, :default_strategy => :build do |t|
t.text 'Test Twitter Status message'
t.association :user, :factory => :twitter_user #this line causes the problems
end
Factory.define :twitter_user, :class => Twitter::User, :default_strategy => :stub do |u|
u.profile_image_url "#{RAILS_ROOT}/public/images/rails.png"
end
Die t.association :user, :factory => :twitter_user
bewirkt, dass die Probleme, weil, wenn es da ist diese Ausnahme ausgelöst. Gibt es trotzdem etwas zu beheben? Oder ist Factory Girl nur für Active-Record-Objekte gedacht? Dank
NoMethodError: undefined method `save!' for #<Twitter::User:0x4af3de46>
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.0/lib/factory_girl/proxy/create.rb:5:in `result'
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.0/lib/factory_girl/factory.rb:293:in `run'
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.0/lib/factory_girl/factory.rb:237:in `create'
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.0/lib/factory_girl/proxy/build.rb:17:in `associate'
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.0/lib/factory_girl/attribute/association.rb:13:in `add_to'
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.0/lib/factory_girl/factory.rb:290:in `run'
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.0/lib/factory_girl/factory.rb:288:in `each'
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.0/lib/factory_girl/factory.rb:288:in `run'
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/thoughtbot-factory_girl-1.2.0/lib/factory_girl/factory.rb:217:in `build'
test/functional/tweet_feeds_controller_test.rb:12:in `test_Display_friends_timeline_for_the_'amber'_user'
/usr/local/share/jruby-1.1.6/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:94:in `run_with_callbacks_and_mocha'