测试资产时出错:无法复制 NilClass
我正在使用 Rails 3.0.9 和 ruby 1.9.2。我正在做一个系统,允许用户将物品放入不同的壁橱中。用户的一种可能性是将其他用户的物品复制到他自己的衣柜中(如果您不明白,请告诉我,我不擅长解释事情..)。
为了处理图像,我使用回形针 2.3.16。我正在使用 Rspec-rails 2.6.1、Cucumber-rails 1.0.2 测试我的应用程序。当我用guard & 运行测试时spork 资产的复制部分,我遇到了“TypeError:无法复制 NilClass”。我在网上搜索了答案,但没有找到任何具体的和有效的:(。
你对这个问题有想法吗?
我的 Close_spec.rb 代码(如果你需要其他东西,请告诉我):
describe '#tidy_up' do
let!(:other_user) { Factory.create(:confirmed_user, :user_name => 'Plop', :email => '[email protected]') }
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
I'm using rails 3.0.9 with ruby 1.9.2. I am doing a system that allow users to put items into different closets. One of the user's possibility is to copy an item of an other user into his own closet (please tell me if you don't understand, I'm not good in explaining things..).
To handle images, I'm using paperclip 2.3.16. I'm testing my app with Rspec-rails 2.6.1, Cucumber-rails 1.0.2. When I run my tests with guard & spork on the asset's copy part, i'm having a "TypeError: can't dup NilClass". I've search on the net for an answer but didn't find anything specific and working :(.
Have you an idea about this issue ?
My code for closet_spec.rb (if you need something else, just tell me) :
describe '#tidy_up' do
let!(:other_user) { Factory.create(:confirmed_user, :user_name => 'Plop', :email => '[email protected]') }
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论