1

啊,这可能是一个令人尴尬的问题,但我是工厂女孩的新手。

规范/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'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

RSpec.configure do |config|

end

规格/工厂.rb

FactoryGirl.define do
    factory :user do
        email "example@hotmail.com"
        password "password"
    end
end

规范/密码重置规范.rb

require 'spec_helper'

describe "PasswordResets" do
    it "emails user when requesting a password rest" do
        user = FactoryGirl.create :user
    end
end

然而这给了我:

uninitialized constant User

那么我需要先定义用户模型吗?

4

1 回答 1

1

当然是。FactoryGirl 无法在没有模型的情况下创建记录。

于 2013-09-26T00:53:42.460 回答