gems test-prof 1.1.0

latest releases: 1.3.3.1, 1.4.0.rc.1, 1.3.3...
19 months ago

Highlights

  • Added Factory Default (or factory associations) profiler and FactoryDefault usage stats.

Factory Default profiles shows which factories (and variations) were created via associations and how many times. This information can help you estimate the effect of adding a default record.

Here is an example report:

$ FACTORY_DEFAULT_PROF=1 bin/rspec

[TEST PROF INFO] Factory associations usage:

                                    factory      count    total time

                                      track        281     00:12.671
     user{organization:<Organization#<id>>}         62     00:05.830
                                       user         46     00:04.401
                                 assessment          6     00:02.599
                        specialist_vertical         24     00:02.209
                         user[without_plan]         16     00:01.201
                               organization        352     00:01.138
                                      admin        341     00:00.999

After adding default factory records, you can now also get the information about the actual usage:

$ FACTORY_DEFAULT_STATS=1 bin/rspec spec/models/user_spec.rb

[TEST PROF INFO] FactoryDefault usage stats:

        factory        hit       miss

          track        224         51
          admin         83          0
   organization         77         89
           user         51         82

FactoryDefault summary: hit=435 miss=222

Factory Default

  • Added skip_factory_default(&block) to temporary disable default factories.

You can also use TestProf::FactoryDefault.disable!(&block).

  • Defaults now could be created per trait (or set of traits).

Now create_default(:user) and create_default(:user, :admin) would result into two defaults corresponding to the specified traits.

  • Added preserve_attributes = false | true configuration option.

Allow skipping defaults if association is defined with overrides, e.g.:

factory :post do
  association :user, name: "Post Author"
end
  • Added ability to dynamically disable Factory Default (turn create_default into create) by setting the FACTORY_DEFAULT_DISABLED=1 environmental variable.

Before All

  • Added tags support to before_all hooks.
TestProf::BeforeAll.configure do |config|
  config.before(:begin, reset_sequences: true, foo: :bar) do
    warn <<~MESSAGE
      Do NOT create objects outside of transaction
      because all db sequences will be reset to 1
      in every single example, so that IDs of new objects
      can get into conflict with the long-living ones.
    MESSAGE
  end
end
  • Support using Factory Default within before_all / let_it_be.

Default factories created within before_all or let_it_be are not reset 'till the end of the corresponding context. Thus, now it's possible to use create_default within let_it_be without any additional hacks. Currently, RSpec only.

Fixes

  • Records created with let_it_be(:x, freeze: true) are now frozen during initialization, not at the access (let) time.

Don't miss a new test-prof release

NewReleases is sending notifications on new releases.