Offical documentation: https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md
gem 'factory_girl_rails'- Add the following to
spec/spec_helper.rbfor easier calling of FactoryGirl methods
RSpec.configure do |config|
# For Factory Girl
config.include FactoryGirl::Syntax::Methods
end- FactoryGirl creates doubles based on ActiveRecords
- If you don't have model, you can fake one:
#spec/support/models/deal.rb
class Deal
attr_accessor :title, :remainingQuantity, :price_amount
end- Another way is to define the non-ORM model class and through use of skip_create
- http://collectiveidea.com/blog/archives/2013/11/05/factory-girl-without-active-record/
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "user#{n}@example.com" }
password "123123"
confirmed_at Date.today
factory :buyer, class: Buyer do
first_name "Jay"
last_name "Chou"
address "Taiwan"
mobile "89933-3333"
telephone "2887-22232"
end
end
end