gpt4 book ai didi

factory-bot - Rails 4 中的 Factory Girl 导致 rake 数据库任务加载错误

转载 作者:行者123 更新时间:2023-12-05 00:27:24 27 4
gpt4 key购买 nike

我有一个非常简单的 Rails 4 应用程序,想使用 Factory Girl 编写一些示例测试。该应用程序适用于一些简单的 rspec 测试(全部通过),但是当我将“factory_girl_rails”添加到 gemfile 时,“rake db:migrate”给我以下错误:

MacBook-Pro-2:project-folder me$ rake db:migrate
/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load': cannot load such file -- /Users/me/Code/project-folder/db:migrate (LoadError)
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `block in load'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

这是我的 spec_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__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'factory_girl_rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.formatter = :documentation
config.include Capybara::DSL
config.include FactoryGirl::Syntax::Methods
end

此外,gemfile 本身:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

# To use debugger
gem 'debugger'

gem "devise", :git => "git://github.com/plataformatec/devise.git", :branch => "rails4"

group :development, :test do
gem "rb-fsevent", "~> 0.9.1"
gem "guard", "1.6.2"
gem "guard-rspec", "2.5.1"
gem "rspec-rails", "2.13.1"
gem "shoulda-matchers", "2.1.0"
gem "capybara", "2.1.0"
gem "launchy", "2.2.0"
gem 'factory_girl_rails', '4.2.1'
end

我没有对申请的任何部分进行任何其他更改。我错过了什么?

最佳答案

尝试使用 bundle exec rake db:migrate

关于factory-bot - Rails 4 中的 Factory Girl 导致 rake 数据库任务加载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17983808/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com