0
사양에 fabricator를 사용하는 동안 빈 배열이 나타납니다. 내 생각 엔 fabricator 파일이로드되지 않았다는 것입니다. RSpec의 초기화 후에 fabricator 파일을로드하면 Fabrication::DuplicateFabricatorError
이 발생합니다.Fabricators가로드되지 않습니다.
- 레일 4.1.4
- RSpec에 코어 3.1.5
- RSpec에 레일 3.1.0
- 제조 2.11.3
: 여기 내 설정이다.
# config/application.rb
config.generators do |g|
g.test_framework :rspec, fixture: true
g.fixture_replacement :fabrication, dir: "spec/fabricators"
end
# spec/rails_helper.rb
config.fixture_path = "#{::Rails.root}/spec/fabricators"
config.use_transactional_fixtures = true
여기 일하는 것이 아니라해야 할 코드의 : 사양을 실행할 때
# app/models/user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
# spec/fabricators/user_fabricator.rb
Fabricator(:user) do
email { Faker::Internet.email }
password "password"
password_confirmation "password"
end
# spec/models/user_spec.rb
require 'rails_helper'
describe User do
before :each do
@user = Fabricator(:user)
#=> []
end
it "has an email" do
expect(@user.email).to be_a(String)
expect(@user.email.length).to be > 0
end
end
를 빈 배열 내 제작자에 대해 반환받은 후,이 오류가 발생합니다 : undefined method 'email' for []:Array
. 나는 지나가는 spec를 얻을 것으로 예상한다.
감사합니다. Paul! 내 사양은 두 가지 변경 사항을 전달합니다. 나는 철자법 차이를 놓치기 때문에 어리석은 느낌이지만, 단어 선택은 당신이 그것을 언급 할 때 많은 의미를가집니다. – Nathan