我正在阅读Rails 5 Test Prescriptions这本书,我在运行其中一个例子时遇到了问题。谢谢你的帮助。
我有一个名为point_of_interest.rb的模型 应用程序/模型/ point_of_interest.rb
我收到以下错误:
NameError: uninitialized constant CreatesPointOfInterest
规格/工作流/ creates_point_of_interest.rb
class CreatesPointOfInterest
attr_accessor :name, :point_of_interest
def initialize(name: "")
@name = name
end
def build
self.point_of_interest = PointOfInterest.new(name: name)
end
end
规格/工作流/ creates_point_of_interest_spec.rb
require "rails_helper"
RSpec.describe CreatesPointOfInterest do
describe "initialization" do
it "creates a point of interest given a name" do
creator = CreatesPointOfInterest.new(name: "Pyramids of Giza")
creator.build
expect(creator.point_of_interest.name).to eq("Pyramids of Giza")
end
end
end
终端输出:
〜/ Desktop / adventure / adventure [开发|!SP] $ rspec
An error occurred while loading
./spec/workflows/creates_point_of_interest_spec.rb.
Failure/Error:
RSpec.describe CreatesPointOfInterest do
describe "initialization" do
it "creates a point of interest given a name" do
creator = CreatesPointOfInterest.new(name: "Pyramids of
Giza")
creator.build
expect(creator.point_of_interest.name).to eq("Pyramids of
Giza")
end
end
NameError:
uninitialized constant CreatesPointOfInterest
其他错误:
.rvm/gems/ruby-2.3.3/gems/bootsnap-
1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in
`block in load_missing_constant'
.rvm/gems/ruby-2.3.3/gems/bootsnap-
1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in
`without_bootsnap_cache'
.rvm/gems/ruby-2.3.3/gems/bootsnap-
1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in
`rescue in load_missing_constant'
.rvm/gems/ruby-2.3.3/gems/bootsnap-
1.3.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:43:in
`load_missing_constant'
./spec/workflows/creates_point_of_interest_spec.rb:3:in `<main>'
.rvm/gems/ruby-2.3.3/gems/bootsnap-
1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in
--- Caused by: ---
NameError: uninitialized constant CreatesPointOfInterest
答案 0 :(得分:0)
您的应用使用的类应位于a <- list(
c("C", "A", "C", "C", "U", "U", "G", "U", "C", "C", "U", "C", "A", "C", "G", "G", "U", "C"),
c("G", "U", "A", "G", "C", "A", "C", "U", "A", "A", "A", "G", "U", "G", "C", "U", "U", "A")
)
b <- list(
c(3, 4, 6, 7, 9, 10, 11, 12),
c(1, 2, 3, 4, 6, 7, 8, 10)
)
library(dplyr)
key <- data_frame(
grp = rep(seq_along(a), lengths(a)),
element = unlist(a)
) %>%
group_by(grp) %>%
mutate(loc = seq_len(n()))
lookup <- data_frame(
grp = rep(seq_along(b), lengths(b)),
loc = unlist(b)
)
lookup %>%
left_join(key, by = c("grp", "loc"))
lookup %>%
left_join(key, by = c("grp", "loc")) %>%
{split(.$element, .$grp)}
## $`1`
## [1] "C" "C" "U" "G" "C" "C" "U" "C"
##
## $`2`
## [1] "G" "U" "A" "G" "A" "C" "U" "A"
目录而不是app/
所以你应该:
spec
不
app/workflows/creates_point_of_interest.rb
您的spec文件名应与类名匹配。你确定这是对的吗?
spec/workflows/creates_point_of_interest.rb
但它应该是
spec/workflows/create_point_of_interest_spec.rb