perpetuum mobile
05. 08. 2014. bdd / tdd * ruby gem

Factorygirl

http://rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md


it "redirects to the home page upon save" do
  post :create, contact: Factory.attributes_for(:contact)
  response.should redirect_to root_url
end

A factory generates test data to pass to the controller method; note the use of Factory Girl’s attributes_for option, which generates a hash of values as opposed to a Ruby object.

After create

factory :user do
  after(:create) {|instance| create_list(:post, 5, user: instance) }
end

Resources: