0
我有一個:fakeUser
工廠定義在factories/user.rb
,我正確使用user_spec.rb
。從另一家工廠使用FactoryGirl工廠?
我希望能夠做到這一點,create(:fakeUser)
,在另一個rspec文件potato_spec.rb
。
我該怎麼做?
我有一個:fakeUser
工廠定義在factories/user.rb
,我正確使用user_spec.rb
。從另一家工廠使用FactoryGirl工廠?
我希望能夠做到這一點,create(:fakeUser)
,在另一個rspec文件potato_spec.rb
。
我該怎麼做?
require 'spec_helper'
feature "your potato test" do
let!(:fakeUser) { FactoryGirl.create(:fakeUser) }
context "your test context" do
#...the actions you want to test
end
end
內背景你可能有不同的場景,例如「當用戶登錄」或「當用戶尚客」。
前提是你有一個工廠users.rb的是這樣的:在`規格/工廠定義
FactoryGirl.define do
factory :fakeUser do
name 'John'
#... other attributes you might have for the user
end
end
接受,因爲它是正確的,但Stefan評論說,正是我所需要的。謝謝。 – GigaBass
工廠/ * rb'會自動加載並應在所有規格可用。 – Stefan
順便說一句,你應該使用蛇的情況下,即'fake_user'或者乾脆''用戶' – Stefan
我發誓我只是徹底嘗試使用它,它沒有奏效。但它確實如此。這正是我需要的,謝謝! – GigaBass