Heading image for post: Fabrication 2.0 Upgrade Guide


Fabrication 2.0 Upgrade Guide

Profile picture of Paul Elliott

Fabrication 2.0 came out a few days ago and to bring some of the cool new enhancements we had to break some of the api for existing users. Here is a short list of the changes you'll need to make in your test suite to upgrade.

Remove all the "!" suffixes

Lazy generation is no longer a thing in fabrication so the "!" is no longer necessary. If you leave them in you will see a deprecation warning but things will work

Update usage of attribute block variables

In fabrication 1.x, a block was passed the object being generated. Now is just collects them into an attributes hash and provides that to the block.

The old way:

Fabricator(:person) do
  first_name { Faker::Name.first_name }
  email { |person| "#{person.first_name.downcase}@example.com" }

The new way:

Fabricator(:person) do
  first_name { Faker::Name.first_name }
  email { |attrs| "#{attrs[:first_name].downcase}@example.com" }

As you can see, the change is very simple to make. You will just need to go through and update your Fabricators.

Regenerate the fabrication cucumber steps

Some bug fixes have been made in the steps and a new feature was introduced, so you should regenerate the steps with rails g fabrication:cucumber_steps if you are using them in your project.

Getting Help

If you run into any issues, be sure to check the documentation (http://fabricationgem.org).

If that doesn't help you can open an issue on github (https://github.com/paulelliott/fabrication/issues).

Or if you prefer, you can send a message to the mailing list and I will reply to you (https://groups.google.com/group/fabricationgem).

More posts about Ruby Development

  • Adobe logo
  • Barnes and noble logo
  • Aetna logo
  • Vanderbilt university logo
  • Ericsson logo

We're proud to have launched hundreds of products for clients such as LensRentals.com, Engine Yard, Verisign, ParkWhiz, and Regions Bank, to name a few.

Let's talk about your project