Rspec错误未初始化常量



我有一个公司的招聘任务要做,涉及Rspec。在克隆了他们的repo(我必须在上面工作(之后,我立即遇到了一些错误。我对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在你的规格中,并通知招聘人员你修复了一个可能的错误(可能是为了获得额外的分数(

最新更新