我有以下内容:
# lib/devblog_extensions.rb
module DevblogExtensions
class Time
def self.random_date
# implementation ...
end
end
end
# spec/factories/posts.rb
FactoryGirl.define do
factory :post do
release_date Time.random_date # NoMethodError occurs
end
end
然后在config/application.rb
我有:
config.autoload_paths += %W(#{config.root}/lib)
但是当我跑rspec
时,我仍然得到NoMethodError
,所以我错过了什么?谢谢!
答案 0 :(得分:0)
您可能缺少包含
# spec/factories/posts.rb
include DevblogExtensions
FactoryGirl.define do
factory :post do
release_date Time.random_date # NoMethodError occurs
end
end
更新:快速修复
# lib/devblog_extensions.rb
module DevblogExtensions
end
class Time
def self.random_date
Time.now
end
end