所以我有一個工廠女孩的問題,我一直在使用它很多,這是我有這個問題的第一個Rails應用程序。基本上,當我在控制檯中使用它時,會發生消息/home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/pry-0.10.3/lib/pry/last_exception.rb:54:in 'bt_source_location_for': undefined method '[]' for nil:NilClass (NoMethodError)
和完全由gem庫組成的回溯。當我去測試時,它也失敗了。在spec/support/factory_girl.rb
測試初始化支持目錄我包括相應的代碼以皮棉工廠,我總是做DatabaseCleaner:工廠女孩崩潰測試和控制檯
RSpec.configure do |config|
config.before(:suite) do
begin
DatabaseCleaner.start
FactoryGirl.lint
ensure
DatabaseCleaner.clean
end
end
end
這將導致當測試運行錯誤:/home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.6.3/lib/spring/application.rb:271:in 'ensure in block (2 levels) in shush_backtraces': undefined method 'reject!' for nil:NilClass (NoMethodError)
當我刪除提交新的錯誤被拋出,當我第一次去使用工廠女孩方法:
ActiveRecord::Base.transaction do
create(:team)
end
-
NoMethodError: undefined method `reject!' for nil:NilClass
--- Caused by: ---
fatal:
exception reentered
我以前從來沒有見過'引起錯誤重新進入的消息',但它看起來很神祕。 Factory Girl的版本是4.5,Rails版本是4.2.5,RSpec版本是3.4。我剛開始這個應用程序,所以應用程序沒有太多的其他代碼,但這裏是rails helper,spec helper和Gemfile。
rails_helper.rb
# This file is copied to spec/ when you run 'rails generate
rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'shoulda/matchers'
require 'simplecov'
SimpleCov.start 'rails'
include ActionDispatch::TestProcess
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end
spec_helper.rb
require 'paperclip/matchers'
require 'devise'
RSpec.configure do |config|
config.include Paperclip::Shoulda::Matchers
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
的Gemfile
source 'https://rubygems.org'
gem 'coffee-rails', '~> 4.1.0'
gem 'devise'
gem 'jbuilder', '~> 2.0'
gem 'jquery-rails'
gem 'jwt'
gem 'paperclip', '~> 4.3'
gem 'pg', '~> 0.15'
gem 'rails', '~> 4.2.5'
gem 'sass-rails', '~> 5.0'
gem 'turbolinks'
gem 'uglifier', '>= 1.3.0'
gem 'unicorn'
group :test, :development do
gem 'dotenv-rails'
gem 'bullet'
gem 'did_you_mean', '~> 0.10.0'
gem 'factory_girl_rails'
gem 'pry-rails'
gem 'rspec-rails'
end
group :test do
gem 'database_cleaner'
gem 'shoulda-matchers', require: false
gem 'simplecov', :require => false
end
group :development do
gem 'active_record_query_trace'
gem 'better_errors'
gem 'binding_of_caller'
gem 'spring'
gem 'spring-commands-rspec'
end