我尝试将 Factory_girl 放入我的 Rails 应用程序中进行测试。
这是 Gemfile 的一部分:
gem 'rspec-rails', :group => [:development, :test]
group :development do
gem 'annotate'
gem 'faker', '0.3.1', :require => false
gem 'populator', '1.0.0'
gem 'ruby-debug19'
end
group :test do
gem "capybara"
gem 'factory_girl_rails', '~> 3.5.0'
gem 'guard-rspec'
gem 'guard-spork'
gem 'spork'
gem 'rb-inotify'
gem 'libnotify'
end
group :development, :test do
gem 'sqlite3-ruby', :require=>'sqlite3'
end
然后我进入控制台测试Factory_Girl的安装,例如:rails c
调用该方法:find_definitions
Loading development environment (Rails 3.0.5)
irb(main):002:0> FactoryGirl.find_definitions
NameError: uninitialized constant FactoryGirl
from (irb):2
from /var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands/console.rb:44:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands/console.rb:8:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
所以我假设我必须要求宝石:我这样做并且:
irb(main):003:0> require 'factory_girl_rails'
SystemStackError: stack level too deep
from /usr/lib/ruby/1.9.1/irb/workspace.rb:80
Maybe IRB bug!!
我收到了这个奇怪的错误。
我究竟做错了什么?
有关信息,我在 Rails 3.0.5 和 ruby 1.9.2 上。
宝石配置是:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [i686-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /var/lib/gems/1.9.1
- /home/izambard/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES: