测试 space.rb 的 modle 时
在 space_pages_spec.rb 代码如下
describe "show space page" do
before do
@space = Space.create(
space_setting: "1",
user_group: "1",
rent_env: "1",
num_of_people: "1",
city: "上海",
title: "你好杨浦",
content: "五角场商圈",
photo: "wujiaochang.jpg",
detailed: "1,2,3,4,6,7")
visit space_path(@space)
end
it { should have_selector('h3', text: space.title)}
it { should have_selector('h4', text: space.city)}
end
报错如下
Failures:
1) SpacePages show space page
Failure/Error: visit space_path(@space)
ActiveRecord::RecordNotFound:
Couldn't find SpaceSetting with id=1
# ./app/controllers/spaces_controller.rb:10:in show'
# ./spec/requests/space_pages_spec.rb:30:in
block (3 levels) in '
2) SpacePages show space page
Failure/Error: visit space_path(@space)
ActiveRecord::RecordNotFound:
Couldn't find SpaceSetting with id=1
# ./app/controllers/spaces_controller.rb:10:in show'
# ./spec/requests/space_pages_spec.rb:30:in
block (3 levels) in '
Finished in 0.25858 seconds 4 examples, 2 failures
为什么会找不到 id=1 的 SpaceSetting 呢?