rspec-prof icon indicating copy to clipboard operation
rspec-prof copied to clipboard

Correct usage on Windows

Open jmthomas opened this issue 11 years ago • 1 comments

Your README doesn't state this but I assume you have to require 'rspec-prof' in your spec_helper.rb. Without that I get nothing. With that almost all my specs fail when I run with RSPEC_PROFILE=each. The profiles directory is created and it has a bunch of directories containing zero byte files named after my specs. When I run with RSPEC_PROFILE=all I get a profiles directory with an all.html file that fluctuates in size. It appears that the file is being constantly re-written. Probably a ruby-prof issue but thought I'd post here too.

jmthomas avatar Dec 18 '13 22:12 jmthomas

I ended up writing my own spec_helper.rb using ruby-prof directly which works. I did something like this:

RSpec.configure do |c|
  c.around(:each) do |example|
    if ENV.key?("PROFILE")
      klass = example.metadata[:example_group][:example_group][:description_args][0].to_s.gsub(/::/,'')
      method = example.metadata[:description_args][0].to_s.gsub!(/ /,'_')
      RubyProf.start
      100.times do
        example.run
      end
      result = RubyProf.stop
      result.eliminate_methods!([/Integer#times/, /Integer#upto/, /Enumerable#each_with_index/])
      printer = RubyProf::GraphHtmlPrinter.new(result)
      dir = "./profile/#{klass}"
      FileUtils.mkdir_p(dir)
      printer.print(File.open("#{dir}/#{method}.html", 'w+'), :min_percent => 2)
    else
      example.run
    end
  end

Then I just set the PROFILE environment variable when I want to run ruby-prof.

jmthomas avatar Dec 19 '13 00:12 jmthomas