All Projects → djezzzl → Factory_trace

djezzzl / Factory_trace

Licence: mit
Simple tool to maintain factories and traits from FactoryBot

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Factory trace

Fake ftp
A fake FTP server for use with ruby tests
Stars: ✭ 77 (-58.15%)
Mutual labels:  rspec, minitest
N plus one control
RSpec and Minitest matchers to prevent N+1 queries problem
Stars: ✭ 345 (+87.5%)
Mutual labels:  rspec, minitest
capybara select2
Capybara helpers for https://select2.org select box (supports Select2 version 2/3/4)
Stars: ✭ 48 (-73.91%)
Mutual labels:  rspec, minitest
Still life
Rails upgrade's best friend
Stars: ✭ 213 (+15.76%)
Mutual labels:  rspec, minitest
Lurker
📖 The ultimate tool for documenting and testing APIs in Rails
Stars: ✭ 120 (-34.78%)
Mutual labels:  rspec, minitest
bdd
Given/When/Then/And/But output to RSpec and Minitest
Stars: ✭ 33 (-82.07%)
Mutual labels:  rspec, minitest
factory bot-preload
Preload factories (factory_bot) just like fixtures. It will be easy and, probably, faster!
Stars: ✭ 68 (-63.04%)
Mutual labels:  rspec, minitest
Rantly
Ruby Imperative Random Data Generator and Quickcheck
Stars: ✭ 241 (+30.98%)
Mutual labels:  rspec, minitest
Vscode Ruby Test Adapter
A Ruby test adapter extension for the VS Code Test Explorer
Stars: ✭ 50 (-72.83%)
Mutual labels:  rspec, minitest
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+389.13%)
Mutual labels:  rspec, minitest
Action Cable Testing
Action Cable testing utils
Stars: ✭ 192 (+4.35%)
Mutual labels:  rspec, minitest
With model
Dynamically build an Active Record model (with table) within a test context
Stars: ✭ 119 (-35.33%)
Mutual labels:  rspec, minitest
knapsack pro-ruby
Knapsack Pro gem splits tests across parallel CI nodes and makes sure that tests will run in optimal time on each node.
Stars: ✭ 101 (-45.11%)
Mutual labels:  rspec, minitest
Knapsack
Knapsack splits tests evenly across parallel CI nodes to run fast CI build and save you time.
Stars: ✭ 430 (+133.7%)
Mutual labels:  rspec, minitest
Email Spec
Collection of RSpec/MiniTest matchers and Cucumber steps for testing email in a ruby app using ActionMailer or Pony
Stars: ✭ 1,142 (+520.65%)
Mutual labels:  rspec, minitest
Mutant
Automated code reviews via mutation testing - semantic code coverage.
Stars: ✭ 1,794 (+875%)
Mutual labels:  rspec, minitest
Accept values for
Rspec matchers to test ActiveModel validation that follows BDD.
Stars: ✭ 103 (-44.02%)
Mutual labels:  rspec
Websiteone
A website for Agile Ventures
Stars: ✭ 132 (-28.26%)
Mutual labels:  rspec
Rspec api documentation
Automatically generate API documentation from RSpec
Stars: ✭ 1,366 (+642.39%)
Mutual labels:  rspec
Rspec Request describer
An RSpec plugin to write self-documenting request-specs.
Stars: ✭ 151 (-17.93%)
Mutual labels:  rspec

FactoryTrace

CircleCI 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: 3
unused factory admin => spec/factories.rb:10
unused trait with_address of factory admin => spec/factories.rb:11
unused global trait with_email => spec/factories.rb:16

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.json bundle exec rspec spec/first_spec.rb
# another part
FB_TRACE=trace_only FB_TRACE_FILE=fb_trace_result2.json bundle exec rspec spec/second_spec.rb
# output the usage to the console
bundle exec factory_trace fb_trace_result1.json fb_trace_result2.json
# or to the file
FB_TRACE_FILE=fb_report.txt bundle exec factory_trace fb_trace_result1.json fb_trace_result2.json

Note: bundle exec factory_trace won't load your project. Thus it runs fast and it's 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
  
  # used to trace definitions places 
  # default is true
  # can be true or false  
  config.trace_definition = true 
end

Tip: if you have some errors try to disable trace_definition. That functionality does many monkey patches to FactoryBot. I will appreciate sharing an error stack trace so I can fix it.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].