3

我有一个非常简单的 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

我没有对应用程序的任何部分进行任何其他更改。我错过了什么?

4

1 回答 1

0

尝试使用bundle exec rake db:migrate

于 2013-12-09T11:52:10.747 回答