Skip to content

Commit

Permalink
Subtract an r
Browse files Browse the repository at this point in the history
I've been moving away from class names ending in '-er'. The class is now
the thing, instead of the thing that does the thing.
  • Loading branch information
composerinteralia committed Oct 24, 2022
1 parent 17251bb commit 523098e
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 71 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

source "https://rubygems.org"

# Specify your gem's dependencies in factory_bot_profiler.gemspec
gemspec

gem "rake", "~> 13.0"
Expand Down
40 changes: 21 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
PATH
remote: .
specs:
factory_bot_profiler (0.1.0)
factory_bot_profile (0.1.0)
factory_bot (>= 6.2.1)

GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.3.1)
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand All @@ -19,60 +19,62 @@ GEM
activesupport (>= 5.0.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
minitest (5.16.2)
json (2.6.2)
minitest (5.16.3)
parallel (1.22.1)
parser (3.1.2.0)
parser (3.1.2.1)
ast (~> 2.4.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.5.0)
regexp_parser (2.6.0)
rexml (3.2.5)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
rspec-expectations (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.29.1)
rspec-support (3.11.1)
rubocop (1.35.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.17.0, < 2.0)
rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.19.1)
rubocop-ast (1.23.0)
parser (>= 3.1.1.0)
rubocop-performance (1.13.3)
rubocop-performance (1.14.3)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
standard (1.12.1)
rubocop (= 1.29.1)
rubocop-performance (= 1.13.3)
standard (1.16.1)
rubocop (= 1.35.1)
rubocop-performance (= 1.14.3)
timecop (0.9.5)
tzinfo (2.0.4)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.2.0)
unicode-display_width (2.3.0)

PLATFORMS
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
factory_bot_profiler!
factory_bot_profile!
rake (~> 13.0)
rspec (~> 3.0)
standard (~> 1.3)
timecop

BUNDLED WITH
2.3.11
2.3.22
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FactoryBotProfiler
# FactoryBotProfile

FactoryBotProfiler identifies expensive factories and heavy [factory\_bot][] usage.
FactoryBotProfile identifies expensive factories and heavy [factory\_bot][] usage.
Use this information to speed up your test suite!

[factory\_bot]: https://github.com/thoughtbot/factory_bot
Expand All @@ -9,21 +9,21 @@ Use this information to speed up your test suite!

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

$ bundle add factory_bot_profiler
$ bundle add factory_bot_profile

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

$ gem install factory_bot_profiler
$ 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:

```rb
require "factory_bot_profiler"
require "factory_bot_profile"

FactoryBotProfiler.reporting do
FactoryBotProfile.reporting do
# Code that uses factory_bot
end
```
Expand All @@ -35,12 +35,12 @@ If you need more control over where to start and stop profiling, and when to
report the results, use the `.subscribe` and `.report` methods:

```rb
subscription = FactoryBotProfiler.subscribe
subscription = FactoryBotProfile.subscribe

# Code that uses factory_bot

subscription.unsubscribe
FactoryBotProfiler.report(subscription.stats)
FactoryBotProfile.report(subscription.stats)
```

## Why not FactoryProf?
Expand All @@ -55,7 +55,7 @@ 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.

FactoryBotProfiler, on the other hand, uses factory\_bot's built-in
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.
Expand All @@ -72,12 +72,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/composerinteralia/factory_bot_profiler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/composerinteralia/factory_bot_profiler/blob/main/CODE_OF_CONDUCT.md).
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](https://github.com/composerinteralia/factory_bot_profile/blob/main/CODE_OF_CONDUCT.md).

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Code of Conduct

Everyone interacting in the FactoryBotProfiler project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/composerinteralia/factory_bot_profiler/blob/main/CODE_OF_CONDUCT.md).
Everyone interacting in the FactoryBotProfile project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/composerinteralia/factory_bot_profile/blob/main/CODE_OF_CONDUCT.md).
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "factory_bot_profiler"
require "factory_bot_profile"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
8 changes: 4 additions & 4 deletions factory_bot_profiler.gemspec → factory_bot_profile.gemspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

require_relative "lib/factory_bot_profiler/version"
require_relative "lib/factory_bot_profile/version"

Gem::Specification.new do |spec|
spec.name = "factory_bot_profiler"
spec.version = FactoryBotProfiler::VERSION
spec.name = "factory_bot_profile"
spec.version = FactoryBotProfile::VERSION
spec.authors = ["Daniel Colson"]
spec.email = ["danieljamescolson@gmail.com"]

spec.summary = "Profiling for factory_bot"
spec.homepage = "https://github.com/composerinterali/factory_bot_profiler"
spec.homepage = "https://github.com/composerinterali/factory_bot_profile"
spec.license = "MIT"
spec.required_ruby_version = ">= 3.0.0"

Expand Down
12 changes: 6 additions & 6 deletions lib/factory_bot_profiler.rb → lib/factory_bot_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

require "active_support/notifications"

require_relative "factory_bot_profiler/version"
require_relative "factory_bot_profiler/aggregate_stats"
require_relative "factory_bot_profiler/subscriber"
require_relative "factory_bot_profiler/subscription"
require_relative "factory_bot_profiler/report/simple_report"
require_relative "factory_bot_profile/version"
require_relative "factory_bot_profile/aggregate_stats"
require_relative "factory_bot_profile/subscriber"
require_relative "factory_bot_profile/subscription"
require_relative "factory_bot_profile/report/simple_report"

module FactoryBotProfiler
module FactoryBotProfile
def self.reporting
subscription = subscribe
result = yield
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative "stat"

module FactoryBotProfiler
module FactoryBotProfile
class AggregateStats
def initialize
@by_factory = stats_hash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FactoryBotProfiler
module FactoryBotProfile
class Frame
attr_accessor :name, :start, :child_time

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FactoryBotProfiler
module FactoryBotProfile
module Report
class SimpleReport
def initialize(stats, io: $stdout)
Expand All @@ -10,11 +10,11 @@ def deliver
io.puts
io.puts "++++++++ factory_bot stats:"
io.puts
io.puts " Spent #{(stats.total_time).round(2)} seconds in factory_bot"
io.puts " Spent #{stats.total_time.round(2)} seconds in factory_bot"
io.puts
io.puts " Factories taking the most time overall:"
stats.highest_total_time(3).each do |stat|
io.puts " - :#{stat.name} factory took #{(stat.total_time).round(2)} seconds overall (ran #{stat.count} times)"
io.puts " - :#{stat.name} factory took #{stat.total_time.round(2)} seconds overall (ran #{stat.count} times)"
stat.child_stats_by_total_time.reverse_each do |child_stat|
io.puts " - #{child_stat.total_time.round(2)} seconds spent in :#{child_stat.name} (ran #{child_stat.count}/#{stat.count} times)"
end
Expand All @@ -23,7 +23,7 @@ def deliver
io.puts
io.puts " Slowest factories on average:"
stats.highest_average_time(3).each do |stat|
io.puts " - :#{stat.name} factory took #{(stat.average_time).round(2)} seconds on average (ran #{stat.count} times)"
io.puts " - :#{stat.name} factory took #{stat.average_time.round(2)} seconds on average (ran #{stat.count} times)"
stat.child_stats_by_average_time.reverse_each do |child_stat|
io.puts " - #{child_stat.average_time.round(2)} seconds spent in :#{child_stat.name} on average (ran #{child_stat.count}/#{stat.count} times)"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative "frame"

module FactoryBotProfiler
module FactoryBotProfile
class Stack
def initialize
@stack = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FactoryBotProfiler
module FactoryBotProfile
class Stat
attr_reader :name, :count, :total_time

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative "stack"

module FactoryBotProfiler
module FactoryBotProfile
class Subscriber
def initialize(stats)
@stack = Stack.new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FactoryBotProfiler
module FactoryBotProfile
class Subscription
attr_reader :stats

Expand All @@ -9,7 +9,7 @@ def initialize(stats)
def subscribe
@subscription = ActiveSupport::Notifications.subscribe(
"factory_bot.run_factory",
FactoryBotProfiler::Subscriber.new(stats)
FactoryBotProfile::Subscriber.new(stats)
)
self
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module FactoryBotProfiler
module FactoryBotProfile
VERSION = "0.1.0"
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

RSpec.describe FactoryBotProfiler::AggregateStats do
RSpec.describe FactoryBotProfile::AggregateStats do
it "serializes via Marshal" do
stats = FactoryBotProfiler::AggregateStats.new
frame = FactoryBotProfiler::Frame.new(:test).tap(&:finish!)
stats = FactoryBotProfile::AggregateStats.new
frame = FactoryBotProfile::Frame.new(:test).tap(&:finish!)
stats.collect(frame)

marshal_stats = Marshal.load(Marshal.dump(stats))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

RSpec.describe FactoryBotProfiler::Stack do
RSpec.describe FactoryBotProfile::Stack do
it "pushes and pops" do
stack = FactoryBotProfiler::Stack.new
stack = FactoryBotProfile::Stack.new
name = :name

stack << name
Expand All @@ -12,7 +12,7 @@
end

it "finishes frame when popping" do
stack = FactoryBotProfiler::Stack.new
stack = FactoryBotProfile::Stack.new
name = :name
duration = 42

Expand All @@ -25,7 +25,7 @@
end

it "allows parent frame to observe child frames" do
stack = FactoryBotProfiler::Stack.new
stack = FactoryBotProfile::Stack.new
parent_name = :parent
child_name = :child

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

RSpec.describe FactoryBotProfiler::FactoryStat do
RSpec.describe FactoryBotProfile::FactoryStat do
it "serializes via Marshal" do
stat = FactoryBotProfiler::FactoryStat.new(:test)
stat = FactoryBotProfile::FactoryStat.new(:test)

marshal_stat = Marshal.load(Marshal.dump(stat))

Expand All @@ -11,11 +11,11 @@

describe "#merge!" do
it "merges the values from another factory_stat" do
stat = FactoryBotProfiler::FactoryStat.new(:stat)
stat = FactoryBotProfile::FactoryStat.new(:stat)
frame = build_frame(duration: 2, child_time: {a: 1, b: 2})
stat.increment(frame)

other_stat = FactoryBotProfiler::FactoryStat.new(:stat)
other_stat = FactoryBotProfile::FactoryStat.new(:stat)
other_frame = build_frame(duration: 5, child_time: {a: 2, c: 1})
other_stat.increment(other_frame)

Expand All @@ -32,6 +32,6 @@
end

def build_frame(duration:, child_time:)
double(FactoryBotProfiler::Frame, duration: duration, child_time: child_time)
double(FactoryBotProfile::Frame, duration: duration, child_time: child_time)
end
end
Loading

0 comments on commit 523098e

Please sign in to comment.