Skip to content
Simple tool to maintain factories and traits from FactoryBot
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
exe Add support of partial execution Apr 30, 2019
lib Merge branch 'master' of github.com:djezzzl/factory_trace May 5, 2019
rails-rspec-example Make executable to be independent from project setup May 5, 2019
spec Make executable to be independent from project setup May 5, 2019
.gitignore Add total number of used/unused factories and traits. Apr 28, 2019
.rspec Initial commit Apr 28, 2019
.travis.yml Initial commit Apr 28, 2019
CHANGELOG.md Release 0.2.2 May 5, 2019
CODE_OF_CONDUCT.md Initial commit Apr 28, 2019
Gemfile
LICENSE.txt Initial commit Apr 28, 2019
README.md Make executable to be independent from project setup May 5, 2019
Rakefile Initial commit Apr 28, 2019
factory_trace.gemspec Add support of partial execution Apr 30, 2019

README.md

FactoryTrace

Build Status Gem Version

The main goal of the project is to provide an easy way to maintain FactoryBot inside your project in a good shape.

What it does?

Currently, it helps to find unused factories and traits.

Example output (from Rails RSpec Example):

$ FB_TRACE=1 rspec
total number of unique used factories & traits: 3
total number of unique unused factories & traits: 2
unused global trait with_email
unused factory admin

Installation

Add this line to your application's Gemfile in the group you have factory_bot or factory_bot_rails:

gem 'factory_trace'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install factory_trace

Usage

For now, the gem supports RSpec out of the box. You don't need to add any hooks. Just run the specs, e.g.

# output to STDOUT
FB_TRACE=1 rspec
# OR output to any file
FB_TRACE_FILE=log/factory_trace.txt rspec

For any other case, add the following line where you want to start tracking usage of FactoryBot factories and traits:

FactoryTrace.start

Add this line where you want to stop tracking and get collected information:

FactoryTrace.stop

Partial execution

Imagine, you run your specs in parts (as many as you need) and then want to track total usage of factories and traits. For that, we have a trace_only mode. You can try following commands here.

# one part
FB_TRACE=trace_only FB_TRACE_FILE=fb_trace_result1.txt bundle exec rspec spec/first_spec.rb
# another part
FB_TRACE=trace_only FB_TRACE_FILE=fb_trace_result2.txt bundle exec rspec spec/second_spec.rb
# finally output the usage to the console
bundle exec factory_trace fb_trace_result1.txt fb_trace_result2.txt
# or to the file
FB_TRACE_FILE=fb_report.txt bundle exec factory_trace fb_trace_result1.txt fb_trace_result2.txt

Note: bundle exec factory_trace won't load your project. Thus it runs fast and easier to configure it on CI.

Configuration

You can configure FactoryTrace:

FactoryTrace.configure do |config|
  # default ENV.key?('FB_TRACE') || ENV.key?('FB_TRACE_FILE')
  config.enabled = true 
  
  # default is ENV['FB_TRACE_FILE']
  # when nil outputs to STDOUT 
  config.path = 'log/factory_trace.txt' 
  
  # default is true when +path+ is nil
  config.color = true
  
  # default is ENV['FB_TRACE'] || :full 
  # can be :full or :trace_only 
  config.mode = :full
end

Development

After checking out the repo, run bundle install to install dependencies. Then, run rake spec to run the tests. 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 tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant 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 FactoryTrace project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Changelog

FactoryTrace's changelog is available here.

Copyright

Copyright (c) Evgeniy Demin. See LICENSE.txt for further details.

You can’t perform that action at this time.