[英]Rspec error uninitialized constant
I've got a recruitment task to do from a company, that concerns Rspec. 我有一家公司要做的招聘任务,涉及Rspec。 After cloning their repo on which I have to work I immediately run on some errors.
克隆了我必须处理的存储库后,我立即遇到了一些错误。 I am completely new in Rspec or testing in general actually, I would like to improve, but this error is something I can't find a solution to.
我实际上是Rspec或测试中的一个新手,我想改进,但是这个错误是我找不到的解决方案。
spec/validators/title_brackets_validator_spec.rb 规格/验证/ title_brackets_validator_spec.rb
require "rails_helper"
describe TitleBracketsValidator do
subject { Validatable.new(title: title) }
shared_examples "has valid title" do
it "should be valid" do
expect(subject).to be_valid
end
end
context "with curly brackets" do
let(:title) { "The Fellowship of the Ring {Peter Jackson}" }
it_behaves_like "has valid title"
end
[ more not important 'contexts'...]
end
class Validatable
include ActiveModel::Validations
validates_with TitleBracketsValidator
attr_accessor :title
def initialize(title:)
@title = title
end
end
and while running bundle exec rspec
I get an error: 在运行
bundle exec rspec
出现错误:
An error occurred while loading ./spec/validators/title_brackets_validator_spec.rb.
Failure/Error:
describe TitleBracketsValidator do
subject { Validatable.new(title: title) }
shared_examples "has valid title" do
it "should be valid" do
expect(subject).to be_valid
end
end
shared_examples "has invalid title" do
NameError:
uninitialized constant TitleBracketsValidator
# /var/lib/gems/2.3.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `block in load_missing_constant'
# /var/lib/gems/2.3.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in `without_bootsnap_cache'
# /var/lib/gems/2.3.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `rescue in load_missing_constant'
# /var/lib/gems/2.3.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:43:in `load_missing_constant'
# ./spec/validators/title_brackets_validator_spec.rb:3:in `<top (required)>'
# /var/lib/gems/2.3.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
# /var/lib/gems/2.3.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
# ------------------
# --- Caused by: ---
# NameError:
# uninitialized constant TitleBracketsValidator
# /var/lib/gems/2.3.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:43:in `load_missing_constant'
Finished in 0.00045 seconds (files took 1.57 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
Coverage report generated for RSpec to /home/maciej/Templates/task_app/coverage. 0 / 108 LOC (0.0%) covered.
Read your assignment carefully - maybe one of your tasks is to add the file and implement the class TitleBracketsValidator
so it passes all the provided tests? 仔细阅读作业-也许您的任务之一就是添加文件并实现
TitleBracketsValidator
类,使其通过所有提供的测试?
I'd search for the class in your sources. 我会在您的资源中搜索该课程。 If not there - maybe you should create one.
如果不存在-也许您应该创建一个。 If it's there - then it's a loading issue.
如果在那里-那么就是加载问题。
require
it in your specs and notify the recruiter that you fixed a possible bug (for extra points maybe) 在您的规格中
require
它,并通知招聘人员您已修复了可能的错误(可能需要加分)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.