我是Ruby on Rails的初学者,我正在为wiki项目编写“用户登录”规范,我收到以下错误:
uninitialized constant TestFactories (NameError)
这是我的sign_in_spec.rb
require 'rails_helper'
describe "Sign in flow" do
include TestFactories
before do
@user = authenticated_user
end
describe "successful" do
it "redirects user to the wikis index" do
user = authenticated_user
visit root_path
end
end
end
这是我的test_factories.rb文件:
module TestFactories
def authenticated_user(options={})
user_options = { email: "email#{rand}@fake.com", password: 'password' }.merge(options)
user = User.new(user_options)
user.skip_confirmation!
user.save
user
end
end
这是我的Gemfile:
source 'https://rubygems.org'
gem 'rails'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# Testing
group :develpment, :test do
gem 'rspec-rails'
gem 'capybara'
gem 'database_cleaner'
gem 'factory_girl_rails', '~> 4.0'
gem 'pry-rails'
end
# Databases
# Developemnt
gem 'sqlite3'
答案 0 :(得分:0)
或者您可以在sepc helper中执行类似的操作
RSpec.configure do |config|
config.include TestFactories
end