有人可以解释为什么工厂比测试期间的简单实例更有用吗?更清楚的是,我没有看到以下区别:
before(:each) do @attr = { :name => "Example User",:email => "user@example.com",: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 "mhartl@example.com" user.password "foobar" user.password_confirmation "foobar" end