未初始化的常数FactoryGirl ::评估::可观察

时间:2013-03-07 14:01:41

标签: ruby factory-bot

我尝试将factory_girl 4.2.0与rspec 2.13.0一起使用。首先我添加' factory_girl'到我的Gemfile和包更新:

Using aasm (3.0.16) 
Using i18n (0.6.4) 
Using multi_json (1.6.1) 
Using activesupport (3.2.12) 
Using builder (3.0.4) 
Using activemodel (3.2.12) 
Using arel (3.0.2) 
Using tzinfo (0.3.36) 
Using activerecord (3.2.12) 
Using active_record_inline_schema (0.6.0) 
Using tins (0.7.1) 
Using amatch (0.2.11) 
Using coderay (1.0.9) 
Using conversions (1.4.6) 
Using fastercsv (1.5.5) 
Using fixed_width-multibyte (0.2.3) 
Using hash_digest (1.0.0) 
Using nokogiri (1.5.6) 
Using rubyzip (0.9.9) 
Using ruby-ole (1.2.11.6) 
Using spreadsheet (0.8.2) 
Using roo (1.10.3) 
Using unix_utils (0.0.15) 
Using remote_table (2.1.0) 
Using to_regexp (0.2.0) 
Using errata (1.1.1) 
Using posix-spawn (0.3.6) 
Using upsert (1.1.7) 
Using data_miner (2.4.1) 
Using diff-lcs (1.2.1) 
Using httpclient (2.3.3) 
Using method_source (0.8.1) 
Using pg (0.14.1) 
Using pg-hstore (1.1.7) 
Using slop (3.4.3) 
Using pry (0.9.12) 
Using rspec-core (2.13.0) 
Using rspec-expectations (2.13.0) 
Using rspec-mocks (2.13.0) 
Using rspec (2.13.0) 
Using umarket1-package (0.2.0) 
Using bundler (1.3.1) 

然后在我的spec_helper.rb中我做了:

require 'factory_girl'

但是我收到了这个错误:

.rvm/gems/ruby-1.9.3-p327/gems/factory_girl-4.2.0/lib/factory_girl/evaluation.rb:5:in `<class:Evaluation>': uninitialized constant FactoryGirl::Evaluation::Observable (NameError)

在factory_girl之前我是否需要其他东西?

1 个答案:

答案 0 :(得分:1)

可能你有一个文件在某个地方定义了一个Observer类(甚至只是一个名为observer.rb的文件)。

https://github.com/thoughtbot/factory_girl/blob/af282a178b02ea9cc85b7b0767fce836a76108b4/lib/factory_girl/evaluation.rb#L1

并在您初始化应用程序后加载它(lib文件夹中的示例)。