我已经运行了测试,并且看起来用户不会被Factory Girl创建。这就是我得到的:
reports_controller_spec.rb
require 'rails_helper'
RSpec.describe ReportsController do
let(:user) { create :user }
before { sign_in user }
describe 'GET #subjects' do
subject { get :subjects }
it_behaves_like 'template rendering action', :subjects
end
end
工厂/ users.rb的
FactoryGirl.define do
factory :user do
email { Faker::Internet.safe_email }
password { Faker::Internet.password }
end
end
当我运行测试时,我收到此错误:
ReportsController
GET #subjects
behaves like template rendering action
example at ./spec/support/shared/template_rendering_action.rb:2 (FAILED - 1)
Failures:
1) ReportsController GET #subjects behaves like template rendering action
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `password=' for #<User:0x000000063abd20>
Shared Example Group: "template rendering action" called from ./spec/controllers/reports_controller_spec.rb:11
...
我不明白为什么它不起作用。任何人都可以指出我的错误?感谢。
编辑:我正在使用设计。
答案 0 :(得分:4)
如果您使用的是Devise,则需要将password_confirmation
添加到:user
工厂