From 99b6500e5fd2488ab187a59a544a3e86f1e4ac5f Mon Sep 17 00:00:00 2001 From: Malaber Date: Sun, 16 Mar 2025 13:22:08 +0100 Subject: [PATCH] Install and configure rubyprof --- Gemfile | 1 + Gemfile.lock | 2 ++ spec/spec_helper.rb | 3 +++ spec/support/profile.rb | 13 +++++++++++++ 4 files changed, 19 insertions(+) create mode 100644 spec/support/profile.rb diff --git a/Gemfile b/Gemfile index 0fc4715..036d7b6 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,7 @@ group :test, optional: true do gem 'faker' gem 'rspec-rails' gem 'shoulda-matchers' + gem 'ruby-prof' end group :development, optional: true do diff --git a/Gemfile.lock b/Gemfile.lock index 13f0829..954a4c4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -267,6 +267,7 @@ GEM rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) + ruby-prof (1.7.1) ruby-progressbar (1.13.0) shoulda-matchers (6.2.0) activesupport (>= 5.2.0) @@ -334,6 +335,7 @@ DEPENDENCIES rubocop rubocop-performance rubocop-rails + ruby-prof shoulda-matchers solargraph spring diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 055accf..3139ef1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -99,4 +99,7 @@ RSpec.configure do |config| Kernel.srand config.seed config.example_status_persistence_file_path = 'specs_with_runtime.txt' + + # Run ruby-prof + Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f } end diff --git a/spec/support/profile.rb b/spec/support/profile.rb new file mode 100644 index 0000000..f2a9f48 --- /dev/null +++ b/spec/support/profile.rb @@ -0,0 +1,13 @@ +require 'ruby-prof' + +RSpec.configure do |config| + config.around(:each) do |example| + profile = RubyProf::Profile.new + profile.start + example.run + result = profile.stop + + printer = RubyProf::FlatPrinter.new(result) + printer.print(File.open("profile_#{example.full_description.parameterize}.txt", 'w+')) + end +end \ No newline at end of file