rspec+fabricationを使用して簡単なテストを実行しようとしています。残念ながら、これに関するまともな記事はそれほど多くありません。
spec / model/event_spec.rb内
require 'spec_helper'
describe Event do
subject { Fabricate(:event) }
describe "#full_name" do
its(:city) { should == "LA" }
end
end
spec/fabricators/event_fabricator.rb内
Fabricator(:event) do
user { Fabricate(:user) }
# The test works if I uncomment this line:
# user_id 1
city "LA"
description "Best event evar"
end
spec/fabricators/user_fabricator.rb内
Fabricator(:user) do
name 'Foobar'
email { Faker::Internet.email }
end
私は得続けます:
1) Event#full_name city
Failure/Error: subject { Fabricate(:event) }
ActiveRecord::RecordInvalid:
Validation failed: User can't be blank
PS rspecとファブリケーションの開始について読む価値のあるオンライン記事/チュートリアルを知っている人がいれば、PS。私に知らせてください