diff options
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | spec/spec_helper.rb | 21 | ||||
-rw-r--r-- | spec/unit/recipe_spec.rb | 2 |
3 files changed, 23 insertions, 1 deletions
@@ -13,6 +13,7 @@ group(:development, :test) do gem "simplecov" gem 'rack', "~> 1.5.1" gem 'cheffish', "~> 1.2" + gem 'rspec-prof' gem 'ruby-shadow', :platforms => :ruby unless RUBY_PLATFORM.downcase.match(/(aix|cygwin)/) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dcf244c3cc..ffef54fe70 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -190,6 +190,27 @@ RSpec.configure do |config| end end +require 'ruby-prof' + +RSpec.configure do |c| + def profile(example) + result = RubyProf.profile { yield } + name = example.metadata[:full_description].downcase.gsub(/[^a-z0-9_-]/, "-").gsub(/-+/, "-") + printer = RubyProf::CallTreePrinter.new(result) + open("/Users/jkeiser/src/chef/profiles/callgrind.#{name}.#{Time.now.to_i}.trace", "w") do |f| + printer.print(f) + end + end + + c.around(:each) do |example| + if ENV['PROFILE'] == 'all' or (example.metadata[:profile] and ENV['PROFILE']) + profile(example) { example.run } + else + example.run + end + end +end + require 'webrick/utils' # Webrick uses a centralized/synchronized timeout manager. It works by diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 72d5cc6f63..a811d9d002 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -22,7 +22,7 @@ require 'spec_helper' require 'chef/platform/resource_priority_map' -describe Chef::Recipe do +describe Chef::Recipe, :profile do let(:cookbook_repo) { File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks")) } |