【发布时间】:2014-04-17 18:04:16
【问题描述】:
在运行我的测试时,我不断遇到一个完全无法描述的错误:
undefined method `body' for nil:NilClass
堆栈跟踪将我指向我用于数据库的 gem 中与 Elastic Search 相关的 1 行,该数据库在两个 Rails 项目之间共享。
undefined method `body' for nil:NilClass
# /home_path/project/project-lib/lib/model.rb:31:in update_or_remove_index'
第31行相关的代码是
after_save :update_or_remove_index
def update_or_remove_index
if self.visible
update_index
else
tire.index.remove self
end
end
当 FactoryGirl 创建一个模拟对象并保存它,触发 after_save#update_or_remove_index 时,此错误通常发生在规范中。当我存根 :update_or_remove_index 时,测试通过了。
我正在运行 Ubuntu 13.10、Rails '3.2.17'、'tire'、'~> 0.4.2' 和 factory_girl_rails
**编辑
想通了。有空会回复的
【问题讨论】:
标签: ruby-on-rails rspec factory-bot tire