[英]Rspec error uninitialized constant
我有一家公司要做的招聘任务,涉及Rspec。 克隆了我必须处理的存储库后,我立即遇到了一些错误。 我实际上是Rspec或测试中的一个新手,我想改进,但是这个错误是我找不到的解决方案。
规格/验证/ 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
在运行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.
仔细阅读作业-也许您的任务之一就是添加文件并实现TitleBracketsValidator
类,使其通过所有提供的测试?
我会在您的资源中搜索该课程。 如果不存在-也许您应该创建一个。 如果在那里-那么就是加载问题。 在您的规格中require
它,并通知招聘人员您已修复了可能的错误(可能需要加分)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.