I installed Fabrication and Faker in my Rails 4 project
I created a fabrarication object:
Fabricator(:course) do
title { Faker::Lorem.words(5) }
description { Faker::Lorem.paragraph(2) }
end
And I'm calling the Faker object within my courses_controller_spec.rb test:
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
But for some reason, the test failes at line 6:
course = Fabricate(:course)
the error message is:
Failure/Error: course = Fabricate(:course)
TypeError:
can't cast Array to string
Don't know exactly why this is failing. Has anyone experienced the same error message with Faker?
The return from words(5)
is an array, not a string. You should do this:
title { Faker::Lorem.words(5).join(" ") }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With