Rspec으로 테스트하는 방법을 배우려고합니다. 하지만,Rspec으로 presence_and belongs_to를 테스트하십시오.
require 'spec_helper'
describe Item do
it { should belong_to :list }
before(:each) do
@item = FactoryGirl.create(:item)
end
subject { @item }
it { should respond_to :name }
it { should validate_presence_of :name }
end
이것에 대해 몇 가지 질문이 있습니다 순간
나는 아이템 클래스의 스펙을 가지고있다.는 it { should validate_presence_of :name }
작성과 동일합니다 :
describe "when name is not present" do
before { @item.name = "" }
it { should_not be_valid }
end
또는 둘 사이에 중요한 차이가있다?
it { should belong_to :list }
이 사양에 맞게 작성해야하는지 또는 더 좋은 방법이 있는지 궁금합니다.
또한 @item = FactoryGirl.build(:item)
또는 FactoryGirl.create(:item)
을 할 수 있음을 알고 있습니다. 생성은 테스트 DB에 항목을 저장하고 빌드하지 않습니까? 또는 나는 여기에서 혼란 스럽다. 어떤 것을 사용해야합니까?
감사합니다.
감사합니다. 나는 정말로 shoulda-matchers를 사용하고 있습니다. 나는 짧은 형식을 사용할 것이다! :) – cabaret