如何调用嵌套的factory_girl属性

时间:2015-06-29 00:25:57

标签: ruby-on-rails unit-testing testing rspec tdd

我正在使用rspec和工厂女孩,并且从工厂获得子类有一个奇怪的问题。我正在创建一个设计器,它是用户的子猫,但是测试仍在接收用户,而不是设计师。

FactoryGirl.define do
  factory :user do
    factory :designer do
      role: "designer"
    end
  end
end

describe StoreRating do
  it "should have a rating" do
    user = FactoryGirl.create(:designer)
    store = FactoryGirl.create(:store)

    StoreRating.create(designer: user, store: store, rating: 5) 
  end
end

expected Designer, got User

1 个答案:

答案 0 :(得分:0)

尝试:

FactoryGirl.define do
  factory :user do
    factory :designer, class: Designer do
      role: "designer"
    end
  end
end