From 250ed36d938113b7da123707b138168ad1884d9e Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 1 Mar 2013 21:50:21 -0300 Subject: [PATCH] Proper setup of rspec-fire and improved rspec rake tasks --- Rakefile | 6 ------ spec/spec_helper.rb | 5 +++++ tasks/coverage.rake | 5 ----- tasks/spec.rake | 30 ++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 11 deletions(-) delete mode 100644 tasks/coverage.rake create mode 100644 tasks/spec.rake diff --git a/Rakefile b/Rakefile index 8247fb1..396a942 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,3 @@ raise 'This Rakefile is meant to be used from the dev box' unless ENV['USER'] == 'vagrant' Dir['./tasks/**/*.rake'].each { |f| load f } - -begin - require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec) - task :default => :coverage -rescue LoadError; end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7e5d3d8..7dc442f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,6 +15,11 @@ require 'rspec-spies' Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f } +require 'rspec/fire' +RSpec::Fire.configure do |config| + config.verify_constant_names = ENV['VERIFY_CONSTANT_NAMES'] == '1' +end + RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true diff --git a/tasks/coverage.rake b/tasks/coverage.rake deleted file mode 100644 index 8dc9835..0000000 --- a/tasks/coverage.rake +++ /dev/null @@ -1,5 +0,0 @@ -desc 'Run specs with code coverage enabled' -task :coverage do - ENV['COVERAGE'] = 'true' - Rake::Task["spec"].execute -end diff --git a/tasks/spec.rake b/tasks/spec.rake new file mode 100644 index 0000000..8b2f3de --- /dev/null +++ b/tasks/spec.rake @@ -0,0 +1,30 @@ +begin + require 'rspec/core/rake_task' + + # TODO: add 'spec:acceptance' and 'spec:integration' then they are in place + desc 'Run all specs' + task :spec => ['spec:unit'] + + desc 'Default task which runs all specs with code coverage enabled' + task :default => ['spec:set_coverage', 'spec'] +rescue LoadError; end + +namespace :spec do + task :set_coverage do + ENV['COVERAGE'] = 'true' + end + + def types + dirs = Dir['./spec/**/*_spec.rb'].map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }.uniq + Hash[dirs.map { |d| [d.split('/').last, d] }] + end + types.each do |type, dir| + desc "Run the code examples in #{dir}" + RSpec::Core::RakeTask.new(type) do |t| + # Tells rspec-fire to verify if constants used really exist + ENV['VERIFY_CONSTANT_NAMES'] = '1' + + t.pattern = "./#{dir}/**/*_spec.rb" + end + end +end