lib/sniff/rake_tasks.rb in sniff-0.8.2 vs lib/sniff/rake_tasks.rb in sniff-0.8.3
- old
+ new
@@ -9,22 +9,30 @@
def self.define_tasks(&blk)
new(&blk).define_tasks
end
- attr_accessor :earth_domains, :cucumber, :rspec, :rcov, :rocco, :bueller
+ attr_accessor :earth_domains, :cucumber, :rspec, :coverage, :rocco, :bueller
def initialize
self.earth_domains = :all
self.cucumber = true
self.rspec = false
- self.rcov = true
+ self.coverage = true
self.rocco = true
self.bueller = true
yield self if block_given?
end
+ def ruby18?
+ RUBY_VERSION =~ /^1\.8/ ? true : false
+ end
+
+ def rcov=(val)
+ self.coverage = val
+ end
+
def gemname
@gemname ||= File.basename(Dir.glob(File.join(Dir.pwd, '*.gemspec')).first, '.gemspec')
end
def git(cmd, dir = nil, &blk)
@@ -33,10 +41,24 @@
full_cmd << "unset GIT_DIR && unset GIT_INDEX_FILE && unset GIT_WORK_TREE && git #{cmd}"
sh full_cmd, &blk
end
def define_tasks
+ if coverage && ruby18?
+ require 'rcov'
+ elsif coverage
+ task :simplecov do
+ require 'simplecov'
+
+ SimpleCov.start do
+ add_filter '/spec/'
+ add_filter '/features/'
+ add_filter '/vendor/'
+ end
+ end
+ end
+
task :console do
require 'sniff'
cwd = Dir.pwd
Sniff.init cwd, :earth => earth_domains
@@ -131,17 +153,19 @@
else
t.cucumber_opts = 'features --format pretty'
end
end
- if rcov
+ if coverage && ruby18?
desc "Run cucumber tests with RCov"
Cucumber::Rake::Task.new(:features_with_coverage) do |t|
t.cucumber_opts = "features --format pretty"
t.rcov = true
t.rcov_opts = ['--exclude', 'features']
end
+ elsif coverage
+ task :features_with_coverage => [:simplecov, :features]
end
end
if rspec
require 'rspec/core/rake_task'
@@ -153,16 +177,18 @@
else
c.rspec_opts = '-Ispec --format documentation'
end
end
- if rcov
+ if coverage && ruby18?
desc "Run specs with RCov"
RSpec::Core::RakeTask.new(:examples_with_coverage) do |t|
t.rcov = true
t.rcov_opts = ['--exclude', 'spec']
t.rspec_opts = '-Ispec'
end
+ elsif coverage
+ task :examples_with_coverage => [:simplecov, :examples]
end
end
directory 'log/'