我在 Rails 4 项目中安装了 Fabrication 和 Faker
我创建了一个制造对象:
Fabricator(:course) do
title { Faker::Lorem.words(5) }
description { Faker::Lorem.paragraph(2) }
end
我在我的 courses_controller_spec.rb 测试中调用 Faker 对象:
require 'spec_helper'
describe CoursesController do
describe "GET #show" do
it "set @course" do
course = Fabricate(:course)
get :show, id: course.id
expect(assigns(:course)).to eq(course)
end
it "renders the show template"
end
end
但由于某种原因,测试在第 6 行失败:
course = Fabricate(:course)
错误信息是:
Failure/Error: course = Fabricate(:course)
TypeError:
can't cast Array to string
不知道为什么会失败。有没有人在使用 Faker 时遇到过同样的错误信息?