Skip to content

composerinteralia/factory_bot_profile

Repository files navigation

FactoryBotProfile

FactoryBotProfile identifies expensive factories and heavy factory_bot usage. Use this information to speed up your test suite!

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add factory_bot_profile

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install factory_bot_profile

Usage

The primary API for using this library is to wrap the code you want to profile with the .reporting method:

require "factory_bot_profile"

FactoryBotProfile.reporting do
  # Code that uses factory_bot
end

This will profile every call to factory_bot inside the block, and then print the results to stdout after the code inside the block finishes.

If you need more control over where to start and stop profiling, and when to report the results, use the .subscribe and .report methods:

subscription = FactoryBotProfile.subscribe

# Code that uses factory_bot

subscription.unsubscribe
FactoryBotProfile.report(subscription.stats)

Why not FactoryProf?

FactoryProf is another fantastic tool for profiling factories, and it includes a really neat flamegraph feature that this library doesn't have (at least not yet). So why did I write this library?

FactoryProf profiles factories by monkey patching factory_bot. It's also part of the larger TestProf library, which includes a number of other monkey patches, and it's difficult to load FactoryProf without bringing in other parts of the library as well. These monkey patches can make it difficult to add FactoryProf to an application.

FactoryBotProfile, on the other hand, uses factory_bot's built-in instrumentation to build the profile. My hope is that using built-in factory_bot features, and avoiding monkey patches or private APIs should make this library fairly stable.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/composerinteralia/factory_bot_profile. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the FactoryBotProfile project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

Profile your factory_bot factories

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published