0

我正在尝试将 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 之前我需要其他要求吗?

4

1 回答 1

1

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

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

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

于 2013-08-06T05:06:34.350 回答