[英]uninitialized constant ApplicationRecord rspec
1) created a model called Skill
1)创建了一个称为Skill
的模型
2) ran some seeds 2)跑了一些种子
3) ran rspec --init
3)运行rspec --init
4) created file skill_spec.rb
with the code below 4)使用以下代码创建文件skill_spec.rb
require_relative "../app/models/skill"
describe Skill do
describe "database" do
it "should have 42 skills" do
expect(Skill.all.count).to eq(42)
end
end
end
5) when I run rspec
in console get error: 5)当我在控制台中运行rspec
时出现错误:
Failure/Error: class Skill < ApplicationRecordNameError: uninitialized constant ApplicationRecord 失败/错误:类Skill <ApplicationRecordNameError:未初始化的常量ApplicationRecord
I already have a file application_record.rb
with the following code 我已经有一个包含以下代码的文件application_record.rb
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
For rails specs use require 'rails-helper'
at beginning of each spec file (it is generated by bin/rails generate rspec:install
from rspec-rails
gem) 对于Rails规范,请在每个规范文件的开头使用require 'rails-helper'
(由bin/rails generate rspec:install
从rspec-rails
gem bin/rails generate rspec:install
)
It contains line require File.expand_path('../config/environment', __dir__)
that will load your rails environment and you'll have autoloading and all other rails parts working. 它包含行require File.expand_path('../config/environment', __dir__)
,它将加载您的rails环境,并且您将具有自动加载功能,并且所有其他rails部件都将工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.