1

我正在使用带有 ruby​​ 1.9.2 的 rails 3.0.9。我正在做一个允许用户将物品放入不同壁橱的系统。用户的一种可能性是将其他用户的物品复制到他自己的壁橱中(如果您不明白,请告诉我,我不擅长解释事情..)。

为了处理图像,我使用的是回形针 2.3.16。我正在使用 Rspec-rails 2.6.1、Cucumber-rails 1.0.2 测试我的应用程序。当我在资产的副本部分使用 guard & spork 运行测试时,我遇到了“TypeError:无法复制 NilClass”。我在网上搜索了答案,但没有找到任何具体且有效的内容:(。

你对这个问题有什么想法吗?

我的 closet_spec.rb 代码(如果您需要其他内容,请告诉我):

  describe '#tidy_up' do
let!(:other_user) { Factory.create(:confirmed_user, :user_name => 'Plop', :email => 'coin@plop.fr') }
let!(:closet) { other_user.closets.first }
let!(:item) { Item.create! :type_id => 42, :closet_id => dream_dressing.id }
let!(:dressing_item) { Item.create! :type_id => 42, :closet_id => dressing.id }

before do
  path = File.join(Rails.root, "spec", "support", 'image.jpg')
  f = File.open(path)
  2.times.map do |n| 
    i = Item.new :type_id => 2#, :asset => Asset.new(picture)
    i.save!
    puts ">>>>>>>>>>>>>>>>>>>>> #{i.id}"
    i.build_asset(:picture => f)
    closet.items << i
  end
  @count = 0
end

it 'copies given items and assets to closet' do
  expect { dream_dressing.tidy_up closet.items }.to change { dream_dressing.items.count }.by 2
  expect { dream_dressing.tidy_up closet.items }.to change { dream_dressing.items.map{|i| i.asset; puts ">>>>>>>>>>>>>>>>> asset : #{i.asset} " }.length }.by 2
end
4

0 回答 0