From 8e485b89f8b678e29db431d6d865fc3e0c74856b Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Tue, 4 Mar 2014 17:05:55 +0000 Subject: [PATCH] add rubydeps support for graphing class hierarchy https://github.com/dcadenas/rubydeps --- Gemfile | 1 + Rakefile | 47 +++++++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 5 +++++ 3 files changed, 53 insertions(+) create mode 100644 Rakefile diff --git a/Gemfile b/Gemfile index f1db8eb..6176f55 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ source 'https://rubygems.org' group :test, :development do gem 'chefspec', '~> 3.0' + gem 'rubydeps' end group :development do diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..bac07c3 --- /dev/null +++ b/Rakefile @@ -0,0 +1,47 @@ +IGNORED_CLASSES = ['RSpec::Core::ExampleGroup'] +DUMP_FILE = 'rubydeps.dump' +DOT_FILE = 'rubydeps.dot' +SVG_FILE = 'rubydeps.svg' + +task :default => "rubydeps:svg" + +file DUMP_FILE do + sh 'RUBYDEPS=y rspec' +end + +file DOT_FILE => DUMP_FILE do + ignore_regexp = IGNORED_CLASSES.join "|" + sh "rubydeps --class-name-filter='^(?!#{ignore_regexp})'" + dot = File.read(DOT_FILE) + dot.gsub!('rankdir=LR', 'rankdir=TB') + # Unfortunately due to https://github.com/dcadenas/rubydeps/issues/4 + # we need to manually exclude some superfluous dependencies which + # go in the wrong direction. + dot.gsub!(/\\\n/, '') + dot.gsub!(/^(?=\s+Object )/, '#') + dot.gsub!(/^(?=\s+"Pacemaker::Resource::Meta" ->)/, '#') + dot.gsub!(/^(?=\s+"Pacemaker::CIBObject" ->)/, '#') + dot.gsub!(/^(?=\s+"Chef::Mixin::Pacemaker::StandardCIBObject" -> "(?!Pacemaker::CIBObject))/, '#') + dot.gsub!(/^(?=\s+"Chef::Mixin::Pacemaker::RunnableResource" -> "(?!Pacemaker::CIBObject))/, '#') + File.open(DOT_FILE, 'w') { |f| f.write(dot) } +end + +file SVG_FILE => DOT_FILE do + sh "dot -Tsvg #{DOT_FILE} > #{SVG_FILE}" +end + +namespace :rubydeps do + desc "Clean rubydeps dump" + task :clean do + FileUtils.rm_f([DUMP_FILE]) + end + + desc "Regenerate #{DUMP_FILE}" + task :dump => DUMP_FILE + + desc "Regenerate #{DOT_FILE}" + task :dot => DOT_FILE + + desc "Regenerate #{SVG_FILE}" + task :svg => SVG_FILE +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 79c8501..ee9c3c2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,6 +43,11 @@ end # FIXME #running_guard = ENV['GUARD_NOTIFY'] && ! ENV['GUARD_NOTIFY'].empty? +if ENV['RUBYDEPS'] + require 'rubydeps' + Rubydeps.start +end + if false # ! running_guard at_exit { ChefSpec::Coverage.report! } end