可能有人請解釋爲什麼工廠比測試過程中一個簡單的實例更加有用嗎?更明確地說,我不明白之間的差別:Rails的3個工廠VS簡單的實例化
before(:each) do
@attr = {
:name => "Example User",
:email => "[email protected]",
:password => "foobar",
:password_confirmation => "foobar"
}
end
it "should create a new instance given valid attributes" do
User.create!(@attr)
end
這
before(:each) do
@user = Factory(:user)
end
它具有以下工廠
:
Factory.define :user do |user|
user.name "Michael Hartl"
user.email "[email protected]"
user.password "foobar"
user.password_confirmation "foobar"
end
謝謝apneadiving。它看起來像我一樣,所以我假設方便,但由於我從頭開始學習,我想確保我沒有失去任何東西。感謝名單! –